Skip to content

Commit

Permalink
fix: remove the empty unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
Geczy committed Sep 2, 2023
1 parent 6032275 commit c4a4470
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/dota/src/twitch/lib/CommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ class CommandHandler {
// Function for parsing a Twitch chat message to extract the command and its arguments
parseMessage(message: MessageType) {
// Use a regular expression to match the command and its arguments
const match = message.content.match(/^!(\w+=?)\s*(.*)/)
// `/\uDB40\uDC00/g` is unicode empty space that 7tv adds to spam a command
const match = message.content.replace(/\uDB40\uDC00/g, '').match(/^!(\w+=?)\s*(.*)/)

if (!match) {
return [] // Return an empty array if the message is not a command
Expand All @@ -177,18 +178,18 @@ class CommandHandler {
// Split the arguments on spaces, while taking into account quoted strings
const args = match[2].match(/\S+|"[^"]+"/g)
if (args === null) {
return [match[1].toLowerCase()] // Return the command if there are no arguments
return [match[1].toLowerCase().trim()] // Return the command if there are no arguments
}

// Strip the quotes from the quoted arguments
for (let i = 0; i < args.length; i++) {
if (args[i].startsWith('"')) {
args[i] = args[i].slice(1, -1)
args[i] = args[i].slice(1, -1).trim()
}
}

// Return the command and its arguments
return [match[1].toLowerCase(), ...args]
return [match[1].toLowerCase().trim(), ...args]
}

// Function for checking if a command is on cooldown
Expand Down

0 comments on commit c4a4470

Please sign in to comment.