2019-09-08 22:27:57 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common/Atomic.hpp"
|
|
|
|
#include "common/Channel.hpp"
|
|
|
|
#include "common/Singleton.hpp"
|
|
|
|
#include "providers/irc/AbstractIrcServer.hpp"
|
|
|
|
|
2022-12-31 15:41:01 +01:00
|
|
|
#include <pajlada/signals/signalholder.hpp>
|
|
|
|
|
2019-09-08 22:27:57 +02:00
|
|
|
#include <chrono>
|
|
|
|
#include <memory>
|
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
class Settings;
|
|
|
|
class Paths;
|
|
|
|
class TwitchChannel;
|
2023-01-21 15:06:55 +01:00
|
|
|
class BttvLiveUpdates;
|
2022-11-13 12:07:41 +01:00
|
|
|
class SeventvEventAPI;
|
2024-01-21 14:20:21 +01:00
|
|
|
class BttvEmotes;
|
|
|
|
class FfzEmotes;
|
|
|
|
class SeventvEmotes;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-05-21 12:10:49 +02:00
|
|
|
class ITwitchIrcServer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~ITwitchIrcServer() = default;
|
|
|
|
|
2023-10-13 17:41:23 +02:00
|
|
|
virtual const IndirectChannel &getWatchingChannel() const = 0;
|
2023-05-21 12:10:49 +02:00
|
|
|
|
2024-02-17 13:26:54 +01:00
|
|
|
virtual QString getLastUserThatWhisperedMe() const = 0;
|
|
|
|
|
2023-05-21 12:10:49 +02:00
|
|
|
// Update this interface with TwitchIrcServer methods as needed
|
|
|
|
};
|
|
|
|
|
|
|
|
class TwitchIrcServer final : public AbstractIrcServer,
|
|
|
|
public Singleton,
|
|
|
|
public ITwitchIrcServer
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
|
|
|
public:
|
2019-09-18 13:03:16 +02:00
|
|
|
TwitchIrcServer();
|
2023-10-25 18:13:48 +02:00
|
|
|
~TwitchIrcServer() override = default;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2024-01-16 21:56:43 +01:00
|
|
|
void initialize(Settings &settings, const Paths &paths) override;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
void forEachChannelAndSpecialChannels(std::function<void(ChannelPtr)> func);
|
|
|
|
|
|
|
|
std::shared_ptr<Channel> getChannelOrEmptyByID(const QString &channelID);
|
|
|
|
|
2022-08-28 12:20:47 +02:00
|
|
|
void reloadBTTVGlobalEmotes();
|
|
|
|
void reloadAllBTTVChannelEmotes();
|
|
|
|
void reloadFFZGlobalEmotes();
|
|
|
|
void reloadAllFFZChannelEmotes();
|
2022-10-16 13:22:17 +02:00
|
|
|
void reloadSevenTVGlobalEmotes();
|
|
|
|
void reloadAllSevenTVChannelEmotes();
|
2022-08-28 12:20:47 +02:00
|
|
|
|
2022-11-13 12:07:41 +01:00
|
|
|
/** 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);
|
|
|
|
|
2019-09-08 22:27:57 +02:00
|
|
|
Atomic<QString> lastUserThatWhisperedMe;
|
|
|
|
|
|
|
|
const ChannelPtr whispersChannel;
|
|
|
|
const ChannelPtr mentionsChannel;
|
2021-05-09 16:17:04 +02:00
|
|
|
const ChannelPtr liveChannel;
|
2023-12-03 23:07:30 +01:00
|
|
|
const ChannelPtr automodChannel;
|
2019-09-08 22:27:57 +02:00
|
|
|
IndirectChannel watchingChannel;
|
|
|
|
|
2023-01-21 15:06:55 +01:00
|
|
|
std::unique_ptr<BttvLiveUpdates> bttvLiveUpdates;
|
2022-11-13 12:07:41 +01:00
|
|
|
std::unique_ptr<SeventvEventAPI> seventvEventAPI;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-10-13 17:41:23 +02:00
|
|
|
const IndirectChannel &getWatchingChannel() const override;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2024-02-17 13:26:54 +01:00
|
|
|
QString getLastUserThatWhisperedMe() const override;
|
|
|
|
|
2019-09-08 22:27:57 +02:00
|
|
|
protected:
|
2023-10-25 18:13:48 +02:00
|
|
|
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(
|
2019-09-08 22:27:57 +02:00
|
|
|
const QString &channelname) override;
|
|
|
|
|
2023-10-25 18:13:48 +02:00
|
|
|
QString cleanChannelName(const QString &dirtyChannelName) override;
|
|
|
|
bool hasSeparateWriteConnection() const override;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void onMessageSendRequested(TwitchChannel *channel, const QString &message,
|
|
|
|
bool &sent);
|
2022-07-31 12:45:25 +02:00
|
|
|
void onReplySendRequested(TwitchChannel *channel, const QString &message,
|
|
|
|
const QString &replyId, bool &sent);
|
|
|
|
|
|
|
|
bool prepareToSend(TwitchChannel *channel);
|
2019-09-08 22:27:57 +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_;
|
|
|
|
|
|
|
|
pajlada::Signals::SignalHolder signalHolder_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace chatterino
|