diff options
| author | Fuwn <[email protected]> | 2025-10-11 11:30:23 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-10-11 11:30:23 -0700 |
| commit | 65907e89b1362dcfe7d3ce96200b2e14f63477e4 (patch) | |
| tree | f8bc04d755a81aa654701553c9e94916fa766193 | |
| parent | feat(gateway:prm): Increase message threshold (diff) | |
| download | umabotdiscord-65907e89b1362dcfe7d3ce96200b2e14f63477e4.tar.xz umabotdiscord-65907e89b1362dcfe7d3ce96200b2e14f63477e4.zip | |
feat(gateway:prm): Add reply handling
3 files changed, 111 insertions, 8 deletions
diff --git a/packages/gateway/src/commands/utilities.ts b/packages/gateway/src/commands/utilities.ts index d6ec548..7ed18b4 100644 --- a/packages/gateway/src/commands/utilities.ts +++ b/packages/gateway/src/commands/utilities.ts @@ -477,7 +477,7 @@ export const getAllChannelsInCategory = async ( export const sendPersonaLog = async ( client: Client, - type: "persona" | "conversation" | "reaction", + type: "persona" | "persona-reply" | "conversation" | "reaction", personaName: string, messageLink?: string, isPrimer: boolean = false, @@ -495,16 +495,20 @@ export const sendPersonaLog = async ( .setTitle( type === "persona" ? "🎠Persona Message" - : type === "conversation" - ? "💬 Conversation Starter" - : "👀 Random Reaction", + : type === "persona-reply" + ? "💠Persona Reply" + : type === "conversation" + ? "💬 Conversation Starter" + : "👀 Random Reaction", ) .setColor( type === "persona" ? "#ff6b6b" - : type === "conversation" - ? "#4ecdc4" - : "#ffd93d", + : type === "persona-reply" + ? "#9b59b6" + : type === "conversation" + ? "#4ecdc4" + : "#ffd93d", ) .addFields( { diff --git a/packages/gateway/src/listeners/messageCreate/constants.ts b/packages/gateway/src/listeners/messageCreate/constants.ts index a39e218..b8174c9 100644 --- a/packages/gateway/src/listeners/messageCreate/constants.ts +++ b/packages/gateway/src/listeners/messageCreate/constants.ts @@ -73,3 +73,29 @@ export const PERSONA_ENDINGS = [ "You're all stars! 🌠", "Keep being fantastic! 🎉", ]; + +export const PERSONA_REPLY_FIRST_PARTS = [ + "Oh my", + "Well well", + "Hmm", + "Oh dear", + "My my", + "Oh wow", + "Well then", + "Oh boy", + "Hmm interesting", + "Oh really", +]; + +export const PERSONA_REPLY_SECOND_PARTS = [ + "I'll remember this the next time I'm thinking of what to do with this channel", + "I'll keep this in mind when deciding the future of this channel", + "This will influence my decisions about this channel going forward", + "I'll consider this when making choices about this channel", + "This will be remembered when I think about this channel's direction", + "I'll take this into account for future channel decisions", + "This will be factored into my plans for this channel", + "I'll remember this when contemplating this channel's purpose", + "This will guide my thoughts about this channel's future", + "I'll keep this in consideration for this channel's development", +]; diff --git a/packages/gateway/src/listeners/messageCreate/personaRandomMessage.ts b/packages/gateway/src/listeners/messageCreate/personaRandomMessage.ts index 737891f..a9211ef 100644 --- a/packages/gateway/src/listeners/messageCreate/personaRandomMessage.ts +++ b/packages/gateway/src/listeners/messageCreate/personaRandomMessage.ts @@ -1,7 +1,11 @@ import { Message, WebhookClient, Client } from "discord.js"; import { UMA_PERSONAS } from "../../constants"; import { sendPersonaLog } from "../../commands/utilities"; -import { PERSONA_MIDDLES } from "./constants"; +import { + PERSONA_MIDDLES, + PERSONA_REPLY_FIRST_PARTS, + PERSONA_REPLY_SECOND_PARTS, +} from "./constants"; import { generatePersonaMessage } from "./utilities"; const ENABLED_PRIMER_MESSAGE = false; @@ -13,6 +17,10 @@ interface PersonaMessageTracker { lastRandomMessageTime: number; lastUserMessageTime: number; isActive: boolean; + lastPersonaMessageId: string | null; + lastPersonaName: string | null; + lastPersonaAvatar: string | null; + hasReplied: boolean; } class PersonaRandomMessageSystem { @@ -21,6 +29,10 @@ class PersonaRandomMessageSystem { lastRandomMessageTime: 0, lastUserMessageTime: 0, isActive: false, + lastPersonaMessageId: null, + lastPersonaName: null, + lastPersonaAvatar: null, + hasReplied: false, }; private webhookClient: WebhookClient | null = null; private client: Client | null = null; @@ -98,6 +110,11 @@ class PersonaRandomMessageSystem { true, sentMessageLink, ); + + this.tracker.lastPersonaMessageId = sentMessage.id; + this.tracker.lastPersonaName = randomPersona.name; + this.tracker.lastPersonaAvatar = randomPersona.avatar; + this.tracker.hasReplied = false; } catch (error) { console.error("Failed to send primer persona message:", error); } @@ -110,6 +127,17 @@ class PersonaRandomMessageSystem { if (message.author.bot) return; + if ( + this.tracker.lastPersonaMessageId && + message.reference?.messageId === this.tracker.lastPersonaMessageId && + !this.tracker.hasReplied && + message.content.length >= 10 + ) { + await this.handleReplyToPersona(); + + return; + } + const now = Date.now(); const timeSinceLastUserMessage = now - this.tracker.lastUserMessageTime; const fiveMinutes = 5 * 60 * 1000; @@ -158,11 +186,56 @@ class PersonaRandomMessageSystem { this.tracker.messageCount = 0; this.tracker.lastRandomMessageTime = Date.now(); + this.tracker.lastPersonaMessageId = sentMessage.id; + this.tracker.lastPersonaName = randomPersona.name; + this.tracker.lastPersonaAvatar = randomPersona.avatar; + this.tracker.hasReplied = false; } catch (error) { console.error("Failed to send persona message:", error); } } + private async handleReplyToPersona(): Promise<void> { + try { + if (!this.webhookClient) { + console.error("Failed to reply to persona - webhook not initialized"); + + return; + } + + const firstPart = + PERSONA_REPLY_FIRST_PARTS[ + Math.floor(Math.random() * PERSONA_REPLY_FIRST_PARTS.length) + ]; + const secondPart = + PERSONA_REPLY_SECOND_PARTS[ + Math.floor(Math.random() * PERSONA_REPLY_SECOND_PARTS.length) + ]; + const replyMessage = `${firstPart} .... ${secondPart} ....`; + const sentMessage = await this.webhookClient.send({ + content: replyMessage, + username: this.tracker.lastPersonaName || "UmaBot Persona", + avatarURL: + this.tracker.lastPersonaAvatar || + "https://cdn.discordapp.com/embed/avatars/0.png", + }); + const sentMessageLink = `https://discord.com/channels/${this.client!.guilds.cache.first()?.id}/${TARGET_CHANNEL_ID}/${sentMessage.id}`; + + await sendPersonaLog( + this.client!, + "persona-reply", + this.tracker.lastPersonaName || "UmaBot Persona", + undefined, + false, + sentMessageLink, + ); + + this.tracker.hasReplied = true; + } catch (error) { + console.error("Failed to send persona reply:", error); + } + } + public destroy(): void { this.webhookClient?.destroy(); } |