Implement basic ClearChat handling

Fixes #56
This commit is contained in:
Rasmus Karlsson 2017-12-16 19:08:32 +01:00
parent b39034ab74
commit 6d56148ed2
3 changed files with 76 additions and 1 deletions

View file

@ -263,7 +263,49 @@ void IrcManager::handleRoomStateMessage(Communi::IrcMessage *message)
void IrcManager::handleClearChatMessage(Communi::IrcMessage *message) void IrcManager::handleClearChatMessage(Communi::IrcMessage *message)
{ {
// TODO: Implement assert(message->parameters().length() >= 1);
auto rawChannelName = message->parameter(0);
assert(rawChannelName.length() >= 2);
auto trimmedChannelName = rawChannelName.mid(1);
auto c = this->channelManager.getTwitchChannel(trimmedChannelName);
if (!c) {
debug::Log("[IrcManager:handleClearChatMessage] Channel {} not found in channel manager",
trimmedChannelName);
return;
}
if (message->parameters().length() == 1) {
std::shared_ptr<Message> msg(
Message::createSystemMessage("Chat has been cleared by a moderator."));
c->addMessage(msg);
return;
}
assert(message->parameters().length() >= 2);
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();
}
std::shared_ptr<Message> msg(
Message::createTimeoutMessage(username, durationInSeconds, reason));
c->addMessage(msg);
} }
void IrcManager::handleUserStateMessage(Communi::IrcMessage *message) void IrcManager::handleUserStateMessage(Communi::IrcMessage *message)

View file

@ -107,6 +107,36 @@ Message *Message::createSystemMessage(const QString &text)
return message; return message;
} }
Message *Message::createTimeoutMessage(const QString &username, const QString &durationInSeconds,
const QString &reason)
{
Message *message = new Message;
AddCurrentTimestamp(message);
QString text;
text.append(username);
text.append(" has been timed out");
// TODO: Implement who timed the user out
text.append(" for ");
text.append(durationInSeconds);
bool ok = true;
int timeoutDuration = durationInSeconds.toInt(&ok);
text.append(" second");
if (ok && timeoutDuration > 1) {
text.append("s");
}
if (reason.length() > 0) {
text.append(": \"");
text.append(reason);
text.append("\"");
}
text.append(".");
Word word(text, Word::Type::Default, MessageColor(MessageColor::Type::System), text, text); Word word(text, Word::Type::Default, MessageColor(MessageColor::Type::System), text, text);
message->getWords().push_back(word); message->getWords().push_back(word);

View file

@ -35,6 +35,9 @@ public:
static Message *createSystemMessage(const QString &text); static Message *createSystemMessage(const QString &text);
static Message *createTimeoutMessage(const QString &username, const QString &durationInSeconds,
const QString &reason);
private: private:
static LazyLoadedImage *badgeStaff; static LazyLoadedImage *badgeStaff;
static LazyLoadedImage *badgeAdmin; static LazyLoadedImage *badgeAdmin;