Skip to content

Commit

Permalink
add TwitchPrivateMessage#bits, deprecate totalBits instead
Browse files Browse the repository at this point in the history
  • Loading branch information
d-fischer committed Dec 6, 2020
1 parent eb3b84e commit 8c1442a
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,69 @@ import { ChatUser } from '../ChatUser';
import type { ParsedMessageCheerPart, ParsedMessagePart } from '../Toolkit/EmoteTools';
import { fillTextPositions, parseEmoteOffsets, parseEmotePositions } from '../Toolkit/EmoteTools';

/**
* An IRC PRIVMSG, with easy accessors for commonly used data from its tags.
*/
export class TwitchPrivateMessage extends MessageTypes.Commands.PrivateMessage {
/**
* Info about the user that send the message, like their user ID and their status in the current channel.
*/
get userInfo(): ChatUser {
return new ChatUser(this._prefix!.nick, this._tags);
}

/**
* The ID of the channel the message is in.
*/
get channelId(): string | null {
return this._tags.get('room-id') ?? null;
}

/**
* Whether the message is a cheer.
*/
get isCheer(): boolean {
return this._tags.has('bits') ?? false;
}

get totalBits(): number {
/**
* The number of bits cheered with the message.
*/
get bits(): number {
return Number(this._tags.get('bits') ?? 0);
}

/**
* The number of bits cheered with the message.
*
* @deprecated Use {@TwitchPrivateMessage#bits} instead.
*/
get totalBits(): number {
return this.bits;
}

/**
* The offsets of emote usages in the message.
*/
get emoteOffsets(): Map<string, string[]> {
return parseEmoteOffsets(this._tags.get('emotes'));
}

/**
* Parses the message, separating text from emote usages.
*/
parseEmotes(): ParsedMessagePart[] {
const messageText = this.params.message;
const foundEmotes: ParsedMessagePart[] = parseEmotePositions(messageText, this.emoteOffsets);

return fillTextPositions(messageText, foundEmotes);
}

/**
* Parses the message, separating text from emote usages and cheers.
*
* @param cheermotes A list of cheermotes
*/
parseEmotesAndBits(cheermotes: CheermoteList): ParsedMessagePart[] {
const messageText = this.params.message;
const foundCheermotes = cheermotes.parseMessage(messageText);
Expand Down

0 comments on commit 8c1442a

Please sign in to comment.