1 #pragma once 2 3 #include "common/Atomic.hpp" 4 #include "common/Channel.hpp" 5 #include "common/Singleton.hpp" 6 #include "pajlada/signals/signalholder.hpp" 7 #include "providers/bttv/BttvEmotes.hpp" 8 #include "providers/ffz/FfzEmotes.hpp" 9 #include "providers/irc/AbstractIrcServer.hpp" 10 11 #include <chrono> 12 #include <memory> 13 #include <queue> 14 15 namespace chatterino { 16 17 class Settings; 18 class Paths; 19 class PubSub; 20 class TwitchChannel; 21 22 class TwitchIrcServer final : public AbstractIrcServer, public Singleton 23 { 24 public: 25 TwitchIrcServer(); 26 virtual ~TwitchIrcServer() override = default; 27 28 virtual void initialize(Settings &settings, Paths &paths) override; 29 30 void forEachChannelAndSpecialChannels(std::function<void(ChannelPtr)> func); 31 32 std::shared_ptr<Channel> getChannelOrEmptyByID(const QString &channelID); 33 34 Atomic<QString> lastUserThatWhisperedMe; 35 36 const ChannelPtr whispersChannel; 37 const ChannelPtr mentionsChannel; 38 const ChannelPtr liveChannel; 39 IndirectChannel watchingChannel; 40 41 PubSub *pubsub; 42 43 const BttvEmotes &getBttvEmotes() const; 44 const FfzEmotes &getFfzEmotes() const; 45 46 protected: 47 virtual void initializeConnection(IrcConnection *connection, 48 ConnectionType type) override; 49 virtual std::shared_ptr<Channel> createChannel( 50 const QString &channelName) override; 51 52 virtual void privateMessageReceived( 53 Communi::IrcPrivateMessage *message) override; 54 virtual void readConnectionMessageReceived( 55 Communi::IrcMessage *message) override; 56 virtual void writeConnectionMessageReceived( 57 Communi::IrcMessage *message) override; 58 59 virtual std::shared_ptr<Channel> getCustomChannel( 60 const QString &channelname) override; 61 62 virtual QString cleanChannelName(const QString &dirtyChannelName) override; 63 virtual bool hasSeparateWriteConnection() const override; 64 65 private: 66 void onMessageSendRequested(TwitchChannel *channel, const QString &message, 67 bool &sent); 68 69 std::mutex lastMessageMutex_; 70 std::queue<std::chrono::steady_clock::time_point> lastMessagePleb_; 71 std::queue<std::chrono::steady_clock::time_point> lastMessageMod_; 72 std::chrono::steady_clock::time_point lastErrorTimeSpeed_; 73 std::chrono::steady_clock::time_point lastErrorTimeAmount_; 74 75 BttvEmotes bttv; 76 FfzEmotes ffz; 77 78 pajlada::Signals::SignalHolder signalHolder_; 79 }; 80 81 } // namespace chatterino 82