diff --git a/packages/bot/src/bot/commands/moderation/pronouns.ts b/packages/bot/src/bot/commands/moderation/pronouns.ts index 840afb3..2a0a197 100644 --- a/packages/bot/src/bot/commands/moderation/pronouns.ts +++ b/packages/bot/src/bot/commands/moderation/pronouns.ts @@ -40,7 +40,7 @@ export default { let target; try { - target = await server.fetchMember(targetUser); + target = await server.fetchMemberFresh(targetUser.id); } catch (e) { return message.reply("The target is not part of this server."); } diff --git a/packages/bot/src/bot/modules/event_handler.ts b/packages/bot/src/bot/modules/event_handler.ts index 2c003d6..09a715e 100644 --- a/packages/bot/src/bot/modules/event_handler.ts +++ b/packages/bot/src/bot/modules/event_handler.ts @@ -6,7 +6,7 @@ import InfractionType from "automod-lib/dist/types/antispam/InfractionType"; import { getOwnMemberInServer, storeInfraction } from "../util"; import { fetchUsername } from "./mod_logs"; import { DEFAULT_PREFIX } from "./command_handler"; -import { setServerPrefixPronouns } from "./prefix_pronouns"; +import { setServerPrefixPronouns, clearServerPrefixPronouns } from "./prefix_pronouns"; import { UserSystemMessage } from "../../stoat/index.js"; const DM_SESSION_LIFETIME = 1000 * 60 * 5; @@ -91,7 +91,12 @@ client.on("serverCreate", async (server) => { return undefined; }); - setServerPrefixPronouns(server, DEFAULT_PREFIX).catch((e) => console.warn("Failed to update prefix pronouns in server:", server.id, e)); + const prefixConfig = await dbs.SERVERS.findOne({ id: server.id }).catch(() => null); + if (prefixConfig?.prefix) { + setServerPrefixPronouns(server, prefixConfig.prefix).catch((e) => console.warn("Failed to update prefix pronouns in server:", server.id, e)); + } else { + clearServerPrefixPronouns(server).catch((e) => console.warn("Failed to clear prefix pronouns in server:", server.id, e)); + } const channels = server.channels.filter((c) => c && c.type == "TextChannel"); diff --git a/packages/bot/src/bot/modules/prefix_pronouns.ts b/packages/bot/src/bot/modules/prefix_pronouns.ts index e0f05aa..c957a24 100644 --- a/packages/bot/src/bot/modules/prefix_pronouns.ts +++ b/packages/bot/src/bot/modules/prefix_pronouns.ts @@ -8,8 +8,10 @@ const PRONOUNS_MAX_LENGTH = 24; function prefixPronounText(prefix: string): string { const sanitised = prefix.replace(/\s+/g, " ").trim(); if (!sanitised) return ""; + const text = `Prefix: ${sanitised}`; - return text.length > PRONOUNS_MAX_LENGTH ? sanitised.slice(0, PRONOUNS_MAX_LENGTH) : text; + if (text.length <= PRONOUNS_MAX_LENGTH) return text; + return [...sanitised].slice(0, PRONOUNS_MAX_LENGTH).join(""); } async function setServerPrefixPronouns(server: Server, prefix: string): Promise {