Skip to content

Commit

Permalink
Somnia Bot: add talent scalings to archive char command (#2775)
Browse files Browse the repository at this point in the history
* add debug command

* Update apps/somnia/src/commands/debug.ts

Co-authored-by: Van Nguyen <[email protected]>

* add links to github

* fix hyperlink

* Update debug.ts

Co-authored-by: Van Nguyen <[email protected]>

* Update debug.ts

Co-authored-by: Van Nguyen <[email protected]>

* user installed archive command

* Update events.ts

* fix asset url

* fix formatting

* add talent scalings

* fix command name

* mini ci

* cleanup

* update gen

* Update archive.ts

* Update char.ts

---------

Co-authored-by: Van Nguyen <[email protected]>
  • Loading branch information
Godlander and nguyentvan7 authored Mar 9, 2025
1 parent 8d2daaf commit 44a8f1d
Show file tree
Hide file tree
Showing 24 changed files with 335 additions and 116 deletions.
44 changes: 26 additions & 18 deletions apps/somnia/src/commands/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import { error } from '../lib/message'

import {
allArtifactSetKeys,
allCharacterKeys,
allCharacterSheetKeys,
allWeaponKeys,
type ArtifactSetKey,
type CharacterKey,
type CharacterSheetKey,
type WeaponKey,
} from '@genshin-optimizer/gi/consts'
import { i18nInstance } from '@genshin-optimizer/gi/i18n-node'
Expand Down Expand Up @@ -106,19 +106,21 @@ export const slashcommand = new SlashCommandBuilder()

type ArchiveSubcommand = 'char' | 'weapon' | 'artifact'
const archive = {
char: allCharacterKeys,
char: allCharacterSheetKeys,
weapon: allWeaponKeys,
artifact: allArtifactSetKeys,
}
function translate(
namespace: string,
key: string,
lang = 'en',
object = false
object = false,
options?: { [key: string]: any }
): any {
return i18nInstance.t(`${namespace}:${key}`, {
returnObjects: object,
lng: lang,
...options,
})
}
export { translate }
Expand All @@ -135,15 +137,20 @@ export const talentlist = {
//clean tags from input
//discord has no colored text, so just bold everything instead
export function clean(s: string) {
//keep italic tags
s = s.replaceAll(/(<i>)+/g, '-# *')
//trim whitespace
s = s.trim()
//italics become small
s = s.replace(/(<i>[\s\S]*)\n([\s\S]*<\/i>)/g, (m) =>
m.replace(/\n/g, '\n-# ')
)
s = s.replaceAll(/(<i>)+/g, '*-# ')
s = s.replaceAll(/(<\/i>)+/g, '*')
//turn rest into bold
s = s.replaceAll(/(<\/?\w+>)+/g, '**')
//ignore <br/> tags
s = s.replaceAll(/<\w+\/>/g, '')
//remove extra whitespace
return s.trim()
return s
}

export async function autocomplete(interaction: AutocompleteInteraction) {
Expand Down Expand Up @@ -187,25 +194,25 @@ export async function autocomplete(interaction: AutocompleteInteraction) {
async function archiveMessage(
subcommand: ArchiveSubcommand,
id: string,
lang: string,
arg: string
arg: string,
lang: string
) {
//character archive
if (subcommand === 'char') {
if (!archive[subcommand].includes(id as CharacterKey))
throw 'invalid character name'
return await charArchive(id as CharacterKey, lang, arg)
if (!archive[subcommand].includes(id as CharacterSheetKey))
throw 'Invalid character name'
return await charArchive(id as CharacterSheetKey, arg, lang)
}
//weapons archive
else if (subcommand === 'weapon') {
if (!archive[subcommand].includes(id as WeaponKey))
throw 'invalid weapon name'
return await weaponArchive(id as WeaponKey, lang, arg)
throw 'Invalid weapon name'
return await weaponArchive(id as WeaponKey, arg, lang)
}
//artifacts archive
else if (subcommand === 'artifact') {
if (!archive[subcommand].includes(id as ArtifactSetKey))
throw 'invalid artifact name'
throw 'Invalid artifact name'
return await artifactArchive(id as ArtifactSetKey, lang)
} else throw 'Invalid selection'
}
Expand All @@ -222,7 +229,7 @@ export async function run(interaction: ChatInputCommandInteraction) {
arg = interaction.options.getString('refine', false) ?? ''

try {
interaction.reply(await archiveMessage(subcommand, id, lang, arg))
interaction.reply(await archiveMessage(subcommand, id, arg, lang))
} catch (e) {
error(interaction, e)
}
Expand All @@ -234,11 +241,12 @@ export async function selectmenu(
) {
const subcommand = args[1] as ArchiveSubcommand
const id = args[2]
const lang = args[3]
//const oldarg = args[3]
const lang = args[4]
const arg = interaction.values[0]

try {
interaction.update(await archiveMessage(subcommand, id, lang, arg))
interaction.update(await archiveMessage(subcommand, id, arg, lang))
} catch (e) {
error(interaction, e)
}
Expand Down
Loading

0 comments on commit 44a8f1d

Please sign in to comment.