Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EmoteSetList.findEmoteId throwing "Invalid regular expression" error #165

Closed
ebiggz opened this issue Aug 16, 2020 · 3 comments
Closed

EmoteSetList.findEmoteId throwing "Invalid regular expression" error #165

ebiggz opened this issue Aug 16, 2020 · 3 comments
Labels
Milestone

Comments

@ebiggz
Copy link

ebiggz commented Aug 16, 2020

Bug Report

Code

async function example() {
    const streamerEmotes = await twitchClient.kraken.users.getUserEmotes('58612601');
    const emoteId = await streamerEmotes.findEmoteId('PogChamp');
}

Expected behavior

To return correct emote id if a match is found, not throw an error.

Actual Behavior

Throws the following error:

{
  message: "Invalid regular expression: /8-)/: Unmatched ')'",
  stack: "SyntaxError: Invalid regular expression: /8-)/: Unmatched ')'\n" +
    '    at new RegExp (<anonymous>)\n' +
    '    at class_1.EmoteSetList.findEmoteId (C:\\Users\\ebiggz\\Documents\\GitHub\\Firebot\\node_modules\\twitch\\lib\\API\\Kraken\\Channel\\EmoteSetList.js:26:29)\n' +
    '    at class_1.<anonymous> (C:\\Users\\ebiggz\\Documents\\GitHub\\Firebot\\node_modules\\@d-fischer\\cache-decorators\\lib\\decorators\\Cached.js:25:57)\n' +
    '    at step (C:\\Users\\ebiggz\\Documents\\GitHub\\Firebot\\node_modules\\tslib\\tslib.js:136:27)\n' +
    '    at Object.next (C:\\Users\\ebiggz\\Documents\\GitHub\\Firebot\\node_modules\\tslib\\tslib.js:117:57)\n' +
    '    at C:\\Users\\ebiggz\\Documents\\GitHub\\Firebot\\node_modules\\tslib\\tslib.js:110:75\n' +
    '    at new Promise (<anonymous>)\n' +
    '    at Object.__awaiter (C:\\Users\\ebiggz\\Documents\\GitHub\\Firebot\\node_modules\\tslib\\tslib.js:106:16)\n' +
    '    at class_1.descriptor.value [as findEmoteId] (C:\\Users\\ebiggz\\Documents\\GitHub\\Firebot\\node_modules\\@d-fischer\\cache-decorators\\lib\\decorators\\Cached.js:15:28)\n' +
    '    at Object.exports.buildFirebotChatMessageFromText (C:\\Users\\ebiggz\\Documents\\GitHub\\Firebot\\backend\\chat\\chat-helpers.js:106:48)'
}

It appears emote.code needs to have RegEx characters escaped on this line:
https://github.com/d-fischer/twitch/blob/b28451c07cfe3f138250bd3eef55160380423660/packages/twitch/src/API/Kraken/Channel/EmoteSetList.ts#L29

Environment

  • Version: v4.1.3
  • Node version: v12.18.0
  • Browser version: Electron
  • Operating system: Windows 10
@ebiggz ebiggz added the bug label Aug 16, 2020
@d-fischer
Copy link
Member

It doesn't seem to be quite that simple. Some emote codes are actually regexes:

"code": "\\:-?\\)"

That's just the regular smiley face.
As you see, this one even has the closing brace properly escaped.
So it might be necessary to implement some kind of algorithm to determine whether or not a given emote code is a regex.
This probably needs to be throroughly tested to make sure not a single emote code gets misinterpreted or throws an error like this.

@ebiggz
Copy link
Author

ebiggz commented Aug 18, 2020

Ah shoot, I didn't realize some of the codes are already regexes, and ones that are properly escaped at that. That adds a frustrating layer of complexity. I am guessing Twitch recently updated some of the emote codes? We've been using .findEmoteId for awhile now and it only started throwing this error within the last week.

@d-fischer d-fischer added this to the 4.2 milestone Aug 26, 2020
@d-fischer
Copy link
Member

This should be fixed on the master branch. Please check out the prerelease version 4.2.0-pre.7 to check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants