Skip to content

Commit

Permalink
new: !facet command
Browse files Browse the repository at this point in the history
  • Loading branch information
Geczy committed Jun 4, 2024
1 parent 79a14d2 commit 72c2c9a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/dota/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}}",
Expand Down Expand Up @@ -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}}"
Expand Down
1 change: 1 addition & 0 deletions packages/dota/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const defaultSettings = {
commandSteam: true,
commandXPM: true,
commandWinProbability: true,
commandFacet: true,
'minimap-blocker': true,
minimapRight: false,
mmr: null,
Expand Down
1 change: 1 addition & 0 deletions packages/dota/src/twitch/commandLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
54 changes: 54 additions & 0 deletions packages/dota/src/twitch/commands/facet.ts
Original file line number Diff line number Diff line change
@@ -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 }),
)
}
},
})
1 change: 1 addition & 0 deletions packages/dota/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 72c2c9a

Please sign in to comment.