From 0bb324652f8e7599eda2ada752982694baf93216 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 9 Sep 2023 12:34:53 -0500 Subject: [PATCH] refactor: say() to check chatters so its not checked manually elsewhere --- docker-compose-dev.yml | 3 -- packages/dota/src/dota/GSIHandler.ts | 48 ++++++++----------- .../events/gsi-events/event.aegis_denied.ts | 16 ++----- .../gsi-events/event.aegis_picked_up.ts | 12 ++--- .../gsi-events/event.bounty_rune_pickup.ts | 8 +--- .../events/gsi-events/event.roshan_killed.ts | 12 ++--- .../src/dota/events/gsi-events/event.tip.ts | 10 +--- .../src/dota/events/gsi-events/hero.name.ts | 3 +- .../src/dota/events/gsi-events/hero.smoked.ts | 8 +--- .../src/dota/events/gsi-events/map.paused.ts | 8 +--- .../src/dota/events/gsi-events/newdata.ts | 18 ++++--- .../dota/events/gsi-events/player.deaths.ts | 20 +++----- .../events/gsi-events/player.killstreak.ts | 9 +--- packages/dota/src/dota/lib/checkMidas.ts | 14 ++---- packages/dota/src/dota/lib/checkPassiveTp.ts | 13 ++--- packages/dota/src/dota/say.ts | 28 ++++++++++- 16 files changed, 88 insertions(+), 142 deletions(-) diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 080f6aec..20f6e4cc 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -1,18 +1,15 @@ services: twitch-chat: - platform: linux/arm64 image: "ghcr.io/dotabod/twitch-chat:v2.0" volumes: - ./packages/twitch/chat/src:/app/packages/twitch/chat/src twitch-events: - platform: linux/arm64 image: "ghcr.io/dotabod/twitch-events:v2.0" volumes: - ./packages/twitch/events/src:/app/packages/twitch/events/src dota: - platform: linux/arm64 image: "ghcr.io/dotabod/dota:v2.0" volumes: - ./packages/dota/src:/app/packages/dota/src diff --git a/packages/dota/src/dota/GSIHandler.ts b/packages/dota/src/dota/GSIHandler.ts index cf024372..85f1ddba 100644 --- a/packages/dota/src/dota/GSIHandler.ts +++ b/packages/dota/src/dota/GSIHandler.ts @@ -199,7 +199,7 @@ export class GSIHandler { .then(({ record }) => { server.io.to(this.client.token).emit('update-wl', record) }) - .catch((e) => { + .catch(() => { // Stream not live // console.error('[MMR] emitWLUpdate Error getting WL', {e: e?.message || e}) }) @@ -230,7 +230,7 @@ export class GSIHandler { }, 60 * 2000) } }) - .catch((e) => { + .catch(() => { // stream not live }) } @@ -544,14 +544,10 @@ export class GSIHandler { return } - const tellChatBets = getValueOrDefault(DBSettings.tellChatBets, client.settings) - const chattersEnabled = getValueOrDefault(DBSettings.chatter, client.settings) - - if (chattersEnabled && tellChatBets) { - say(client, t('bets.open', { emote: 'peepoGamble', lng: client.locale }), { - delay: false, - }) - } + say(client, t('bets.open', { emote: 'peepoGamble', lng: client.locale }), { + delay: false, + key: DBSettings.tellChatBets, + }) this.openingBets = false logger.info('[BETS] open bets', { event: 'open_bets', @@ -642,11 +638,15 @@ export class GSIHandler { }) if (this.client.stream_online) { - const tellChatBets = getValueOrDefault(DBSettings.tellChatBets, this.client.settings) - const chattersEnabled = getValueOrDefault(DBSettings.chatter, this.client.settings) - if (chattersEnabled && tellChatBets) { - say(this.client, t('bets.notScored', { emote: 'D:', lng: this.client.locale, matchId })) - } + say( + this.client, + t('bets.notScored', { + emote: 'D:', + lng: this.client.locale, + matchId, + key: DBSettings.tellChatBets, + }), + ) await refundTwitchBet(this.getChannelId()) } await this.resetClientState() @@ -707,10 +707,12 @@ export class GSIHandler { ? t('bets.won', { lng: this.client.locale, emote: 'Happi' }) : t('bets.lost', { lng: this.client.locale, emote: 'Happi' }) - say(this.client, message, { delay: false }) + say(this.client, message, { delay: false, chattersKey: 'matchOutcome' }) if (!betsEnabled) { - logger.info('Bets are not enabled, stopping here', { name: this.client.name }) + logger.info('Bets are not enabled, stopping here', { + name: this.client.name, + }) this.resetClientState().catch(() => { // }) @@ -739,15 +741,6 @@ export class GSIHandler { this.resetClientState().catch((e) => { logger.error('Error resetting client state', { e }) }) - - const chattersEnabled = getValueOrDefault(DBSettings.chatter, this.client.settings) - const { - matchOutcome: { enabled: chatterEnabled }, - } = getValueOrDefault(DBSettings.chatters, this.client.settings) - - if (!chattersEnabled || !chatterEnabled) { - return - } }) }, getStreamDelay(this.client.settings)) } @@ -780,8 +773,7 @@ export class GSIHandler { if (this.client.stream_online) { const tellChatBets = getValueOrDefault(DBSettings.tellChatBets, this.client.settings) - const chattersEnabled = getValueOrDefault(DBSettings.chatter, this.client.settings) - if (chattersEnabled && tellChatBets) { + if (tellChatBets) { say( this.client, t('bets.notScored', { emote: 'D:', lng: this.client.locale, matchId }), diff --git a/packages/dota/src/dota/events/gsi-events/event.aegis_denied.ts b/packages/dota/src/dota/events/gsi-events/event.aegis_denied.ts index 994c4467..2cb54bd8 100644 --- a/packages/dota/src/dota/events/gsi-events/event.aegis_denied.ts +++ b/packages/dota/src/dota/events/gsi-events/event.aegis_denied.ts @@ -1,4 +1,3 @@ -import { DBSettings, getValueOrDefault } from '@dotabod/settings' import { t } from 'i18next' import { DotaEvent, DotaEventTypes } from '../../../types.js' @@ -18,15 +17,10 @@ eventHandler.registerEvent(`event:${DotaEventTypes.AegisDenied}`, { const heroName = getHeroNameOrColor(matchPlayers[event.player_id]?.heroid ?? 0, event.player_id) - const chattersEnabled = getValueOrDefault(DBSettings.chatter, dotaClient.client.settings) - const { - roshDeny: { enabled: chatterEnabled }, - } = getValueOrDefault(DBSettings.chatters, dotaClient.client.settings) - - if (chattersEnabled && chatterEnabled) - say( - dotaClient.client, - t('aegis.denied', { lng: dotaClient.client.locale, heroName, emote: 'ICANT' }), - ) + say( + dotaClient.client, + t('aegis.denied', { lng: dotaClient.client.locale, heroName, emote: 'ICANT' }), + { chattersKey: 'roshDeny' }, + ) }, }) diff --git a/packages/dota/src/dota/events/gsi-events/event.aegis_picked_up.ts b/packages/dota/src/dota/events/gsi-events/event.aegis_picked_up.ts index 1807f865..bf412a54 100644 --- a/packages/dota/src/dota/events/gsi-events/event.aegis_picked_up.ts +++ b/packages/dota/src/dota/events/gsi-events/event.aegis_picked_up.ts @@ -1,4 +1,3 @@ -import { DBSettings, getValueOrDefault } from '@dotabod/settings' import { t } from 'i18next' import RedisClient from '../../../db/RedisClient.js' @@ -82,14 +81,9 @@ eventHandler.registerEvent(`event:${DotaEventTypes.AegisPickedUp}`, { const redisClient = RedisClient.getInstance() await redisClient.client.json.set(`${dotaClient.getToken()}:aegis`, '$', res) - const chattersEnabled = getValueOrDefault(DBSettings.chatter, dotaClient.client.settings) - const { - roshPickup: { enabled: chatterEnabled }, - } = getValueOrDefault(DBSettings.chatters, dotaClient.client.settings) - - if (chattersEnabled && chatterEnabled) { - say(dotaClient.client, generateAegisMessage(res, dotaClient.client.locale)) - } + say(dotaClient.client, generateAegisMessage(res, dotaClient.client.locale), { + chattersKey: 'roshPickup', + }) emitAegisEvent(res, dotaClient.getToken()) }, diff --git a/packages/dota/src/dota/events/gsi-events/event.bounty_rune_pickup.ts b/packages/dota/src/dota/events/gsi-events/event.bounty_rune_pickup.ts index a05efce9..a1dd7aa0 100644 --- a/packages/dota/src/dota/events/gsi-events/event.bounty_rune_pickup.ts +++ b/packages/dota/src/dota/events/gsi-events/event.bounty_rune_pickup.ts @@ -1,4 +1,3 @@ -import { DBSettings, getValueOrDefault } from '@dotabod/settings' import { t } from 'i18next' import { DotaEvent, DotaEventTypes } from '../../../types.js' @@ -15,12 +14,6 @@ eventHandler.registerEvent(`event:${DotaEventTypes.BountyPickup}`, { if (!dotaClient.client.stream_online) return if (Number(dotaClient.client.gsi?.map?.clock_time) > 120) return - const chattersEnabled = getValueOrDefault(DBSettings.chatter, dotaClient.client.settings) - const { - bounties: { enabled: chatterEnabled }, - } = getValueOrDefault(DBSettings.chatters, dotaClient.client.settings) - if (!chattersEnabled || !chatterEnabled) return - const playingTeam = (await redisClient.client.get(`${dotaClient.client.token}:playingTeam`)) ?? dotaClient.client.gsi?.player?.team_name @@ -80,6 +73,7 @@ eventHandler.registerEvent(`event:${DotaEventTypes.BountyPickup}`, { totalBounties: dotaClient.bountyHeroNames.length, heroNames: bountyHeroNamesString, }), + { chattersKey: 'bounties' }, ) dotaClient.bountyHeroNames = [] }, 15000) diff --git a/packages/dota/src/dota/events/gsi-events/event.roshan_killed.ts b/packages/dota/src/dota/events/gsi-events/event.roshan_killed.ts index f9166605..5006573d 100644 --- a/packages/dota/src/dota/events/gsi-events/event.roshan_killed.ts +++ b/packages/dota/src/dota/events/gsi-events/event.roshan_killed.ts @@ -1,4 +1,3 @@ -import { DBSettings, getValueOrDefault } from '@dotabod/settings' import { t } from 'i18next' import RedisClient from '../../../db/RedisClient.js' @@ -100,11 +99,6 @@ eventHandler.registerEvent(`event:${DotaEventTypes.RoshanKilled}`, { const minDate = dotaClient.addSecondsToNow(minS) const maxDate = dotaClient.addSecondsToNow(maxS) - const chattersEnabled = getValueOrDefault(DBSettings.chatter, dotaClient.client.settings) - const { - roshanKilled: { enabled: chatterEnabled }, - } = getValueOrDefault(DBSettings.chatters, dotaClient.client.settings) - const redisClient = RedisClient.getInstance() // TODO: move this to a redis handler const redisJson = (await redisClient.client.json.get( @@ -123,9 +117,9 @@ eventHandler.registerEvent(`event:${DotaEventTypes.RoshanKilled}`, { await redisClient.client.json.set(`${dotaClient.getToken()}:roshan`, '$', res) - if (chattersEnabled && chatterEnabled) { - say(dotaClient.client, generateRoshanMessage(res, dotaClient.client.locale)) - } + say(dotaClient.client, generateRoshanMessage(res, dotaClient.client.locale), { + chattersKey: 'roshanKilled', + }) emitRoshEvent(res, dotaClient.getToken()) }, diff --git a/packages/dota/src/dota/events/gsi-events/event.tip.ts b/packages/dota/src/dota/events/gsi-events/event.tip.ts index 9f665635..95e5d3d3 100644 --- a/packages/dota/src/dota/events/gsi-events/event.tip.ts +++ b/packages/dota/src/dota/events/gsi-events/event.tip.ts @@ -1,4 +1,3 @@ -import { DBSettings, getValueOrDefault } from '@dotabod/settings' import { t } from 'i18next' import { DotaEvent, DotaEventTypes } from '../../../types.js' @@ -14,13 +13,6 @@ eventHandler.registerEvent(`event:${DotaEventTypes.Tip}`, { if (!dotaClient.client.stream_online) return if (!isPlayingMatch(dotaClient.client.gsi)) return - const chattersEnabled = getValueOrDefault(DBSettings.chatter, dotaClient.client.settings) - const { - tip: { enabled: chatterEnabled }, - } = getValueOrDefault(DBSettings.chatters, dotaClient.client.settings) - - if (!chattersEnabled || !chatterEnabled) return - const { matchPlayers } = await getAccountsFromMatch({ gsi: dotaClient.client.gsi }) const heroName = getHeroNameOrColor( @@ -35,6 +27,7 @@ eventHandler.registerEvent(`event:${DotaEventTypes.Tip}`, { say( dotaClient.client, t('tip.from', { emote: 'ICANT', lng: dotaClient.client.locale, heroName }), + { chattersKey: 'tip' }, ) } @@ -47,6 +40,7 @@ eventHandler.registerEvent(`event:${DotaEventTypes.Tip}`, { say( dotaClient.client, t('tip.to', { emote: 'PepeLaugh', lng: dotaClient.client.locale, heroName: toHero }), + { chattersKey: 'tip' }, ) } }, diff --git a/packages/dota/src/dota/events/gsi-events/hero.name.ts b/packages/dota/src/dota/events/gsi-events/hero.name.ts index f6ce48ea..abad9dfc 100644 --- a/packages/dota/src/dota/events/gsi-events/hero.name.ts +++ b/packages/dota/src/dota/events/gsi-events/hero.name.ts @@ -32,8 +32,7 @@ eventHandler.registerEvent(`hero:name`, { } const tellChatBets = getValueOrDefault(DBSettings.tellChatBets, dotaClient.client.settings) - const chattersEnabled = getValueOrDefault(DBSettings.chatter, dotaClient.client.settings) - if (tellChatBets && chattersEnabled) + if (tellChatBets) say( dotaClient.client, t('bets.remade', { diff --git a/packages/dota/src/dota/events/gsi-events/hero.smoked.ts b/packages/dota/src/dota/events/gsi-events/hero.smoked.ts index ff726e62..db37cfb7 100644 --- a/packages/dota/src/dota/events/gsi-events/hero.smoked.ts +++ b/packages/dota/src/dota/events/gsi-events/hero.smoked.ts @@ -1,4 +1,3 @@ -import { DBSettings, getValueOrDefault } from '@dotabod/settings' import { t } from 'i18next' import { GSIHandler, redisClient } from '../../GSIHandler.js' @@ -11,12 +10,6 @@ eventHandler.registerEvent(`hero:smoked`, { handler: async (dotaClient: GSIHandler, isSmoked: boolean) => { if (!dotaClient.client.stream_online) return if (!isPlayingMatch(dotaClient.client.gsi)) return - const chatterEnabled = getValueOrDefault(DBSettings.chatter, dotaClient.client.settings) - if (!chatterEnabled) return - - const chatters = getValueOrDefault(DBSettings.chatters, dotaClient.client.settings) - - if (!chatters.smoke.enabled) return if (isSmoked) { const playingHero = (await redisClient.client.get( @@ -29,6 +22,7 @@ eventHandler.registerEvent(`hero:smoked`, { say( dotaClient.client, t('chatters.smoked', { emote: 'Shush', heroName, lng: dotaClient.client.locale }), + { chattersKey: 'smoke' }, ) } }, diff --git a/packages/dota/src/dota/events/gsi-events/map.paused.ts b/packages/dota/src/dota/events/gsi-events/map.paused.ts index d6a754c2..2e3d6507 100644 --- a/packages/dota/src/dota/events/gsi-events/map.paused.ts +++ b/packages/dota/src/dota/events/gsi-events/map.paused.ts @@ -1,4 +1,3 @@ -import { DBSettings, getValueOrDefault } from '@dotabod/settings' import { t } from 'i18next' import { GSIHandler } from '../../GSIHandler.js' @@ -12,18 +11,15 @@ eventHandler.registerEvent(`map:paused`, { if (!dotaClient.client.stream_online) return if (!isPlayingMatch(dotaClient.client.gsi)) return - const chattersEnabled = getValueOrDefault(DBSettings.chatter, dotaClient.client.settings) - const { - pause: { enabled: chatterEnabled }, - } = getValueOrDefault(DBSettings.chatters, dotaClient.client.settings) // Necessary to let the frontend know, so we can pause any rosh / aegis / etc timers server.io.to(dotaClient.getToken()).emit('paused', isPaused) - if (isPaused && chattersEnabled && chatterEnabled) { + if (isPaused) { say( dotaClient.client, t('chatters.pause', { emote: 'PauseChamp', lng: dotaClient.client.locale }), + { chattersKey: 'pause' }, ) } }, diff --git a/packages/dota/src/dota/events/gsi-events/newdata.ts b/packages/dota/src/dota/events/gsi-events/newdata.ts index bbb6907d..42853082 100644 --- a/packages/dota/src/dota/events/gsi-events/newdata.ts +++ b/packages/dota/src/dota/events/gsi-events/newdata.ts @@ -20,12 +20,7 @@ function chatterMatchFound(client: SocketClient) { const commands = DelayedCommands.filter((cmd) => getValueOrDefault(cmd.key, client.settings)) - const chattersEnabled = getValueOrDefault(DBSettings.chatter, client.settings) - const { - commandsReady: { enabled: chatterEnabled }, - } = getValueOrDefault(DBSettings.chatters, client.settings) - - if (commands.length && chattersEnabled && chatterEnabled) { + if (commands.length) { say( client, t('matchFound', { @@ -33,6 +28,7 @@ function chatterMatchFound(client: SocketClient) { lng: client.locale, }), { + chattersKey: 'commandsReady', delay: false, }, ) @@ -53,12 +49,15 @@ async function saveMatchData(client: SocketClient) { if (!client.steam32Id) return // did we already come here before? - let [steamServerId, lobbyType] = await redisClient.client + const res = await redisClient.client .multi() .get(`${matchId}:steamServerId`) .get(`${matchId}:lobbyType`) .exec() + let [steamServerId] = res + const [, lobbyType] = res + if (steamServerId && lobbyType) return if (!steamServerId && !lobbyType) { @@ -134,13 +133,12 @@ eventHandler.registerEvent(`newdata`, { return } - const chattersEnabled = getValueOrDefault(DBSettings.chatter, dotaClient.client.settings) const { powerTreads: { enabled: treadsChatterEnabled }, } = getValueOrDefault(DBSettings.chatters, dotaClient.client.settings) - if (chattersEnabled && treadsChatterEnabled) { + if (treadsChatterEnabled) { try { - void calculateManaSaved(dotaClient) + await calculateManaSaved(dotaClient) } catch (e) { logger.error('err calculateManaSaved', { e }) } diff --git a/packages/dota/src/dota/events/gsi-events/player.deaths.ts b/packages/dota/src/dota/events/gsi-events/player.deaths.ts index 5683293e..af373cdb 100644 --- a/packages/dota/src/dota/events/gsi-events/player.deaths.ts +++ b/packages/dota/src/dota/events/gsi-events/player.deaths.ts @@ -1,4 +1,3 @@ -import { DBSettings, getValueOrDefault } from '@dotabod/settings' import { t } from 'i18next' import { Item } from '../../../types.js' @@ -26,11 +25,6 @@ eventHandler.registerEvent(`player:deaths`, { if (!isPlayingMatch(dotaClient.client.gsi)) return if (!deaths) return - const chatterEnabled = getValueOrDefault(DBSettings.chatter, dotaClient.client.settings) - if (!chatterEnabled) return - - const chatters = getValueOrDefault(DBSettings.chatters, dotaClient.client.settings) - const playingHero = (await redisClient.client.get( `${dotaClient.getToken()}:playingHero`, )) as HeroNames | null @@ -38,14 +32,12 @@ eventHandler.registerEvent(`player:deaths`, { const heroName = handleGetHero(playingHero ?? dotaClient.client.gsi?.hero?.name)?.localized_name ?? '' - await firstBloodChat(chatters, dotaClient, heroName) - passiveDeathChat(chatters, dotaClient, heroName) + await firstBloodChat(dotaClient, heroName) + passiveDeathChat(dotaClient, heroName) }, }) -async function firstBloodChat(chatters: any, dotaClient: GSIHandler, heroName: string) { - if (!chatters.firstBloodDeath.enabled) return - +async function firstBloodChat(dotaClient: GSIHandler, heroName: string) { const playingTeam = (await redisClient.client.get(`${dotaClient.client.token}:playingTeam`)) ?? dotaClient.client.gsi?.player?.team_name @@ -61,6 +53,7 @@ async function firstBloodChat(chatters: any, dotaClient: GSIHandler, heroName: s say( dotaClient.client, t('chatters.firstBloodDeath', { emote: 'PepeLaugh', heroName, lng: dotaClient.client.locale }), + { chattersKey: 'firstBloodDeath' }, ) } @@ -74,9 +67,7 @@ function cantCastItem(item: Item, dotaClient: GSIHandler) { ) } -function passiveDeathChat(chatters: any, dotaClient: GSIHandler, heroName: string) { - if (!chatters.passiveDeath.enabled) return - +function passiveDeathChat(dotaClient: GSIHandler, heroName: string) { const couldHaveLivedWith = findItem({ itemName: passiveItemNames.map((i) => i.name), searchStashAlso: false, @@ -110,5 +101,6 @@ function passiveDeathChat(chatters: any, dotaClient: GSIHandler, heroName: strin say( dotaClient.client, t('chatters.died', { emote: 'ICANT', heroName, itemNames, lng: dotaClient.client.locale }), + { chattersKey: 'passiveDeath' }, ) } diff --git a/packages/dota/src/dota/events/gsi-events/player.killstreak.ts b/packages/dota/src/dota/events/gsi-events/player.killstreak.ts index 00f742d2..5744e34f 100644 --- a/packages/dota/src/dota/events/gsi-events/player.killstreak.ts +++ b/packages/dota/src/dota/events/gsi-events/player.killstreak.ts @@ -1,4 +1,3 @@ -import { DBSettings, getValueOrDefault } from '@dotabod/settings' import { t } from 'i18next' import { GSIHandler, redisClient } from '../../GSIHandler.js' @@ -12,13 +11,6 @@ eventHandler.registerEvent(`player:kill_streak`, { if (!isPlayingMatch(dotaClient.client.gsi)) return if (!dotaClient.client.stream_online) return - const chattersEnabled = getValueOrDefault(DBSettings.chatter, dotaClient.client.settings) - const { - killstreak: { enabled: chatterEnabled }, - } = getValueOrDefault(DBSettings.chatters, dotaClient.client.settings) - - if (!chattersEnabled || !chatterEnabled) return - const playingHero = (await redisClient.client.get( `${dotaClient.getToken()}:playingHero`, )) as HeroNames | null @@ -38,6 +30,7 @@ eventHandler.registerEvent(`player:kill_streak`, { heroName, lng: dotaClient.client.locale, }), + { chattersKey: 'killstreak' }, ) return } diff --git a/packages/dota/src/dota/lib/checkMidas.ts b/packages/dota/src/dota/lib/checkMidas.ts index b6019ae0..0e56845e 100644 --- a/packages/dota/src/dota/lib/checkMidas.ts +++ b/packages/dota/src/dota/lib/checkMidas.ts @@ -1,4 +1,3 @@ -import { DBSettings, getValueOrDefault } from '@dotabod/settings' import { t } from 'i18next' import { SocketClient } from '../../types.js' @@ -12,13 +11,7 @@ import { findItem } from './findItem.js' * @param token - The token used for Redis operations */ export async function checkPassiveMidas(client: SocketClient) { - const { - midas: { enabled: midasChatterEnabled }, - } = getValueOrDefault(DBSettings.chatters, client.settings) - - const chattersEnabled = getValueOrDefault(DBSettings.chatter, client.settings) - - if (chattersEnabled && midasChatterEnabled && client.stream_online) { + if (client.stream_online) { const isMidasPassive = await checkMidasIterator(client) if (typeof isMidasPassive === 'number') { say( @@ -28,9 +21,12 @@ export async function checkPassiveMidas(client: SocketClient) { lng: client.locale, seconds: isMidasPassive, }), + { chattersKey: 'midas' }, ) } else if (isMidasPassive) { - say(client, t('chatters.midas', { emote: 'massivePIDAS', lng: client.locale })) + say(client, t('chatters.midas', { emote: 'massivePIDAS', lng: client.locale }), { + chattersKey: 'midas', + }) } } } diff --git a/packages/dota/src/dota/lib/checkPassiveTp.ts b/packages/dota/src/dota/lib/checkPassiveTp.ts index c425ee9a..d7421308 100644 --- a/packages/dota/src/dota/lib/checkPassiveTp.ts +++ b/packages/dota/src/dota/lib/checkPassiveTp.ts @@ -1,4 +1,3 @@ -import { DBSettings, getValueOrDefault } from '@dotabod/settings' import { t } from 'i18next' import { SocketClient } from '../../types.js' @@ -22,15 +21,6 @@ export async function checkPassiveTp(client: SocketClient) { told: 0, } - const chattersEnabled = getValueOrDefault(DBSettings.chatter, client.settings) - const { - noTp: { enabled: chatterEnabled }, - } = getValueOrDefault(DBSettings.chatters, client.settings) - - if (!chattersEnabled || !chatterEnabled) { - return - } - const tp = client.gsi?.items?.teleport0 const hasTp = tp && tp.name !== 'empty' const deadge = client.gsi?.hero?.alive === false @@ -55,6 +45,7 @@ export async function checkPassiveTp(client: SocketClient) { channel: `@${client.name}`, lng: client.locale, }), + { chattersKey: 'noTp' }, ) return resetPassiveTime(client.token) } @@ -67,6 +58,7 @@ export async function checkPassiveTp(client: SocketClient) { channel: `@${client.name}`, lng: client.locale, }), + { chattersKey: 'noTp' }, ) return resetPassiveTime(client.token) @@ -97,6 +89,7 @@ export async function checkPassiveTp(client: SocketClient) { lng: client.locale, emote: 'HECANT', }), + { chattersKey: 'noTp' }, ) return true } diff --git a/packages/dota/src/dota/say.ts b/packages/dota/src/dota/say.ts index 2f3e4f3c..f183a6d5 100644 --- a/packages/dota/src/dota/say.ts +++ b/packages/dota/src/dota/say.ts @@ -1,3 +1,4 @@ +import { DBSettings, defaultSettings, getValueOrDefault, SettingKeys } from '@dotabod/settings' import { t } from 'i18next' import { chatClient } from '../twitch/chatClient.js' @@ -7,10 +8,35 @@ import { getStreamDelay } from './GSIHandler.js' export function say( client: SocketClient, message: string, - { delay = true, beta = false }: { delay?: boolean; beta?: boolean } = {}, + { + delay = true, + key, + chattersKey, + beta = false, + }: { + key?: SettingKeys + chattersKey?: keyof (typeof defaultSettings)['chatters'] + delay?: boolean + beta?: boolean + } = {}, ) { if (beta && !client.beta_tester) return + // global + const chattersEnabled = getValueOrDefault(DBSettings.chatter, client.settings) + if (!chattersEnabled) return + + // specific 1 + const chatter = key && getValueOrDefault(key, client.settings) + if (key && !chatter) return + + // specific 2 + const chatterSpecific = getValueOrDefault( + DBSettings.chatters, + client.settings, + ) as (typeof defaultSettings)['chatters'] + if (chattersKey && !chatterSpecific[chattersKey].enabled) return + const msg = beta ? `${message} ${t('betaFeature', { lng: client.locale })}` : message if (!delay) { chatClient.say(client.name, msg)