mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
added basic keyword ignore setting
This commit is contained in:
parent
91d45214d9
commit
dd05ea28fe
13 changed files with 195 additions and 7 deletions
|
@ -163,7 +163,9 @@ SOURCES += \
|
||||||
src/widgets/basewindow.cpp \
|
src/widgets/basewindow.cpp \
|
||||||
src/singletons/helper/moderationaction.cpp \
|
src/singletons/helper/moderationaction.cpp \
|
||||||
src/widgets/streamview.cpp \
|
src/widgets/streamview.cpp \
|
||||||
src/util/networkrequest.cpp
|
src/util/networkrequest.cpp \
|
||||||
|
src/widgets/settingspages/ignoreuserspage.cpp \
|
||||||
|
src/widgets/settingspages/ignoremessagespage.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/precompiled_header.hpp \
|
src/precompiled_header.hpp \
|
||||||
|
@ -266,7 +268,9 @@ HEADERS += \
|
||||||
src/widgets/streamview.hpp \
|
src/widgets/streamview.hpp \
|
||||||
src/util/networkrequest.hpp \
|
src/util/networkrequest.hpp \
|
||||||
src/util/networkworker.hpp \
|
src/util/networkworker.hpp \
|
||||||
src/util/networkrequester.hpp
|
src/util/networkrequester.hpp \
|
||||||
|
src/widgets/settingspages/ignoreuserspage.hpp \
|
||||||
|
src/widgets/settingspages/ignoremessagespage.hpp
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources/resources.qrc
|
resources/resources.qrc
|
||||||
|
|
|
@ -255,7 +255,9 @@ void IrcManager::privateMessageReceived(Communi::IrcPrivateMessage *message)
|
||||||
|
|
||||||
twitch::TwitchMessageBuilder builder(c.get(), message, args);
|
twitch::TwitchMessageBuilder builder(c.get(), message, args);
|
||||||
|
|
||||||
c->addMessage(builder.parse());
|
if (!builder.isIgnored()) {
|
||||||
|
c->addMessage(builder.parse());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IrcManager::messageReceived(Communi::IrcMessage *message)
|
void IrcManager::messageReceived(Communi::IrcMessage *message)
|
||||||
|
|
|
@ -17,6 +17,7 @@ void _registerSetting(std::weak_ptr<pajlada::Settings::ISettingData> setting)
|
||||||
|
|
||||||
SettingManager::SettingManager()
|
SettingManager::SettingManager()
|
||||||
: snapshot(nullptr)
|
: snapshot(nullptr)
|
||||||
|
, _ignoredKeywords(new std::vector<QString>)
|
||||||
{
|
{
|
||||||
this->wordFlagsListener.addSetting(this->showTimestamps);
|
this->wordFlagsListener.addSetting(this->showTimestamps);
|
||||||
this->wordFlagsListener.addSetting(this->showBadges);
|
this->wordFlagsListener.addSetting(this->showBadges);
|
||||||
|
@ -29,6 +30,7 @@ SettingManager::SettingManager()
|
||||||
};
|
};
|
||||||
|
|
||||||
this->moderationActions.connect([this](auto, auto) { this->updateModerationActions(); });
|
this->moderationActions.connect([this](auto, auto) { this->updateModerationActions(); });
|
||||||
|
this->ignoredKeywords.connect([this](auto, auto) { this->updateIgnoredKeywords(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageElement::Flags SettingManager::getWordFlags()
|
MessageElement::Flags SettingManager::getWordFlags()
|
||||||
|
@ -135,6 +137,11 @@ std::vector<ModerationAction> SettingManager::getModerationActions() const
|
||||||
return this->_moderationActions;
|
return this->_moderationActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::shared_ptr<std::vector<QString>> SettingManager::getIgnoredKeywords() const
|
||||||
|
{
|
||||||
|
return this->_ignoredKeywords;
|
||||||
|
}
|
||||||
|
|
||||||
void SettingManager::updateModerationActions()
|
void SettingManager::updateModerationActions()
|
||||||
{
|
{
|
||||||
auto &resources = singletons::ResourceManager::getInstance();
|
auto &resources = singletons::ResourceManager::getInstance();
|
||||||
|
@ -202,5 +209,18 @@ void SettingManager::updateModerationActions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingManager::updateIgnoredKeywords()
|
||||||
|
{
|
||||||
|
static QRegularExpression newLineRegex("(\r\n?|\n)+");
|
||||||
|
|
||||||
|
auto items = new std::vector<QString>();
|
||||||
|
|
||||||
|
for (QString line : this->ignoredKeywords.getValue().split(newLineRegex)) {
|
||||||
|
items->push_back(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->_ignoredKeywords = std::shared_ptr<std::vector<QString>>(items);
|
||||||
|
}
|
||||||
} // namespace singletons
|
} // namespace singletons
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -75,6 +75,10 @@ public:
|
||||||
/// Links
|
/// Links
|
||||||
BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false};
|
BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false};
|
||||||
|
|
||||||
|
/// Ingored Users
|
||||||
|
BoolSetting enableTwitchIgnoredUsers = {"/ignore/enableTwitchIgnoredUsers", true};
|
||||||
|
QStringSetting ignoredKeywords = {"/ignore/ignoredKeywords", ""};
|
||||||
|
|
||||||
/// Moderation
|
/// Moderation
|
||||||
QStringSetting moderationActions = {"/moderation/actions", "/ban {user}\n/timeout {user} 300"};
|
QStringSetting moderationActions = {"/moderation/actions", "/ban {user}\n/timeout {user} 300"};
|
||||||
|
|
||||||
|
@ -107,6 +111,7 @@ public:
|
||||||
void recallSnapshot();
|
void recallSnapshot();
|
||||||
|
|
||||||
std::vector<ModerationAction> getModerationActions() const;
|
std::vector<ModerationAction> getModerationActions() const;
|
||||||
|
const std::shared_ptr<std::vector<QString>> getIgnoredKeywords() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void wordFlagsChanged();
|
void wordFlagsChanged();
|
||||||
|
@ -114,10 +119,12 @@ signals:
|
||||||
private:
|
private:
|
||||||
std::vector<ModerationAction> _moderationActions;
|
std::vector<ModerationAction> _moderationActions;
|
||||||
std::unique_ptr<rapidjson::Document> snapshot;
|
std::unique_ptr<rapidjson::Document> snapshot;
|
||||||
|
std::shared_ptr<std::vector<QString>> _ignoredKeywords;
|
||||||
|
|
||||||
SettingManager();
|
SettingManager();
|
||||||
|
|
||||||
void updateModerationActions();
|
void updateModerationActions();
|
||||||
|
void updateIgnoredKeywords();
|
||||||
|
|
||||||
messages::MessageElement::Flags wordFlags = messages::MessageElement::Default;
|
messages::MessageElement::Flags wordFlags = messages::MessageElement::Default;
|
||||||
|
|
||||||
|
|
|
@ -230,7 +230,6 @@ void TwitchChannel::fetchRecentMessages()
|
||||||
auto msgArray = obj.value("messages").toArray();
|
auto msgArray = obj.value("messages").toArray();
|
||||||
if (msgArray.size() > 0) {
|
if (msgArray.size() > 0) {
|
||||||
std::vector<messages::MessagePtr> messages;
|
std::vector<messages::MessagePtr> messages;
|
||||||
messages.resize(msgArray.size());
|
|
||||||
|
|
||||||
for (int i = 0; i < msgArray.size(); i++) {
|
for (int i = 0; i < msgArray.size(); i++) {
|
||||||
QByteArray content = msgArray[i].toString().toUtf8();
|
QByteArray content = msgArray[i].toString().toUtf8();
|
||||||
|
@ -239,7 +238,9 @@ void TwitchChannel::fetchRecentMessages()
|
||||||
|
|
||||||
messages::MessageParseArgs args;
|
messages::MessageParseArgs args;
|
||||||
twitch::TwitchMessageBuilder builder(channel, privMsg, args);
|
twitch::TwitchMessageBuilder builder(channel, privMsg, args);
|
||||||
messages.at(i) = builder.parse();
|
if (!builder.isIgnored()) {
|
||||||
|
messages.push_back(builder.parse());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
channel->addMessagesAtStart(messages);
|
channel->addMessagesAtStart(messages);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,21 @@ TwitchMessageBuilder::TwitchMessageBuilder(Channel *_channel,
|
||||||
, tags(this->ircMessage->tags())
|
, tags(this->ircMessage->tags())
|
||||||
, usernameColor(singletons::ThemeManager::getInstance().messages.textColors.system)
|
, usernameColor(singletons::ThemeManager::getInstance().messages.textColors.system)
|
||||||
{
|
{
|
||||||
|
this->originalMessage = this->ircMessage->content();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TwitchMessageBuilder::isIgnored() const
|
||||||
|
{
|
||||||
|
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
||||||
|
std::shared_ptr<std::vector<QString>> ignoredKeywords = settings.getIgnoredKeywords();
|
||||||
|
|
||||||
|
for (const QString &keyword : *ignoredKeywords) {
|
||||||
|
if (this->originalMessage.contains(keyword, Qt::CaseInsensitive)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagePtr TwitchMessageBuilder::parse()
|
MessagePtr TwitchMessageBuilder::parse()
|
||||||
|
@ -34,8 +49,6 @@ MessagePtr TwitchMessageBuilder::parse()
|
||||||
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
||||||
singletons::EmoteManager &emoteManager = singletons::EmoteManager::getInstance();
|
singletons::EmoteManager &emoteManager = singletons::EmoteManager::getInstance();
|
||||||
|
|
||||||
this->originalMessage = this->ircMessage->content();
|
|
||||||
|
|
||||||
// PARSING
|
// PARSING
|
||||||
this->parseUsername();
|
this->parseUsername();
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
QString messageID;
|
QString messageID;
|
||||||
QString userName;
|
QString userName;
|
||||||
|
|
||||||
|
bool isIgnored() const;
|
||||||
messages::MessagePtr parse();
|
messages::MessagePtr parse();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -47,6 +47,18 @@ public:
|
||||||
return LayoutCreator<T2>(t);
|
return LayoutCreator<T2>(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T2, typename Q = T,
|
||||||
|
typename std::enable_if<std::is_base_of<QWidget, Q>::value, int>::type = 0,
|
||||||
|
typename std::enable_if<std::is_base_of<QLayout, T2>::value, int>::type = 0>
|
||||||
|
LayoutCreator<T2> setLayoutType()
|
||||||
|
{
|
||||||
|
T2 *layout = new T2;
|
||||||
|
|
||||||
|
this->item->setLayout(layout);
|
||||||
|
|
||||||
|
return LayoutCreator<T2>(layout);
|
||||||
|
}
|
||||||
|
|
||||||
LayoutCreator<T> assign(T **ptr)
|
LayoutCreator<T> assign(T **ptr)
|
||||||
{
|
{
|
||||||
*ptr = this->item;
|
*ptr = this->item;
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include "widgets/settingspages/commandpage.hpp"
|
#include "widgets/settingspages/commandpage.hpp"
|
||||||
#include "widgets/settingspages/emotespage.hpp"
|
#include "widgets/settingspages/emotespage.hpp"
|
||||||
#include "widgets/settingspages/highlightingpage.hpp"
|
#include "widgets/settingspages/highlightingpage.hpp"
|
||||||
|
#include "widgets/settingspages/ignoremessagespage.hpp"
|
||||||
|
#include "widgets/settingspages/ignoreuserspage.hpp"
|
||||||
#include "widgets/settingspages/logspage.hpp"
|
#include "widgets/settingspages/logspage.hpp"
|
||||||
#include "widgets/settingspages/moderationpage.hpp"
|
#include "widgets/settingspages/moderationpage.hpp"
|
||||||
|
|
||||||
|
@ -77,6 +79,8 @@ void SettingsDialog::addTabs()
|
||||||
this->addTab(new settingspages::BehaviourPage);
|
this->addTab(new settingspages::BehaviourPage);
|
||||||
this->addTab(new settingspages::CommandPage);
|
this->addTab(new settingspages::CommandPage);
|
||||||
this->addTab(new settingspages::EmotesPage);
|
this->addTab(new settingspages::EmotesPage);
|
||||||
|
this->addTab(new settingspages::IgnoreUsersPage);
|
||||||
|
this->addTab(new settingspages::IgnoreMessagesPage);
|
||||||
this->addTab(new settingspages::HighlightingPage);
|
this->addTab(new settingspages::HighlightingPage);
|
||||||
// this->addTab(new settingspages::LogsPage);
|
// this->addTab(new settingspages::LogsPage);
|
||||||
this->addTab(new settingspages::ModerationPage);
|
this->addTab(new settingspages::ModerationPage);
|
||||||
|
|
39
src/widgets/settingspages/ignoremessagespage.cpp
Normal file
39
src/widgets/settingspages/ignoremessagespage.cpp
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
#include "ignoremessagespage.hpp"
|
||||||
|
|
||||||
|
#include "util/layoutcreator.hpp"
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QTextEdit>
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
namespace widgets {
|
||||||
|
namespace settingspages {
|
||||||
|
IgnoreMessagesPage::IgnoreMessagesPage()
|
||||||
|
: SettingsPage("Ignore Messages", ":/images/theme.svg")
|
||||||
|
{
|
||||||
|
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
||||||
|
util::LayoutCreator<IgnoreMessagesPage> layoutCreator(this);
|
||||||
|
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
|
||||||
|
|
||||||
|
layout.emplace<QLabel>("Ignored keywords:");
|
||||||
|
QTextEdit *textEdit = layout.emplace<QTextEdit>().getElement();
|
||||||
|
|
||||||
|
textEdit->setPlainText(settings.ignoredKeywords);
|
||||||
|
|
||||||
|
QObject::connect(textEdit, &QTextEdit::textChanged,
|
||||||
|
[this] { this->keywordsUpdated.start(200); });
|
||||||
|
|
||||||
|
QObject::connect(&this->keywordsUpdated, &QTimer::timeout, [textEdit, &settings] {
|
||||||
|
QString text = textEdit->toPlainText();
|
||||||
|
|
||||||
|
settings.ignoredKeywords = text;
|
||||||
|
|
||||||
|
qDebug() << "xD";
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---- misc
|
||||||
|
this->keywordsUpdated.setSingleShot(true);
|
||||||
|
}
|
||||||
|
} // namespace settingspages
|
||||||
|
} // namespace widgets
|
||||||
|
} // namespace chatterino
|
19
src/widgets/settingspages/ignoremessagespage.hpp
Normal file
19
src/widgets/settingspages/ignoremessagespage.hpp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
#include "widgets/settingspages/settingspage.hpp"
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
namespace widgets {
|
||||||
|
namespace settingspages {
|
||||||
|
|
||||||
|
class IgnoreMessagesPage : public SettingsPage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IgnoreMessagesPage();
|
||||||
|
|
||||||
|
QTimer keywordsUpdated;
|
||||||
|
};
|
||||||
|
} // namespace settingspages
|
||||||
|
} // namespace widgets
|
||||||
|
} // namespace chatterino
|
51
src/widgets/settingspages/ignoreuserspage.cpp
Normal file
51
src/widgets/settingspages/ignoreuserspage.cpp
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#include "ignoreuserspage.hpp"
|
||||||
|
|
||||||
|
#include "singletons/settingsmanager.hpp"
|
||||||
|
#include "util/layoutcreator.hpp"
|
||||||
|
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QListView>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
#define INFO "/ignore <user> in chat ignores a user\n/unignore <user> in chat unignores a user\n\nChatterino uses the twitch api for ignored users so they are shared with the webchat.\nIf you use your own oauth key make sure that it has the correct permissions."
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
namespace widgets {
|
||||||
|
namespace settingspages {
|
||||||
|
IgnoreUsersPage::IgnoreUsersPage()
|
||||||
|
: SettingsPage("Ignore Users", ":/images/theme.svg")
|
||||||
|
{
|
||||||
|
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
|
||||||
|
util::LayoutCreator<IgnoreUsersPage> layoutCreator(this);
|
||||||
|
auto layout = layoutCreator.setLayoutType<QVBoxLayout>().withoutMargin();
|
||||||
|
|
||||||
|
auto label = layout.emplace<QLabel>(INFO);
|
||||||
|
label->setWordWrap(true);
|
||||||
|
label->setStyleSheet("color: #BBB");
|
||||||
|
|
||||||
|
layout.append(
|
||||||
|
this->createCheckBox("Enable twitch ignored users", settings.enableTwitchIgnoredUsers));
|
||||||
|
|
||||||
|
auto anyways = layout.emplace<QHBoxLayout>().withoutMargin();
|
||||||
|
{
|
||||||
|
anyways.emplace<QLabel>("Show anyways if:");
|
||||||
|
anyways.emplace<QComboBox>();
|
||||||
|
anyways->addStretch(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto addremove = layout.emplace<QHBoxLayout>().withoutMargin();
|
||||||
|
{
|
||||||
|
auto add = addremove.emplace<QPushButton>("Ignore user");
|
||||||
|
auto remove = addremove.emplace<QPushButton>("Unignore User");
|
||||||
|
addremove->addStretch(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto userList = layout.emplace<QListView>();
|
||||||
|
}
|
||||||
|
} // namespace settingspages
|
||||||
|
} // namespace widgets
|
||||||
|
} // namespace chatterino
|
15
src/widgets/settingspages/ignoreuserspage.hpp
Normal file
15
src/widgets/settingspages/ignoreuserspage.hpp
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "widgets/settingspages/settingspage.hpp"
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
namespace widgets {
|
||||||
|
namespace settingspages {
|
||||||
|
class IgnoreUsersPage : public SettingsPage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IgnoreUsersPage();
|
||||||
|
};
|
||||||
|
} // namespace settingspages
|
||||||
|
} // namespace widgets
|
||||||
|
} // namespace chatterino
|
Loading…
Reference in a new issue