Test coverage reports; voicemsg command; debug command; refactoring
This commit is contained in:
193
discord/commands/debug/debug.ts
Normal file
193
discord/commands/debug/debug.ts
Normal file
@@ -0,0 +1,193 @@
|
||||
import { ChatInputCommandInteraction, SlashCommandBuilder, MessageType } from 'discord.js';
|
||||
import { logInfo, logWarn, logError } from '../../../logging';
|
||||
import {
|
||||
fetchMotd,
|
||||
dateToSnowflake,
|
||||
sendBiggestLoserAnnouncement,
|
||||
triggerThrowback,
|
||||
} from '../helpers';
|
||||
|
||||
/**
|
||||
* debug.ts
|
||||
* Debug commands for ADMIN to force-trigger scheduled events
|
||||
*/
|
||||
|
||||
async function debugCommand(interaction: ChatInputCommandInteraction) {
|
||||
// Only ADMIN can use debug commands
|
||||
if (interaction.user.id !== process.env.ADMIN) {
|
||||
await interaction.reply({
|
||||
content: '❌ You are not authorized to use debug commands.',
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const subcommand = interaction.options.getString('action');
|
||||
|
||||
if (!subcommand) {
|
||||
await interaction.reply({
|
||||
content: '❌ No action specified.',
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
|
||||
try {
|
||||
switch (subcommand) {
|
||||
case 'motd': {
|
||||
logInfo('[debug] ADMIN triggered MOTD');
|
||||
const randomMessage = await fetchMotd();
|
||||
if (randomMessage) {
|
||||
// Send to the channel where the command was invoked
|
||||
await interaction.channel.send(randomMessage);
|
||||
logInfo(`[debug] Sent forced MOTD: ${randomMessage}`);
|
||||
await interaction.editReply({
|
||||
content: `✅ MOTD sent successfully!\n\n**Message:** ${randomMessage}`,
|
||||
});
|
||||
} else {
|
||||
await interaction.editReply({
|
||||
content: '❌ Could not fetch MOTD.',
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'throwback': {
|
||||
logInfo('[debug] ADMIN triggered throwback');
|
||||
if (!process.env.THROWBACK_CHANNEL) {
|
||||
await interaction.editReply({
|
||||
content: '❌ THROWBACK_CHANNEL not configured.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Get provider/config from client
|
||||
const provider = (interaction.client as any).provider?.();
|
||||
const llmconf = (interaction.client as any).llmconf?.();
|
||||
const sysprompt = (interaction.client as any).sysprompt?.();
|
||||
|
||||
if (!provider || !llmconf || !sysprompt) {
|
||||
await interaction.editReply({
|
||||
content: '❌ LLM provider/configuration not available.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine source channel (optional parameter or default)
|
||||
const sourceId = interaction.options.getString('source');
|
||||
let sourceChannel: any;
|
||||
if (sourceId) {
|
||||
sourceChannel = await interaction.client.channels.fetch(sourceId);
|
||||
if (!sourceChannel || !('messages' in sourceChannel)) {
|
||||
await interaction.editReply({
|
||||
content: '❌ Source channel not found or invalid.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sourceChannel = await interaction.client.channels.fetch(
|
||||
process.env.THROWBACK_CHANNEL
|
||||
);
|
||||
}
|
||||
|
||||
// Target channel is where the command was invoked
|
||||
const targetChannel = interaction.channel;
|
||||
|
||||
try {
|
||||
const result = await triggerThrowback(
|
||||
interaction.client,
|
||||
sourceChannel,
|
||||
targetChannel,
|
||||
provider,
|
||||
sysprompt,
|
||||
llmconf
|
||||
);
|
||||
await interaction.editReply({
|
||||
content: `✅ Throwback sent successfully!\n\n**Original message:** ${result.originalMessage}\n\n**Reply:** ${result.response}`,
|
||||
});
|
||||
} catch (err) {
|
||||
logError(`[debug] Error fetching throwback message: ${err}`);
|
||||
await interaction.editReply({
|
||||
content: `❌ Error: ${err}`,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'biggest-loser': {
|
||||
logInfo('[debug] ADMIN triggered biggest loser announcement');
|
||||
if (!process.env.LOSER_CHANNEL) {
|
||||
await interaction.editReply({
|
||||
content: '❌ LOSER_CHANNEL not configured.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine source guild (optional parameter or default)
|
||||
const sourceId = interaction.options.getString('source');
|
||||
|
||||
// Target channel is where the command was invoked
|
||||
const targetChannel = interaction.channel;
|
||||
|
||||
try {
|
||||
const declaration = await sendBiggestLoserAnnouncement(
|
||||
interaction.client,
|
||||
targetChannel,
|
||||
sourceId || undefined
|
||||
);
|
||||
|
||||
logInfo(`[debug] Declaring biggest loser: ${declaration}`);
|
||||
await targetChannel.send(declaration);
|
||||
await targetChannel.send(
|
||||
'https://tenor.com/view/klajumas-spit-skreplis-klajumas-skreplis-gif-13538828554330887910'
|
||||
);
|
||||
await interaction.editReply({
|
||||
content: `✅ Biggest loser announcement sent!\n\n**Declaration:** ${declaration}`,
|
||||
});
|
||||
} catch (err) {
|
||||
logError(`[debug] Error finding biggest loser: ${err}`);
|
||||
await interaction.editReply({
|
||||
content: `❌ Error: ${err}`,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
await interaction.editReply({
|
||||
content: `❌ Unknown action: ${subcommand}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
logError(`[debug] Error executing debug command: ${err}`);
|
||||
await interaction.editReply({
|
||||
content: `❌ Error: ${err}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('debug')
|
||||
.setDescription('Debug commands for admin')
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('action')
|
||||
.setDescription('The scheduled event to trigger')
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
{ name: 'MOTD (Message of the Day)', value: 'motd' },
|
||||
{ name: 'Throwback (1 year ago message)', value: 'throwback' },
|
||||
{ name: 'Biggest Loser Announcement', value: 'biggest-loser' }
|
||||
)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('source')
|
||||
.setDescription('Source channel/guild ID to pull history from (optional)')
|
||||
),
|
||||
execute: debugCommand,
|
||||
};
|
||||
Reference in New Issue
Block a user