add debug binding ALT+Q to add test messages to current chatwidget

(every second)
This commit is contained in:
Rasmus Karlsson 2017-09-17 04:36:48 +02:00
parent 51e5d198fb
commit 38d118c5dc
4 changed files with 98 additions and 5 deletions

View file

@ -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<std::shared_ptr<Channel>> getItems();
std::shared_ptr<twitch::TwitchChannel> addTwitchChannel(const QString &channel);

View file

@ -49,20 +49,23 @@ public:
pajlada::Signals::Signal<Communi::IrcPrivateMessage *> onPrivateMessage;
private:
ChannelManager &channelManager;
Resources &resources;
EmoteManager &emoteManager;
WindowManager &windowManager;
private:
// variables
twitch::TwitchUser _account;
pajlada::Settings::Setting<std::string> currentUser;
std::shared_ptr<Communi::IrcConnection> writeConnection = nullptr;
public:
std::shared_ptr<Communi::IrcConnection> readConnection = nullptr;
private:
std::mutex connectionMutex;
uint32_t connectionGeneration = 0;

View file

@ -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 <boost/signals2.hpp>
#include <functional>
#include <random>
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<std::string> usernameVariants = {
"pajlada", //
"trump", //
"Chancu", //
"pajaWoman", //
"fourtf", //
"weneedmoreautisticbots", //
"fourtfbot", //
"pajbot", //
"snusbot", //
};
static std::vector<std::string> 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 <typename Iter, typename RandomGenerator>
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 <typename Iter>
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<twitch::TwitchChannel>(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

View file

@ -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