From 38d118c5dc7b241da132ed0ad93782bd138d5741 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 17 Sep 2017 04:36:48 +0200 Subject: [PATCH] add debug binding ALT+Q to add test messages to current chatwidget (every second) --- src/channelmanager.hpp | 8 ++-- src/ircmanager.hpp | 5 ++- src/widgets/chatwidget.cpp | 86 ++++++++++++++++++++++++++++++++++++++ src/widgets/chatwidget.hpp | 4 ++ 4 files changed, 98 insertions(+), 5 deletions(-) diff --git a/src/channelmanager.hpp b/src/channelmanager.hpp index 8a669e94e..a4cd71b30 100644 --- a/src/channelmanager.hpp +++ b/src/channelmanager.hpp @@ -14,14 +14,14 @@ class IrcManager; class ChannelManager { - WindowManager &windowManager; - EmoteManager &emoteManager; - IrcManager &ircManager; - public: explicit ChannelManager(WindowManager &_windowManager, EmoteManager &_emoteManager, IrcManager &_ircManager); + WindowManager &windowManager; + EmoteManager &emoteManager; + IrcManager &ircManager; + const std::vector> getItems(); std::shared_ptr addTwitchChannel(const QString &channel); diff --git a/src/ircmanager.hpp b/src/ircmanager.hpp index f24810cad..fbd94cb14 100644 --- a/src/ircmanager.hpp +++ b/src/ircmanager.hpp @@ -49,20 +49,23 @@ public: pajlada::Signals::Signal onPrivateMessage; -private: ChannelManager &channelManager; Resources &resources; EmoteManager &emoteManager; WindowManager &windowManager; +private: // variables twitch::TwitchUser _account; pajlada::Settings::Setting currentUser; std::shared_ptr writeConnection = nullptr; + +public: std::shared_ptr readConnection = nullptr; +private: std::mutex connectionMutex; uint32_t connectionGeneration = 0; diff --git a/src/widgets/chatwidget.cpp b/src/widgets/chatwidget.cpp index ebd1146b8..99bb811b0 100644 --- a/src/widgets/chatwidget.cpp +++ b/src/widgets/chatwidget.cpp @@ -3,6 +3,7 @@ #include "colorscheme.hpp" #include "notebookpage.hpp" #include "settingsmanager.hpp" +#include "twitch/twitchmessagebuilder.hpp" #include "util/urlfetch.hpp" #include "widgets/qualitypopup.hpp" #include "widgets/textinputdialog.hpp" @@ -23,6 +24,7 @@ #include #include +#include using namespace chatterino::messages; @@ -75,6 +77,11 @@ ChatWidget::ChatWidget(ChannelManager &_channelManager, NotebookPage *parent) // CTRL+C: Copy ezShortcut(this, "CTRL+B", &ChatWidget::doCopy); +#ifndef NDEBUG + // F12: Toggle message spawning + ezShortcut(this, "ALT+Q", &ChatWidget::doToggleMessageSpawning); +#endif + this->channelName.getValueChangedSignal().connect( std::bind(&ChatWidget::channelNameUpdated, this, std::placeholders::_1)); @@ -83,6 +90,10 @@ ChatWidget::ChatWidget(ChannelManager &_channelManager, NotebookPage *parent) this->input.textInput.installEventFilter(parent); this->view.mouseDown.connect([this](QMouseEvent *) { this->giveFocus(Qt::MouseFocusReason); }); + + QTimer *timer = new QTimer(this); + connect(timer, &QTimer::timeout, this, &ChatWidget::test); + timer->start(1000); } ChatWidget::~ChatWidget() @@ -422,5 +433,80 @@ void ChatWidget::doCopy() QApplication::clipboard()->setText(this->view.getSelectedText()); } +static std::vector usernameVariants = { + "pajlada", // + "trump", // + "Chancu", // + "pajaWoman", // + "fourtf", // + "weneedmoreautisticbots", // + "fourtfbot", // + "pajbot", // + "snusbot", // +}; + +static std::vector messageVariants = { + "hehe", // + "lol pajlada", // + "hehe BANNEDWORD", // + "someone ordered pizza", // + "for ice poseidon", // + "and delivery guy said it is for enza denino", // + "!gn", // + "for my laptop", // + "should I buy a Herschel backpack?", // +}; + +template +static Iter select_randomly(Iter start, Iter end, RandomGenerator &g) +{ + std::uniform_int_distribution<> dis(0, std::distance(start, end) - 1); + std::advance(start, dis(g)); + return start; +} + +template +static Iter select_randomly(Iter start, Iter end) +{ + static std::random_device rd; + static std::mt19937 gen(rd()); + return select_randomly(start, end, gen); +} + +void ChatWidget::test() +{ + if (this->testEnabled) { + messages::MessageParseArgs args; + + auto message = + new Communi::IrcPrivateMessage(this->channelManager.ircManager.readConnection.get()); + + std::string text = *(select_randomly(messageVariants.begin(), messageVariants.end())); + std::string username = *(select_randomly(usernameVariants.begin(), usernameVariants.end())); + std::string usernameString = username + "!" + username + "@" + username; + + QStringList params{"#pajlada", text.c_str()}; + + qDebug() << params; + + message->setParameters(params); + + message->setPrefix(usernameString.c_str()); + + auto twitchChannel = std::dynamic_pointer_cast(this->channel); + + twitch::TwitchMessageBuilder builder( + twitchChannel.get(), this->channelManager.ircManager.resources, + this->channelManager.emoteManager, this->channelManager.windowManager, message, args); + + twitchChannel->addMessage(builder.parse()); + } +} + +void ChatWidget::doToggleMessageSpawning() +{ + this->testEnabled = !this->testEnabled; +} + } // namespace widgets } // namespace chatterino diff --git a/src/widgets/chatwidget.hpp b/src/widgets/chatwidget.hpp index 442733feb..93edee5f4 100644 --- a/src/widgets/chatwidget.hpp +++ b/src/widgets/chatwidget.hpp @@ -85,6 +85,7 @@ private: public: void load(const boost::property_tree::ptree &tree); boost::property_tree::ptree save(); + bool testEnabled = false; public slots: // Add new split to the notebook page that this chat widget is in @@ -118,6 +119,9 @@ public slots: // Open viewer list of the channel void doOpenViewerList(); + + void doToggleMessageSpawning(); + void test(); }; } // namespace widgets