From 7309fd8668a92b213a109067021efaab38cbe81f Mon Sep 17 00:00:00 2001 From: sando Date: Sun, 8 Aug 2021 21:23:54 +1000 Subject: [PATCH] Strip leading @ and trailing , from /user and /usercard commands (#3143) Co-authored-by: Rasmus Karlsson --- CHANGELOG.md | 1 + .../commands/CommandController.cpp | 41 ++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 397e15c2..f7cca4f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unversioned - Minor: Remove TwitchEmotes.com attribution and the open/copy options when right-clicking a Twitch Emote. (#2214, #3136) +- Minor: Strip leading @ and trailing , from username in /user and /usercard commands. (#3143) - Minor: Display a system message when reloading subscription emotes to match BTTV/FFZ behavior (#3135) - Bugfix: Moderation mode and active filters are now preserved when opening a split as a popup. (#3113, #3130) - Bugfix: Fixed a bug that caused all badge highlights to use the same color. (#3132, #3134) diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 333c2925..8e977af9 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -70,6 +70,32 @@ static const QStringList twitchDefaultCommands{ static const QStringList whisperCommands{"/w", ".w"}; +// stripUserName removes any @ prefix or , suffix to make it more suitable for command use +void stripUserName(QString &userName) +{ + if (userName.startsWith('@')) + { + userName.remove(0, 1); + } + if (userName.endsWith(',')) + { + userName.chop(1); + } +} + +// stripChannelName removes any @ prefix or , suffix to make it more suitable for command use +void stripChannelName(QString &channelName) +{ + if (channelName.startsWith('@') || channelName.startsWith('#')) + { + channelName.remove(0, 1); + } + if (channelName.endsWith(',')) + { + channelName.chop(1); + } +} + void sendWhisperMessage(const QString &text) { // (hemirt) pajlada: "we should not be sending whispers through jtv, but @@ -430,16 +456,17 @@ void CommandController::initialize(Settings &, Paths &paths) makeSystemMessage("Usage /user [user] (channel)")); return ""; } + QString userName = words[1]; + stripUserName(userName); + QString channelName = channel->getName(); + if (words.size() > 2) { channelName = words[2]; - if (channelName[0] == '#') - { - channelName.remove(0, 1); - } + stripChannelName(channelName); } - openTwitchUsercard(channelName, words[1]); + openTwitchUsercard(channelName, userName); return ""; }); @@ -451,10 +478,12 @@ void CommandController::initialize(Settings &, Paths &paths) return ""; } + QString userName = words[1]; + stripUserName(userName); auto *userPopup = new UserInfoPopup( getSettings()->autoCloseUserPopup, static_cast(&(getApp()->windows->getMainWindow()))); - userPopup->setData(words[1], channel); + userPopup->setData(userName, channel); userPopup->move(QCursor::pos()); userPopup->show(); return "";