added regex highlights

This commit is contained in:
fourtf
2018-05-06 12:52:47 +02:00
parent ba4173822e
commit b95388107f
24 changed files with 388 additions and 139 deletions
+77 -75
View File
@@ -61,77 +61,79 @@ void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message)
void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
{
return;
// check parameter count
if (message->parameters().length() < 1) {
return;
}
// // check parameter count
// if (message->parameters().length() < 1) {
// return;
// }
QString chanName;
if (!TrimChannelName(message->parameter(0), chanName)) {
return;
}
// QString chanName;
// if (!TrimChannelName(message->parameter(0), chanName)) {
// return;
// }
auto app = getApp();
// auto app = getApp();
// get channel
auto chan = app->twitch.server->getChannelOrEmpty(chanName);
// // get channel
// auto chan = app->twitch.server->getChannelOrEmpty(chanName);
if (chan->isEmpty()) {
debug::Log("[IrcMessageHandler:handleClearChatMessage] Twitch channel {} not found",
chanName);
return;
}
// if (chan->isEmpty()) {
// debug::Log("[IrcMessageHandler:handleClearChatMessage] Twitch channel {} not found",
// chanName);
// return;
// }
// check if the chat has been cleared by a moderator
if (message->parameters().length() == 1) {
chan->addMessage(Message::createSystemMessage("Chat has been cleared by a moderator."));
// // check if the chat has been cleared by a moderator
// if (message->parameters().length() == 1) {
// chan->addMessage(Message::createSystemMessage("Chat has been cleared by a
// moderator."));
return;
}
// return;
// }
// get username, duration and message of the timed out user
QString username = message->parameter(1);
QString durationInSeconds, reason;
QVariant v = message->tag("ban-duration");
if (v.isValid()) {
durationInSeconds = v.toString();
}
// // get username, duration and message of the timed out user
// QString username = message->parameter(1);
// QString durationInSeconds, reason;
// QVariant v = message->tag("ban-duration");
// if (v.isValid()) {
// durationInSeconds = v.toString();
// }
v = message->tag("ban-reason");
if (v.isValid()) {
reason = v.toString();
}
// v = message->tag("ban-reason");
// if (v.isValid()) {
// reason = v.toString();
// }
// add the notice that the user has been timed out
LimitedQueueSnapshot<MessagePtr> snapshot = chan->getMessageSnapshot();
bool addMessage = true;
int snapshotLength = snapshot.getLength();
// // add the notice that the user has been timed out
// LimitedQueueSnapshot<MessagePtr> snapshot = chan->getMessageSnapshot();
// bool addMessage = true;
// int snapshotLength = snapshot.getLength();
for (int i = std::max(0, snapshotLength - 20); i < snapshotLength; i++) {
auto &s = snapshot[i];
if (s->flags.HasFlag(Message::Timeout) && s->timeoutUser == username) {
MessagePtr replacement(
Message::createTimeoutMessage(username, durationInSeconds, reason, true));
chan->replaceMessage(s, replacement);
addMessage = false;
break;
}
}
// for (int i = std::max(0, snapshotLength - 20); i < snapshotLength; i++) {
// auto &s = snapshot[i];
// if (s->flags.HasFlag(Message::Timeout) && s->timeoutUser == username) {
// MessagePtr replacement(
// Message::createTimeoutMessage(username, durationInSeconds, reason, true));
// chan->replaceMessage(s, replacement);
// addMessage = false;
// break;
// }
// }
if (addMessage) {
chan->addMessage(Message::createTimeoutMessage(username, durationInSeconds, reason, false));
}
// if (addMessage) {
// chan->addMessage(Message::createTimeoutMessage(username, durationInSeconds, reason,
// false));
// }
// disable the messages from the user
for (int i = 0; i < snapshotLength; i++) {
auto &s = snapshot[i];
if (!(s->flags & Message::Timeout) && s->loginName == username) {
s->flags.EnableFlag(Message::Disabled);
}
}
// // disable the messages from the user
// for (int i = 0; i < snapshotLength; i++) {
// auto &s = snapshot[i];
// if (!(s->flags & Message::Timeout) && s->loginName == username) {
// s->flags.EnableFlag(Message::Disabled);
// }
// }
// refresh all
app->windows->repaintVisibleChatWidgets(chan.get());
// // refresh all
// app->windows->repaintVisibleChatWidgets(chan.get());
}
void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
@@ -213,28 +215,28 @@ void IrcMessageHandler::handleModeMessage(Communi::IrcMessage *message)
void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
{
return;
auto app = getApp();
MessagePtr msg = Message::createSystemMessage(message->content());
// auto app = getApp();
// MessagePtr msg = Message::createSystemMessage(message->content());
QString channelName;
if (!TrimChannelName(message->target(), channelName)) {
// Notice wasn't targeted at a single channel, send to all twitch channels
app->twitch.server->forEachChannelAndSpecialChannels([msg](const auto &c) {
c->addMessage(msg); //
});
// QString channelName;
// if (!TrimChannelName(message->target(), channelName)) {
// // Notice wasn't targeted at a single channel, send to all twitch channels
// app->twitch.server->forEachChannelAndSpecialChannels([msg](const auto &c) {
// c->addMessage(msg); //
// });
return;
}
// return;
// }
auto channel = app->twitch.server->getChannelOrEmpty(channelName);
// auto channel = app->twitch.server->getChannelOrEmpty(channelName);
if (channel->isEmpty()) {
debug::Log("[IrcManager:handleNoticeMessage] Channel {} not found in channel manager",
channelName);
return;
}
// if (channel->isEmpty()) {
// debug::Log("[IrcManager:handleNoticeMessage] Channel {} not found in channel manager",
// channelName);
// return;
// }
channel->addMessage(msg);
// channel->addMessage(msg);
}
void IrcMessageHandler::handleWriteConnectionNoticeMessage(Communi::IrcNoticeMessage *message)
+7 -1
View File
@@ -7,7 +7,8 @@ namespace twitch {
TwitchAccount::TwitchAccount(const QString &_username, const QString &_oauthToken,
const QString &_oauthClient, const QString &_userID)
: oauthClient(_oauthClient)
: controllers::accounts::Account("Twitch")
, oauthClient(_oauthClient)
, oauthToken(_oauthToken)
, userName(_username)
, userId(_userID)
@@ -15,6 +16,11 @@ TwitchAccount::TwitchAccount(const QString &_username, const QString &_oauthToke
{
}
QString TwitchAccount::toString() const
{
return this->getUserName();
}
const QString &TwitchAccount::getUserName() const
{
return this->userName;
+5 -1
View File
@@ -3,16 +3,20 @@
#include <QColor>
#include <QString>
#include "controllers/accounts/account.hpp"
namespace chatterino {
namespace providers {
namespace twitch {
class TwitchAccount
class TwitchAccount : public controllers::accounts::Account
{
public:
TwitchAccount(const QString &username, const QString &oauthToken, const QString &oauthClient,
const QString &_userID);
virtual QString toString() const override;
const QString &getUserName() const;
const QString &getOAuthToken() const;
const QString &getOAuthClient() const;
@@ -94,7 +94,7 @@ void TwitchAccountManager::reloadUsers()
debug::Log("User {} already exists, and values updated!", userData.username);
if (userData.username == this->getCurrent()->getUserName()) {
debug::Log("It was the current user, so we need to reconnect stuff!");
this->userChanged.invoke();
this->currentUserChanged.invoke();
}
} break;
case AddUserResponse::UserAdded: {
@@ -126,7 +126,7 @@ void TwitchAccountManager::load()
this->currentUser = this->anonymousUser;
}
this->userChanged.invoke();
this->currentUserChanged.invoke();
});
}
@@ -1,6 +1,8 @@
#pragma once
#include "providers/twitch/twitchaccount.hpp"
#include "util/sharedptrelementless.hpp"
#include "util/signalvector2.hpp"
#include <pajlada/settings/setting.hpp>
@@ -47,9 +49,13 @@ public:
bool removeUser(const QString &username);
pajlada::Settings::Setting<std::string> currentUsername = {"/accounts/current", ""};
pajlada::Signals::NoArgSignal userChanged;
pajlada::Signals::NoArgSignal currentUserChanged;
pajlada::Signals::NoArgSignal userListUpdated;
util::SortedSignalVector<std::shared_ptr<TwitchAccount>,
util::SharedPtrElementLess<TwitchAccount>>
accounts;
private:
enum class AddUserResponse {
UserAlreadyExists,
+2 -2
View File
@@ -45,7 +45,7 @@ TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection
this->refreshLiveStatus(); //
});
this->managedConnect(app->accounts->Twitch.userChanged, [this]() { this->setMod(false); });
this->managedConnect(app->accounts->Twitch.currentUserChanged, [this]() { this->setMod(false); });
auto refreshPubSubState = [=]() {
if (!this->hasModRights()) {
@@ -64,7 +64,7 @@ TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection
this->userStateChanged.connect(refreshPubSubState);
this->roomIDchanged.connect(refreshPubSubState);
this->managedConnect(app->accounts->Twitch.userChanged, refreshPubSubState);
this->managedConnect(app->accounts->Twitch.currentUserChanged, refreshPubSubState);
refreshPubSubState();
this->fetchMessages.connect([this] {
+10 -20
View File
@@ -404,10 +404,9 @@ void TwitchMessageBuilder::parseHighlights()
app->highlights->phrases.getVector();
if (app->settings->enableHighlightsSelf && currentUsername.size() > 0) {
controllers::highlights::HighlightPhrase selfHighlight;
selfHighlight.key = currentUsername;
selfHighlight.sound = app->settings->enableHighlightSound;
selfHighlight.alert = app->settings->enableHighlightTaskbar;
controllers::highlights::HighlightPhrase selfHighlight(
currentUsername, app->settings->enableHighlightTaskbar,
app->settings->enableHighlightSound, false);
activeHighlights.emplace_back(std::move(selfHighlight));
}
@@ -419,26 +418,17 @@ void TwitchMessageBuilder::parseHighlights()
if (!blackList.contains(this->ircMessage->nick(), Qt::CaseInsensitive)) {
for (const controllers::highlights::HighlightPhrase &highlight : activeHighlights) {
int index = -1;
while ((index = this->originalMessage.indexOf(highlight.key, index + 1,
Qt::CaseInsensitive)) != -1) {
if ((index != 0 && this->originalMessage[index - 1] != ' ') ||
(index + highlight.key.length() != this->originalMessage.length() &&
this->originalMessage[index + highlight.key.length()] != ' ')) {
continue;
}
debug::Log("Highlight because {} contains {}", this->originalMessage,
highlight.key);
if (highlight.isMatch(this->originalMessage)) {
debug::Log("Highlight because {} matches {}", this->originalMessage,
highlight.getPattern());
doHighlight = true;
if (highlight.sound) {
playSound = true;
if (highlight.getAlert()) {
doAlert = true;
}
if (highlight.alert) {
doAlert = true;
if (highlight.getSound()) {
playSound = true;
}
if (playSound && doAlert) {
+1 -1
View File
@@ -27,7 +27,7 @@ TwitchServer::TwitchServer()
void TwitchServer::initialize()
{
getApp()->accounts->Twitch.userChanged.connect(
getApp()->accounts->Twitch.currentUserChanged.connect(
[this]() { util::postToThread([this] { this->connect(); }); });
}