Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Nov 8, 2021
1 parent 591dd16 commit 0d7dfae
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
13 changes: 13 additions & 0 deletions src/services/twitch/api/client.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import { ApiClient } from '@twurple/api';
import { StaticAuthProvider } from '@twurple/auth';

import { warning } from '../../../helpers/log.js';

import { variables } from '~/watchers';

const client = async (account: 'broadcaster' | 'bot') => {
const clientId = variables.get(`services.twitch.${account}ClientId`) as string;
const accessToken = variables.get(`services.twitch.${account}AccessToken`) as string;
const isValidToken = variables.get(`services.twitch.${account}TokenValid`) as string;

if ((global as any).mocha) {
warning('Mocking client for ' + account);
return {
clips: {
getClipById: () => {
warning('Mocking call clips.getClipById for ' + account);
},
},
} as unknown as ApiClient;
}

if (!isValidToken) {
throw new Error(`Cannot initialize Twitch API, ${account} token invalid.`);
}
Expand Down
11 changes: 5 additions & 6 deletions src/services/twitch/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import users from '~/users';
import { variables } from '~/watchers';
import joinpart from '~/widgets/joinpart';

const ignoreGiftsFromUser = new Map<string, number>();
const commandRegexp = new RegExp(/^!\w+$/);
class Chat {
shouldConnect = false;
Expand All @@ -68,8 +69,6 @@ class Chat {
broadcasterWarning = false;
botWarning = false;

ignoreGiftsFromUser = new Map<string, number>();

constructor() {
this.emitter();
}
Expand Down Expand Up @@ -624,8 +623,8 @@ class Chat {

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

const ignoreGifts = this.ignoreGiftsFromUser.get(username) ?? 0;
this.ignoreGiftsFromUser.set(username, ignoreGifts + count);
const ignoreGifts = ignoreGiftsFromUser.get(userId) ?? 0;
ignoreGiftsFromUser.set(userId, ignoreGifts + count);

if (isIgnored({ userName: username, userId })) {
return;
Expand Down Expand Up @@ -664,7 +663,7 @@ class Chat {
const recipientId = subInfo.userId;
const tier = (subInfo.isPrime ? 1 : (Number(subInfo.plan ?? 1000) / 1000));

const ignoreGifts = (this.ignoreGiftsFromUser.get(username) ?? 0);
const ignoreGifts = (ignoreGiftsFromUser.get(userId) ?? 0);
let isGiftIgnored = false;

const user = await changelog.get(recipientId);
Expand All @@ -676,7 +675,7 @@ class Chat {

if (ignoreGifts > 0) {
isGiftIgnored = true;
this.ignoreGiftsFromUser.set(username, ignoreGifts - 1);
ignoreGiftsFromUser.set(userId, ignoreGifts - 1);
}

if (!isGiftIgnored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Message - https://discordapp.com/channels/317348946144002050/619437014
});

it('call !media directly with regular viewer should send permission error', async () => {
const parse = new Parser({ sender: user.owner, message: '!media type=video', skip: false, quiet: false });
const parse = new Parser({ sender: user.viewer, message: '!media type=video', skip: false, quiet: false });
const r = await parse.process();
assert.strictEqual(r[0].response, 'You don\'t have enough permissions for \'!media type=video\'');
});
Expand All @@ -37,7 +37,7 @@ describe('Message - https://discordapp.com/channels/317348946144002050/619437014
});

it('call !media directly with regular viewer should send permission error', async () => {
const parse = new Parser({ sender: user.owner, message: '!media type=video2', skip: false, quiet: false });
const parse = new Parser({ sender: user.viewer, message: '!media type=video2', skip: false, quiet: false });
const r = await parse.process();
assert.strictEqual(r[0].response, 'You don\'t have enough permissions for \'!media type=video2\'');
});
Expand Down
6 changes: 3 additions & 3 deletions test/tests/message/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ describe('Message - list filter - @func3', () => {
describe('(list.core.<permissionName>) should return proper message', () => {
it('(list.core.CASTERS) should return core commands', async () => {
const r = await new Message('(list.core.CASTERS)').parse({});
assert.strictEqual(r, '_debug, alias, alias add, alias edit, alias group, alias list, alias remove, alias toggle, alias toggle-visibility, bansong, command, command add, command edit, command list, command remove, command toggle, command toggle-visibility, commercial, cooldown set, cooldown toggle enabled, cooldown toggle followers, cooldown toggle moderators, cooldown toggle owners, cooldown toggle subscribers, cooldown unset, disable, enable, game set, highlight, highlight list, hltb, ignore add, ignore check, ignore remove, immune, keyword, keyword add, keyword edit, keyword list, keyword remove, keyword toggle, level change, makeitrain, media, permission exclude-add, permission exclude-rm, permission list, permit, playlist, playlist add, playlist import, playlist list, playlist remove, playlist set, playlist steal, points add, points all, points get, points online, points remove, points set, points undo, price, price list, price set, price toggle, price unset, queue clear, queue close, queue list, queue open, queue pick, queue random, quote add, quote remove, quote set, raffle open, raffle pick, raffle remove, rank add, rank add-flw, rank add-sub, rank edit, rank edit-flw, rank edit-sub, rank help, rank list, rank list-flw, rank list-sub, rank rm, rank rm-flw, rank rm-sub, rank set, rank unset, scrim stop, set, skipsong, snipe, timers, timers add, timers list, timers rm, timers set, timers toggle, timers unset, title set, top bits, top followage, top gifts, top level, top messages, top points, top subage, top submonths, top time, top tips, tts, unbansong');
assert.strictEqual(r, '_debug, alias, alias add, alias edit, alias group, alias list, alias remove, alias toggle, alias toggle-visibility, bansong, command, command add, command edit, command list, command remove, command toggle, command toggle-visibility, commercial, cooldown set, cooldown toggle enabled, cooldown toggle followers, cooldown toggle moderators, cooldown toggle owners, cooldown toggle subscribers, cooldown unset, disable, enable, highlight, highlight list, hltb, immune, keyword, keyword add, keyword edit, keyword list, keyword remove, keyword toggle, level change, makeitrain, media, permission exclude-add, permission exclude-rm, permission list, permit, playlist, playlist add, playlist import, playlist list, playlist remove, playlist set, playlist steal, points add, points all, points get, points online, points remove, points set, points undo, price, price list, price set, price toggle, price unset, queue clear, queue close, queue list, queue open, queue pick, queue random, quote add, quote remove, quote set, raffle open, raffle pick, raffle remove, rank add, rank add-flw, rank add-sub, rank edit, rank edit-flw, rank edit-sub, rank help, rank list, rank list-flw, rank list-sub, rank rm, rank rm-flw, rank rm-sub, rank set, rank unset, scrim stop, set, skipsong, snipe, timers, timers add, timers list, timers rm, timers set, timers toggle, timers unset, top bits, top followage, top gifts, top level, top messages, top points, top subage, top submonths, top time, top tips, tts, unbansong');
});

it('(list.core.VIEWERS) should return core commands', async () => {
const r = await new Message('(list.core.VIEWERS)').parse({});
assert.strictEqual(r, 'age, bet, currentsong, followage, followers, game, lastseen, level, level buy, me, ping, points, points give, queue, queue join, quote, quote list, raffle, rank, snipe match, songrequest, subage, subs, time, title, uptime, vote, watched, wrongsong');
assert.strictEqual(r, 'age, bet, currentsong, followage, lastseen, level, level buy, me, ping, points, points give, queue, queue join, quote, quote list, raffle, rank, snipe match, songrequest, subage, vote, watched, wrongsong');
});

it('(list.!core.VIEWERS) should return core commands', async () => {
const r = await new Message('(list.!core.VIEWERS)').parse({});
assert.strictEqual(r, '!age, !bet, !currentsong, !followage, !followers, !game, !lastseen, !level, !level buy, !me, !ping, !points, !points give, !queue, !queue join, !quote, !quote list, !raffle, !rank, !snipe match, !songrequest, !subage, !subs, !time, !title, !uptime, !vote, !watched, !wrongsong');
assert.strictEqual(r, '!age, !bet, !currentsong, !followage, !lastseen, !level, !level buy, !me, !ping, !points, !points give, !queue, !queue join, !quote, !quote list, !raffle, !rank, !snipe match, !songrequest, !subage, !vote, !watched, !wrongsong');
});
});
});
6 changes: 3 additions & 3 deletions test/tests/tmi/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('TMI - ignore - @func3', () => {

const item = await getRepository(Settings).findOne({
where: {
namespace: '/core/tmi',
namespace: '/services/twitch',
name: 'ignorelist',
},
});
Expand All @@ -89,7 +89,7 @@ describe('TMI - ignore - @func3', () => {
const r = await twitch.ignoreCheck({ sender: owner, parameters: '@testuser2' });
const item = await getRepository(Settings).findOne({
where: {
namespace: '/core/tmi',
namespace: '/services/twitch',
name: 'ignorelist',
},
});
Expand All @@ -104,7 +104,7 @@ describe('TMI - ignore - @func3', () => {
const r = await twitch.ignoreCheck({ sender: owner, parameters: 'testuser3' });
const item = await getRepository(Settings).findOne({
where: {
namespace: '/core/tmi',
namespace: '/services/twitch',
name: 'ignorelist',
},
});
Expand Down

0 comments on commit 0d7dfae

Please sign in to comment.