Skip to content

Commit

Permalink
fix(twitch): add subcommunitygift tier
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Mar 5, 2024
1 parent 35dd5ed commit a3eba63
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"license": "MIT",
"dependencies": {
"@d-fischer/shared-utils": "^3.6.3",
"@twurple/api": "7.0.6",
"@twurple/auth": "7.0.6",
"@twurple/chat": "7.0.6",
"@twurple/eventsub-base": "^7.0.6",
"@twurple/eventsub-ws": "7.0.6",
"@twurple/pubsub": "7.0.6",
"@twurple/api": "7.0.10",
"@twurple/auth": "7.0.10",
"@twurple/chat": "7.0.10",
"@twurple/eventsub-base": "^7.0.10",
"@twurple/eventsub-ws": "7.0.10",
"@twurple/pubsub": "7.0.10",
"async-mutex": "^0.4.0",
"axios": "1.6.2",
"basic-auth": "2.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Events extends Core {
{ id: 'follow', variables: [ 'username', 'is.moderator', 'is.subscriber', 'is.vip', 'is.broadcaster', 'is.bot', 'is.owner' ] },
{ id: 'subscription', variables: [ 'username', 'is.moderator', 'is.subscriber', 'is.vip', 'is.broadcaster', 'is.bot', 'is.owner', 'method', 'subCumulativeMonths', 'tier' ] },
{ id: 'subgift', variables: [ 'username', 'is.moderator', 'is.subscriber', 'is.vip', 'is.broadcaster', 'is.bot', 'is.owner', 'recipient', 'recipientis.moderator', 'recipientis.subscriber', 'recipientis.vip', 'recipientis.broadcaster', 'recipientis.bot', 'recipientis.owner', 'tier' ] },
{ id: 'subcommunitygift', variables: [ 'username', 'count' ] },
{ id: 'subcommunitygift', variables: [ 'username', 'count', 'tier' ] },
{ id: 'resub', variables: [ 'username', 'is.moderator', 'is.subscriber', 'is.vip', 'is.broadcaster', 'is.bot', 'is.owner', 'subStreakShareEnabled', 'subStreak', 'subStreakName', 'subCumulativeMonths', 'subCumulativeMonthsName', 'tier', 'message' ] },
{ id: 'tip', variables: [ 'username', 'amount', 'currency', 'message', 'amountInBotCurrency', 'currencyInBot' ] },
{
Expand Down
9 changes: 5 additions & 4 deletions src/helpers/events/emitter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EventSubChannelGoalType } from '@twurple/eventsub-base/lib/events/common/EventSubChannelGoalType';
import { TypedEmitter } from 'tiny-typed-emitter';

import { EmitData } from '~/database/entity/overlay.js';
import { Types } from '~/plugins/ListenTo.js';

export interface Events {
Expand Down Expand Up @@ -58,23 +59,23 @@ export interface Events {
'cheer': (opts: {userName: string, userId: string, bits: number, message: string}) => void;
'user-joined-channel': (opts: {userName: string}) => void;
'user-parted-channel': (opts: {userName: string}) => void;
'subcommunitygift': (opts: {userName: string; count: number}) => void;
'subcommunitygift': (opts: {userName: string; count: number, tier: EmitData['tier']}) => void;
'reward-redeemed': (opts: {userId: string; userName: string; rewardId: string; userInput: string;}) => void;
'timeout': (opts: {userName: string; duration: number}) => void;
'ban': (opts: {userName: string; reason: string}) => void;
'raid': (opts: {userName: string, hostViewers: number, event: string, timestamp: number}) => void;
'highlight': (opts: {userId: string, message: string}) => void;
'stream-started': () => void;
'stream-stopped': () => void;
'subscription': (opts: { userName: string; method: string; subCumulativeMonths: number; tier: string}) => void;
'resub': (opts: { userName: string; subStreakShareEnabled: boolean, subStreak: number; subStreakName: string; subCumulativeMonthsName: string; message: string; subCumulativeMonths: number; tier: string}) => void;
'subscription': (opts: { userName: string; method: string; subCumulativeMonths: number; tier: EmitData['tier']}) => void;
'resub': (opts: { userName: string; subStreakShareEnabled: boolean, subStreak: number; subStreakName: string; subCumulativeMonthsName: string; message: string; subCumulativeMonths: number; tier: EmitData['tier']}) => void;
'clearchat': () => void;
'command-send-x-times': (opts: { reset: boolean } | { userName: string, message: string, source: 'discord' | 'twitch' }) => void;
'keyword-send-x-times': (opts: { reset: boolean } | { userName: string, message: string, source: 'discord' | 'twitch' }) => void;
'chatter-first-message': (opts: { userName: string, message: string, source: 'twitch' }) => void;
'every-x-minutes-of-stream': (opts: { reset: boolean }) => void;
'stream-is-running-x-minutes': (opts: { reset: boolean }) => void;
'subgift': (opts: { userName: string; recipient: string; tier: number; }) => void;
'subgift': (opts: { userName: string; recipient: string; tier: EmitData['tier']; }) => void;
'number-of-viewers-is-at-least-x': (opts: { reset: boolean }) => void;
'tip': (opts: { isAnonymous: boolean, userName: string, amount: string; currency: string; amountInBotCurrency: string; currencyInBot: string; message: string; }) => void;
// OBS Websocket integration
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/events/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const subscription = async (username: string , subInfo: ChatSubInfo, user
});
sub(`${username}#${userstate.userId}, tier: ${tier}`);
eventEmitter.emit('subscription', {
userName: username, method: subInfo.isPrime ? 'Twitch Prime' : '', subCumulativeMonths: amount, tier: String(tier),
userName: username, method: subInfo.isPrime ? 'Twitch Prime' : '', subCumulativeMonths: amount, tier,
});
alerts.trigger({
eventId: eventData?.id ?? null,
Expand Down
9 changes: 5 additions & 4 deletions src/services/twitch/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ class Chat {
resub(`${username}#${userstate.userId}, streak share: ${subStreakShareEnabled}, streak: ${subStreak}, months: ${amount}, message: ${message}, tier: ${tier}`);
eventEmitter.emit('resub', {
userName: username,
tier: String(tier),
tier,
subStreakShareEnabled,
subStreak,
subStreakName: getLocalizedName(subStreak, translate('core.months')),
Expand Down Expand Up @@ -517,6 +517,7 @@ class Chat {
try {
const userId = subInfo.gifterUserId ?? '';
const count = subInfo.count;
const tier = String(Number(subInfo.plan) / 1000) as EmitData['tier'];

changelog.increment(userId, { giftedSubscribes: Number(count) });

Expand All @@ -533,14 +534,14 @@ class Chat {
count,
timestamp: Date.now(),
});
eventEmitter.emit('subcommunitygift', { userName: username, count });
eventEmitter.emit('subcommunitygift', { userName: username, count, tier });
subcommunitygift(`${username}#${userId}, to ${count} viewers`);
alerts.trigger({
eventId: eventData?.id ?? null,
event: 'subcommunitygift',
name: username,
amount: Number(count),
tier: null,
tier,
currency: '',
monthsName: '',
message: '',
Expand All @@ -559,7 +560,7 @@ class Chat {
const userId = subInfo.gifterUserId ?? '0';
const amount = subInfo.months;
const recipientId = subInfo.userId;
const tier = (subInfo.isPrime ? 1 : (Number(subInfo.plan ?? 1000) / 1000));
const tier = String(subInfo.isPrime ? 'Prime' : (Number(subInfo.plan ?? 1000) / 1000)) as EmitData['tier'];

const ignoreGifts = (ignoreGiftsFromUser.get(userId) ?? 0);
let isGiftIgnored = false;
Expand Down

0 comments on commit a3eba63

Please sign in to comment.