changed to 80 max column

This commit is contained in:
fourtf
2018-08-06 21:17:03 +02:00
parent defa7e41fa
commit f71ff08e68
203 changed files with 3792 additions and 2405 deletions
+36 -21
View File
@@ -29,8 +29,10 @@ TwitchServer::TwitchServer()
this->pubsub = new PubSub;
// getSettings()->twitchSeperateWriteConnection.connect([this](auto, auto) { this->connect(); },
// this->signalHolder_, false);
// getSettings()->twitchSeperateWriteConnection.connect([this](auto, auto) {
// this->connect(); },
// this->signalHolder_,
// false);
}
void TwitchServer::initialize(Settings &settings, Paths &paths)
@@ -39,11 +41,13 @@ void TwitchServer::initialize(Settings &settings, Paths &paths)
[this]() { postToThread([this] { this->connect(); }); });
}
void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead, bool isWrite)
void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead,
bool isWrite)
{
this->singleConnection_ = isRead == isWrite;
std::shared_ptr<TwitchAccount> account = getApp()->accounts->twitch.getCurrent();
std::shared_ptr<TwitchAccount> account =
getApp()->accounts->twitch.getCurrent();
qDebug() << "logging in as" << account->getUserName();
@@ -62,9 +66,12 @@ void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead,
connection->setPassword(oauthToken);
}
connection->sendCommand(Communi::IrcCommand::createCapability("REQ", "twitch.tv/membership"));
connection->sendCommand(Communi::IrcCommand::createCapability("REQ", "twitch.tv/commands"));
connection->sendCommand(Communi::IrcCommand::createCapability("REQ", "twitch.tv/tags"));
connection->sendCommand(
Communi::IrcCommand::createCapability("REQ", "twitch.tv/membership"));
connection->sendCommand(
Communi::IrcCommand::createCapability("REQ", "twitch.tv/commands"));
connection->sendCommand(
Communi::IrcCommand::createCapability("REQ", "twitch.tv/tags"));
connection->setHost("irc.chat.twitch.tv");
connection->setPort(6667);
@@ -74,9 +81,10 @@ std::shared_ptr<Channel> TwitchServer::createChannel(const QString &channelName)
{
TwitchChannel *channel = new TwitchChannel(channelName);
channel->sendMessageSignal.connect([this, channel](auto &chan, auto &msg, bool &sent) {
this->onMessageSendRequested(channel, msg, sent);
});
channel->sendMessageSignal.connect(
[this, channel](auto &chan, auto &msg, bool &sent) {
this->onMessageSendRequested(channel, msg, sent);
});
return std::shared_ptr<Channel>(channel);
}
@@ -113,7 +121,8 @@ void TwitchServer::messageReceived(Communi::IrcMessage *message)
} else if (command == "MODE") {
handler.handleModeMessage(message);
} else if (command == "NOTICE") {
handler.handleNoticeMessage(static_cast<Communi::IrcNoticeMessage *>(message));
handler.handleNoticeMessage(
static_cast<Communi::IrcNoticeMessage *>(message));
} else if (command == "JOIN") {
handler.handleJoinMessage(message);
} else if (command == "PART") {
@@ -133,7 +142,8 @@ void TwitchServer::writeConnectionMessageReceived(Communi::IrcMessage *message)
}
}
std::shared_ptr<Channel> TwitchServer::getCustomChannel(const QString &channelName)
std::shared_ptr<Channel> TwitchServer::getCustomChannel(
const QString &channelName)
{
if (channelName == "/whispers") {
return this->whispersChannel;
@@ -146,7 +156,8 @@ std::shared_ptr<Channel> TwitchServer::getCustomChannel(const QString &channelNa
return nullptr;
}
void TwitchServer::forEachChannelAndSpecialChannels(std::function<void(ChannelPtr)> func)
void TwitchServer::forEachChannelAndSpecialChannels(
std::function<void(ChannelPtr)> func)
{
this->forEachChannel(func);
@@ -154,7 +165,8 @@ void TwitchServer::forEachChannelAndSpecialChannels(std::function<void(ChannelPt
func(this->mentionsChannel);
}
std::shared_ptr<Channel> TwitchServer::getChannelOrEmptyByID(const QString &channelId)
std::shared_ptr<Channel> TwitchServer::getChannelOrEmptyByID(
const QString &channelId)
{
std::lock_guard<std::mutex> lock(this->channelMutex);
@@ -184,8 +196,8 @@ bool TwitchServer::hasSeparateWriteConnection() const
// return getSettings()->twitchSeperateWriteConnection;
}
void TwitchServer::onMessageSendRequested(TwitchChannel *channel, const QString &message,
bool &sent)
void TwitchServer::onMessageSendRequested(TwitchChannel *channel,
const QString &message, bool &sent)
{
sent = false;
@@ -193,17 +205,19 @@ void TwitchServer::onMessageSendRequested(TwitchChannel *channel, const QString
std::lock_guard<std::mutex> guard(this->lastMessageMutex_);
// std::queue<std::chrono::steady_clock::time_point>
auto &lastMessage =
channel->hasModRights() ? this->lastMessageMod_ : this->lastMessagePleb_;
auto &lastMessage = channel->hasModRights() ? this->lastMessageMod_
: this->lastMessagePleb_;
size_t maxMessageCount = channel->hasModRights() ? 99 : 19;
auto minMessageOffset = (channel->hasModRights() ? 100ms : 1100ms);
auto now = std::chrono::steady_clock::now();
// check if you are sending messages too fast
if (!lastMessage.empty() && lastMessage.back() + minMessageOffset > now) {
if (!lastMessage.empty() &&
lastMessage.back() + minMessageOffset > now) {
if (this->lastErrorTimeSpeed_ + 30s < now) {
auto errorMessage = Message::createSystemMessage("sending messages too fast");
auto errorMessage =
Message::createSystemMessage("sending messages too fast");
channel->addMessage(errorMessage);
@@ -220,7 +234,8 @@ void TwitchServer::onMessageSendRequested(TwitchChannel *channel, const QString
// check if you are sending too many messages
if (lastMessage.size() >= maxMessageCount) {
if (this->lastErrorTimeAmount_ + 30s < now) {
auto errorMessage = Message::createSystemMessage("sending too many messages");
auto errorMessage =
Message::createSystemMessage("sending too many messages");
channel->addMessage(errorMessage);