mirror-chatterino2/src/providers/twitch/TwitchIrcServer.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

127 lines
4.3 KiB
C++
Raw Normal View History

2018-02-05 15:11:50 +01:00
#pragma once
2018-08-11 14:20:53 +02:00
#include "common/Atomic.hpp"
#include "common/Channel.hpp"
2018-07-07 11:41:01 +02:00
#include "common/Singleton.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/ffz/FfzEmotes.hpp"
2018-06-26 14:09:39 +02:00
#include "providers/irc/AbstractIrcServer.hpp"
#include "providers/seventv/SeventvEmotes.hpp"
#include <pajlada/signals/signalholder.hpp>
2018-06-24 12:59:47 +02:00
#include <chrono>
#include <memory>
2018-06-06 18:57:22 +02:00
#include <queue>
2018-02-05 15:11:50 +01:00
namespace chatterino {
2018-08-02 14:23:27 +02:00
class Settings;
class Paths;
2018-08-13 14:38:03 +02:00
class TwitchChannel;
class BttvLiveUpdates;
class SeventvEventAPI;
class ITwitchIrcServer
{
public:
virtual ~ITwitchIrcServer() = default;
virtual const BttvEmotes &getBttvEmotes() const = 0;
virtual const FfzEmotes &getFfzEmotes() const = 0;
virtual const SeventvEmotes &getSeventvEmotes() const = 0;
virtual const IndirectChannel &getWatchingChannel() const = 0;
// Update this interface with TwitchIrcServer methods as needed
};
class TwitchIrcServer final : public AbstractIrcServer,
public Singleton,
public ITwitchIrcServer
2018-02-05 15:11:50 +01:00
{
2018-04-30 20:35:01 +02:00
public:
2019-09-18 13:03:16 +02:00
TwitchIrcServer();
~TwitchIrcServer() override = default;
void initialize(Settings &settings, const Paths &paths) override;
void forEachChannelAndSpecialChannels(std::function<void(ChannelPtr)> func);
std::shared_ptr<Channel> getChannelOrEmptyByID(const QString &channelID);
void reloadBTTVGlobalEmotes();
void reloadAllBTTVChannelEmotes();
void reloadFFZGlobalEmotes();
void reloadAllFFZChannelEmotes();
void reloadSevenTVGlobalEmotes();
void reloadAllSevenTVChannelEmotes();
/** Calls `func` with all twitch channels that have `emoteSetId` added. */
void forEachSeventvEmoteSet(const QString &emoteSetId,
std::function<void(TwitchChannel &)> func);
/** Calls `func` with all twitch channels where the seventv-user-id is `userId`. */
void forEachSeventvUser(const QString &userId,
std::function<void(TwitchChannel &)> func);
/**
* Checks if any channel still needs this `userID` or `emoteSetID`.
* If not, it unsubscribes from the respective messages.
*
* It's currently not possible to share emote sets among users,
* but it's a commonly requested feature.
*/
void dropSeventvChannel(const QString &userID, const QString &emoteSetID);
2018-08-11 14:20:53 +02:00
Atomic<QString> lastUserThatWhisperedMe;
2018-02-05 15:11:50 +01:00
const ChannelPtr whispersChannel;
const ChannelPtr mentionsChannel;
const ChannelPtr liveChannel;
const ChannelPtr automodChannel;
2018-04-20 19:54:45 +02:00
IndirectChannel watchingChannel;
std::unique_ptr<BttvLiveUpdates> bttvLiveUpdates;
std::unique_ptr<SeventvEventAPI> seventvEventAPI;
const BttvEmotes &getBttvEmotes() const override;
const FfzEmotes &getFfzEmotes() const override;
const SeventvEmotes &getSeventvEmotes() const override;
const IndirectChannel &getWatchingChannel() const override;
2018-02-05 15:11:50 +01:00
protected:
void initializeConnection(IrcConnection *connection,
ConnectionType type) override;
std::shared_ptr<Channel> createChannel(const QString &channelName) override;
void privateMessageReceived(Communi::IrcPrivateMessage *message) override;
void readConnectionMessageReceived(Communi::IrcMessage *message) override;
void writeConnectionMessageReceived(Communi::IrcMessage *message) override;
std::shared_ptr<Channel> getCustomChannel(
const QString &channelname) override;
QString cleanChannelName(const QString &dirtyChannelName) override;
bool hasSeparateWriteConnection() const override;
2018-05-25 13:53:55 +02:00
private:
2018-07-06 19:23:47 +02:00
void onMessageSendRequested(TwitchChannel *channel, const QString &message,
bool &sent);
void onReplySendRequested(TwitchChannel *channel, const QString &message,
const QString &replyId, bool &sent);
bool prepareToSend(TwitchChannel *channel);
2018-06-24 13:06:11 +02:00
std::mutex lastMessageMutex_;
std::queue<std::chrono::steady_clock::time_point> lastMessagePleb_;
std::queue<std::chrono::steady_clock::time_point> lastMessageMod_;
std::chrono::steady_clock::time_point lastErrorTimeSpeed_;
std::chrono::steady_clock::time_point lastErrorTimeAmount_;
BttvEmotes bttv;
FfzEmotes ffz;
SeventvEmotes seventv_;
pajlada::Signals::SignalHolder signalHolder_;
2018-02-05 15:11:50 +01:00
};
2018-02-05 15:11:50 +01:00
} // namespace chatterino