fix char autocomplete, /tg char active legacy code

This commit is contained in:
Nuno Duque Nunes 2026-06-20 03:28:22 +01:00
parent 9e8877483d
commit da0f90f5d7
2 changed files with 9 additions and 11 deletions

View file

@ -45,8 +45,8 @@ async function autocompleteCharNames(
.filter((c) => !nation || c.nation === nation)
.filter((c) => c.name.toLowerCase().includes(focused.toLowerCase()))
.map((c) => {
const nationEmoji = c.nation ? (NATION_UNICODE[c.nation] || c.nation) : "";
return { name: `${c.class} ${c.level} ${c.name} ${nationEmoji}`.trim(), value: c.name };
const classKey = typeof c.class === "object" ? c.class?.key : c.class;
return { name: `${classKey} ${c.level} ${c.name} [${c.nation}]`.trim(), value: c.name };
})
.slice(0, 25);
return interaction.respond(results);
@ -56,18 +56,18 @@ async function autocompleteCharNames(
// Own chars
const ownChars = getCharacters(user.userKey).map((c) => {
const nationEmoji = c.nation ? (Emoji.nation(c.nation) || c.nation) : "";
const classKey = typeof c.class === "object" ? c.class?.key : c.class;
return {
name: `${c.class} ${c.level} ${c.name} ${nationEmoji}`.trim(),
name: `${classKey} ${c.level} ${c.name} [${c.nation}]`.trim(),
value: c.name,
};
});
// Shared chars
const sharedChars = CharacterRegistry.sharedWith(user.userKey).map(({ char }) => {
const nationEmoji = char.nation ? (Emoji.nation(char.nation) || char.nation) : "";
const classKey = typeof char.class === "object" ? char.class?.key : char.class;
return {
name: `${char.class} ${char.level} ${char.name} 🔗 ${nationEmoji}`.trim(),
name: `${classKey} ${char.level} ${char.name} [${char.nation}] 🔗`.trim(),
value: char.name,
};
});

View file

@ -1,10 +1,8 @@
import { ChatInputCommandInteraction, TextChannel } from "discord.js";
import { Config } from "../../systems/config";
import { resolveUser, hasOfficerRole } from "../../systems/users";
import { getCharacterByName, getActiveCharacter } from "../../systems/characters";
import { addPendingRequest, setSessionBorrow, sendBorrowRequestDM, canUseCharacter } from "../../systems/borrow";
import { polls, updatePollMessage } from "../../systems/poll";
import { replyAndDelete } from "../../utils";
import { Emoji } from "@systems/emojis";
export async function handleCharActive(interaction: ChatInputCommandInteraction): Promise<void> {
const nameArg = interaction.options.getString("name");
@ -22,8 +20,8 @@ export async function handleCharActive(interaction: ChatInputCommandInteraction)
const { char, borrowedFrom } = getEffectiveCharacter(targetKey);
if (!char) return void replyAndDelete(interaction, `❌ No active character found for **${targetKey}**.`);
const { getClassEmoji } = require("../../systems/emojis");
const classEmoji = getClassEmoji(char.class) || char.class;
const classKey = typeof char.class === "object" ? char.class?.key : char.class;
const classEmoji = Emoji.class(classKey) || classKey;
const borrowed = borrowedFrom ? ` *(shared by ${borrowedFrom})*` : "";
return void replyAndDelete(interaction, `${classEmoji} ${char.level} ${char.name}${borrowed}`);
}