Add sassy AI personality with mention detection
Deploy to NAS / deploy (push) Successful in 1m55s

- Add utils/ai.js with NanoGPT integration for GLM-4.5-Air model
- Sassy system prompt: lowercase, slang, no emoji, opinionated gamer
- Conversation history per channel for context
- Update bot.js with messageCreate event for @mention responses
- Add NANO_MODEL env var for model selection
This commit is contained in:
2026-03-09 12:37:45 -04:00
parent ab91c98360
commit a7a6c1e321
2 changed files with 160 additions and 0 deletions
+52
View File
@@ -14,6 +14,7 @@ import path from 'node:path';
import { Client, Collection, Events, GatewayIntentBits } from 'discord.js';
import Logger from './logger.js';
import { loadCommands } from './utils/commandLoader.js';
import { getAIResponse, isAIEnabled, clearHistory } from './utils/ai.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
@@ -40,6 +41,57 @@ client.once(Events.ClientReady, () => {
logger.log(`Ready! Logged in as ${client.user.tag}`);
});
// Handle messages where the bot is mentioned
client.on(Events.MessageCreate, async message => {
// Ignore bot messages
if (message.author.bot) return;
// Check if bot is mentioned
const botId = client.user.id;
const mentioned = message.mentions.has(botId);
if (!mentioned) return;
// Don't respond to commands (they start with /)
if (message.content.trim().startsWith('/')) return;
if (!isAIEnabled()) {
logger.warn('AI response requested but NANOGPT_API_KEY not set');
return;
}
try {
// Get the clean prompt (remove the bot mention)
const cleanPrompt = message.content
.replace(new RegExp(`<@!?${botId}>`, 'g'), '')
.trim();
if (!cleanPrompt) return;
// Get username of who mentioned us
const mentionedUsername = message.author.username;
logger.log(`Mentioned by ${mentionedUsername} in #${message.channel.name}: ${cleanPrompt.substring(0, 50)}...`);
// Typing indicator
await message.channel.sendTyping();
const response = await getAIResponse(cleanPrompt, message.channel.id, mentionedUsername);
// Send response (avoiding mention loop)
await message.reply({
content: response,
allowedMentions: { users: [] }, // Prevent mentioning the user back
});
} catch (error) {
logger.error('AI response failed:', error.message);
await message.reply({
content: 'lol damn, something broke. try again in a sec',
allowedMentions: { users: [] },
});
}
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;