Skip to content

Commit

Permalink
fix parsing message containing both emoji and cheers
Browse files Browse the repository at this point in the history
fixes #107
  • Loading branch information
d-fischer committed Feb 25, 2020
1 parent 819a0d1 commit 888c51d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/twitch/src/API/Kraken/Bits/CheermoteList.ts
@@ -1,4 +1,4 @@
import { indexBy, NonEnumerable } from '@d-fischer/shared-utils';
import { indexBy, NonEnumerable, utf8Length } from '@d-fischer/shared-utils';
import HellFreezesOverError from '../../../Errors/HellFreezesOverError';
import TwitchClient from '../../../TwitchClient';

Expand Down Expand Up @@ -238,15 +238,14 @@ export default class CheermoteList {
// TODO fix this regex so it works in firefox, which does not support lookbehind
const re = new RegExp('(?<=^|\\s)([a-z0-9]+?)(\\d+)(?=\\s|$)', 'gi');
let match: RegExpExecArray | null;
// eslint-disable-next-line no-cond-assign
while ((match = re.exec(message))) {
const name = match[1].toLowerCase();
if (names.includes(name)) {
const amount = Number(match[2]);
result.push({
name,
amount,
position: match.index,
position: utf8Length(message.substr(0, match.index)),
length: match[0].length,
displayInfo: this.getCheermoteDisplayInfo(name, amount)
});
Expand Down

0 comments on commit 888c51d

Please sign in to comment.