Skip to content
This repository was archived by the owner on Feb 9, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unversioned

- Minor: Added support for the `submysterygift` message type ID in `UserNoticeMessage`.
- Bugfix: `ChatClient#connect()` method now properly resolves if `connect()` is called on a client that is already `ready`. (#218)

## v4.3.0
Expand Down
12 changes: 12 additions & 0 deletions lib/message/parser/twitch-message.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ describe("./message/parser/twitch-message", function () {
"turbo=0;user-id=269899575;user-type= :tmi.twitch.tv USERNOTICE #clippyassistant",
instanceOf: UsernoticeMessage,
},
{
irc:
"@badge-info=subscriber/12;badges=subscriber/12,premium/1;color=;display-name=yurixxxxx14;" +
"emotes=;flags=;id=99b77ba7-c77f-4d92-ac3a-ad556e921672;login=yurixxxxx14;mod=0;msg-id=submysterygift;" +
"msg-param-mass-gift-count=1;msg-param-origin-id=4e\\sd1\\s19\\sc5\\s33\\s80\\s68\\" +
"s8c\\sdc\\sc9\\s4d\\s96\\s73\\sd0\\sad\\s40\\s52\\sf3\\s19\\s02;" +
"msg-param-sender-count=1;msg-param-sub-plan=1000;room-id=38884180;subscriber=1;" +
"system-msg=yurixxxxx14\\sis\\sgifting\\s1\\sTier\\s1\\sSubs\\sto\\susertag's\\scommunity!" +
"\\sThey've\\sgifted\\sa\\stotal\\sof\\s1\\sin\\sthe\\schannel!;tmi-sent-ts=1633549401426;" +
"user-id=238886165;user-type= :tmi.twitch.tv USERNOTICE #usertag",
instanceOf: UsernoticeMessage,
},
{
irc:
"@badge-info=;badges=;color=;display-name=receivertest3;emote-sets=0;mod=0;" +
Expand Down
33 changes: 33 additions & 0 deletions lib/message/twitch-types/usernotice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ describe("./message/twitch-types/usernotice", function () {
shouldShareStreakRaw: "0",
subPlanName: "Channel Subscription (faker)",
subPlan: "1000",
subPlanRaw: "1000",
});

assert.isTrue(msg.isResub());
Expand Down Expand Up @@ -196,13 +197,45 @@ describe("./message/twitch-types/usernotice", function () {
months: 2,
monthsRaw: "2",
originID: "da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 90 af d8 07 09",
originIDRaw:
"da 39 a3 ee 5e 6b 4b 0d 32 55 bf ef 95 60 18 90 af d8 07 09",
recipientDisplayName: "qatarking24xd",
recipientID: "236653628",
recipientUsername: "qatarking24xd",
senderCount: 0,
senderCountRaw: "0",
subPlanName: "Channel Subscription (xqcow)",
subPlan: "1000",
subPlanRaw: "1000",
});
});

it("should be able to parse a masssubgift with message", function () {
const msg = parseTwitchMessage(
"@badge-info=subscriber/12;badges=subscriber/12,premium/1;color=;display-name=realuser;emotes=;flags=;id=99b77ba7-c77f-4d92-ac3a-ad556e921672;login=realuser;mod=0;msg-id=submysterygift;msg-param-mass-gift-count=1;msg-param-origin-id=4e\\sd1\\s19\\sc5\\s33\\s80\\s68\\s8c\\sdc\\sc9\\s4d\\s96\\s73\\sd0\\sad\\s40\\s52\\sf3\\s19\\s02;msg-param-sender-count=1;msg-param-sub-plan=1000;room-id=38244999;subscriber=1;system-msg=realuser\\sis\\sgifting\\s1\\sTier\\s1\\sSubs\\sto\\sbroadcaster's\\scommunity!\\sThey've\\sgifted\\sa\\stotal\\sof\\s1\\sin\\sthe\\schannel!;tmi-sent-ts=1633549401426;user-id=239909999;user-type= :tmi.twitch.tv USERNOTICE #broadcaster"
) as UsernoticeMessage;

assert.strictEqual(msg.ircCommand, "USERNOTICE");
assert.strictEqual(msg.ircParameters[0], "#broadcaster");
assert.strictEqual(msg.ircTags["msg-param-mass-gift-count"], "1");
assert.strictEqual(
msg.systemMessage,
"realuser is gifting 1 Tier 1 Subs to broadcaster's community! They've gifted a total of 1 in the channel!"
);
assert.strictEqual(msg.messageTypeID, "submysterygift");

assert.isTrue(msg.isMassSubgift());

assert.deepStrictEqual(msg.eventParams, {
massGiftCount: 1,
massGiftCountRaw: "1",
originID: "4e d1 19 c5 33 80 68 8c dc c9 4d 96 73 d0 ad 40 52 f3 19 02",
originIDRaw:
"4e d1 19 c5 33 80 68 8c dc c9 4d 96 73 d0 ad 40 52 f3 19 02",
senderCount: 1,
senderCountRaw: "1",
subPlan: "1000",
subPlanRaw: "1000",
});
});
});
Expand Down
17 changes: 17 additions & 0 deletions lib/message/twitch-types/usernotice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const convertersMap: Record<string, (value: string) => any> = {
"msg-param-streak-months": convertToInt,
"msg-param-viewerCount": convertToInt,
"msg-param-threshold": convertToInt,
"msg-param-mass-gift-count": convertToInt,
"msg-param-origin-id": convertToString,
"msg-param-sub-plan": convertToString,
};

export function getCamelCasedName(tagKey: string): string {
Expand Down Expand Up @@ -123,6 +126,12 @@ export interface SubgiftParameters extends EventParams {
}
export type AnonSubgiftParameters = SubgiftParameters;

// massgift
export interface MassSubgiftParameters extends EventParams {
massGiftCount: number;
subPlan: string;
}

// anongiftpaidupgrade
export type AnonGiftPaidUpgradeParameters = EventParams & {
promoGiftTotal?: number;
Expand Down Expand Up @@ -171,6 +180,10 @@ export type SubgiftUsernoticeMessage = SpecificUsernoticeMessage<
"subgift",
SubgiftParameters
>;
export type MassSubgiftUsernoticeMessage = SpecificUsernoticeMessage<
"submysterygift",
MassSubgiftParameters
>;
export type AnonSubgiftUsernoticeMessage = SpecificUsernoticeMessage<
"anonsubgift",
AnonSubgiftParameters
Expand Down Expand Up @@ -332,6 +345,10 @@ export class UsernoticeMessage extends ChannelIRCMessage {
return this.messageTypeID === "subgift";
}

public isMassSubgift(): this is MassSubgiftParameters {
return this.messageTypeID === "submysterygift";
}

public isAnonSubgift(): this is AnonSubgiftUsernoticeMessage {
return this.messageTypeID === "anonsubgift";
}
Expand Down