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
+110
View File
@@ -160,6 +160,116 @@ TEST(UtilTwitch, StripChannelName)
}
}
TEST(UtilTwitch, ParseUserNameOrID)
{
struct TestCase {
QString input;
QString expectedUserName;
QString expectedUserID;
};
std::vector<TestCase> tests{
{
"pajlada",
"pajlada",
{},
},
{
"Pajlada",
"Pajlada",
{},
},
{
"@Pajlada",
"Pajlada",
{},
},
{
"#Pajlada",
"Pajlada",
{},
},
{
"#Pajlada,",
"Pajlada",
{},
},
{
"#Pajlada,",
"Pajlada",
{},
},
{
"@@Pajlada,",
"@Pajlada",
{},
},
{
// We only strip one character off the front
"#@Pajlada,",
"@Pajlada",
{},
},
{
"@@Pajlada,,",
"@Pajlada,",
{},
},
{
"",
"",
{},
},
{
"@",
"",
{},
},
{
",",
"",
{},
},
{
// We purposefully don't handle spaces at the end, as all expected usages of this function split the message up by space and strip the parameters by themselves
", ",
", ",
{},
},
{
// We purposefully don't handle spaces at the start, as all expected usages of this function split the message up by space and strip the parameters by themselves
" #",
" #",
{},
},
{
"id:123",
{},
"123",
},
{
"id:",
{},
"",
},
};
for (const auto &[input, expectedUserName, expectedUserID] : tests)
{
auto [actualUserName, actualUserID] = parseUserNameOrID(input);
EXPECT_EQ(actualUserName, expectedUserName)
<< "name " << qUtf8Printable(actualUserName) << " ("
<< qUtf8Printable(input) << ") did not match expected value "
<< qUtf8Printable(expectedUserName);
EXPECT_EQ(actualUserID, expectedUserID)
<< "id " << qUtf8Printable(actualUserID) << " ("
<< qUtf8Printable(input) << ") did not match expected value "
<< qUtf8Printable(expectedUserID);
}
}
TEST(UtilTwitch, UserLoginRegexp)
{
struct TestCase {