diff --git a/packages/dota/locales/en/translation.json b/packages/dota/locales/en/translation.json index 77db8430..79e9a3f8 100644 --- a/packages/dota/locales/en/translation.json +++ b/packages/dota/locales/en/translation.json @@ -108,6 +108,7 @@ "unranked": "Not ranked", "won": "Won last game" }, + "facet": "{{- heroName}} facet: {{- facetTitle}} · {{- facetDescription}}", "lifetime": "Lifetime games", "matchFound": "Match data found {{commandList}} commands activated.", "matchId": "Match ID: {{matchId}}", @@ -207,7 +208,7 @@ "unknown": "Couldn't find the last git commit, here's the repo {{- url}}" }, "winprobability": { - "winProbability": "{{winRate}}% win probability {{emote}} at {{gameTime}}:00 ⏲ · Next update in {{remainingCooldown}}s", + "winProbability": "{{winRate}}% win probability at {{gameTime}}:00 · Next update in {{remainingCooldown}}s", "winProbabilityDataNotAvailable": "Win probability is not available yet · Try again in {{remainingCooldown}}s" }, "xpm": "Live XPM for {{- heroName}}: {{num}}" diff --git a/packages/dota/src/settings.ts b/packages/dota/src/settings.ts index 7a7f638e..edab89b3 100644 --- a/packages/dota/src/settings.ts +++ b/packages/dota/src/settings.ts @@ -78,6 +78,7 @@ export const defaultSettings = { commandSteam: true, commandXPM: true, commandWinProbability: true, + commandFacet: true, 'minimap-blocker': true, minimapRight: false, mmr: null, diff --git a/packages/dota/src/twitch/commandLoader.ts b/packages/dota/src/twitch/commandLoader.ts index b9f30ff6..b1cf039b 100644 --- a/packages/dota/src/twitch/commandLoader.ts +++ b/packages/dota/src/twitch/commandLoader.ts @@ -7,6 +7,7 @@ import './commands/d2pt.js' import './commands/delay.js' import './commands/dotabod.js' import './commands/dotabuff.js' +import './commands/facet.js' import './commands/fixdbl.js' import './commands/fixparty.js' import './commands/friends.js' diff --git a/packages/dota/src/twitch/commands/facet.ts b/packages/dota/src/twitch/commands/facet.ts new file mode 100644 index 00000000..38bdb992 --- /dev/null +++ b/packages/dota/src/twitch/commands/facet.ts @@ -0,0 +1,54 @@ +import DOTA_HERO_ABILITIES from 'dotaconstants/build/hero_abilities.json' assert { type: 'json' } +import { t } from 'i18next' +import { gsiHandlers } from '../../dota/lib/consts.js' +import { getHeroNameOrColor } from '../../dota/lib/heroes.js' +import { DBSettings } from '../../settings.js' +import { chatClient } from '../chatClient.js' +import commandHandler from '../lib/CommandHandler.js' +import { findAccountFromCmd } from '../lib/findGSIByAccountId.js' + +commandHandler.registerCommand('facet', { + dbkey: DBSettings.commandFacet, + handler: async (message, args, command) => { + const { + channel: { name: channel, client }, + } = message + + const gsi = gsiHandlers.get(client.token) + + if (!gsi || !client.gsi?.map?.matchid) { + chatClient.say( + message.channel.name, + t('notPlaying', { emote: 'PauseChamp', lng: message.channel.client.locale }), + ) + return + } + + try { + const { hero, playerIdx } = await findAccountFromCmd(client.gsi, args, client.locale, command) + if (typeof hero?.id !== 'number') { + chatClient.say(channel, t('gameNotFound', { lng: message.channel.client.locale })) + return + } + + const facet = + DOTA_HERO_ABILITIES?.[hero.name as keyof typeof DOTA_HERO_ABILITIES]?.facets[hero.facet - 1] + + chatClient.say( + channel, + t('facet', { + lng: message.channel.client.locale, + heroName: getHeroNameOrColor(hero?.id ?? 0, playerIdx), + facetTitle: facet.title, + facetDescription: facet.description, + }), + ) + return + } catch (e: any) { + chatClient.say( + message.channel.name, + e?.message ?? t('gameNotFound', { lng: message.channel.client.locale }), + ) + } + }, +}) diff --git a/packages/dota/src/types.ts b/packages/dota/src/types.ts index 9ec640ad..f95f01ae 100644 --- a/packages/dota/src/types.ts +++ b/packages/dota/src/types.ts @@ -173,6 +173,7 @@ export interface Hero { team2?: { player0: Hero; player1: Hero; player2: Hero; player3: Hero; player4: Hero } team3?: { player5: Hero; player6: Hero; player7: Hero; player8: Hero; player9: Hero } id: number // -1 if hero not yet set + facet?: number // 1 | 2, name?: HeroNames // e.g. 'npc_dota_hero_antimage' once set xpos?: number // -5422, ypos?: number // -4771,