feat: Allow id: prefix in /ban and /timeout (#4945)

ban example: `/ban id:70948394`, equivalent to `/banid 70948394`
timeout example: `/timeout id:70948394 10 xd`
This commit is contained in:
pajlada
2023-11-08 21:42:06 +01:00
committed by GitHub
parent 68817fa1a1
commit fcc5f4b3df
5 changed files with 243 additions and 59 deletions
+27
View File
@@ -62,6 +62,33 @@ void stripChannelName(QString &channelName)
}
}
std::pair<ParsedUserName, ParsedUserID> parseUserNameOrID(const QString &input)
{
if (input.startsWith("id:"))
{
return {
{},
input.mid(3),
};
}
QString userName = input;
if (userName.startsWith('@') || userName.startsWith('#'))
{
userName.remove(0, 1);
}
if (userName.endsWith(','))
{
userName.chop(1);
}
return {
userName,
{},
};
}
QRegularExpression twitchUserNameRegexp()
{
static QRegularExpression re(
+10
View File
@@ -16,6 +16,16 @@ void stripUserName(QString &userName);
// stripChannelName removes any @ prefix or , suffix to make it more suitable for command use
void stripChannelName(QString &channelName);
using ParsedUserName = QString;
using ParsedUserID = QString;
/**
* Parse the given input into either a user name or a user ID
*
* User IDs take priority and are parsed if the input starts with `id:`
*/
std::pair<ParsedUserName, ParsedUserID> parseUserNameOrID(const QString &input);
// Matches a strict Twitch user login.
// May contain lowercase a-z, 0-9, and underscores
// Must contain between 1 and 25 characters