First commit for dscrdbt

This commit is contained in:
2025-04-15 16:15:56 -06:00
commit 11a100eacf
13 changed files with 482 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
const { Events } = require('discord.js');
const { generateCaption, generateImage, generatePostImage } = require('../utils/newsProcessor');
module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if (!interaction.isModalSubmit()) return;
if (interaction.customId !== 'aipostModal') return;
try {
const newsLink = interaction.fields.getTextInputValue('newsLinkInput');
await interaction.deferReply();
// Process the article with status updates
// await interaction.editReply('📰 Reading article...');
// const articleData = await scrapeArticle(newsLink);
await interaction.editReply('✍️ Generating image copy...');
const imageText = await generateImage(newsLink);
await interaction.editReply('🎨 Creating AI image...');
const imageUrl = await generatePostImage(imageText);
await interaction.editReply('📝 Generating Instagram post...');
const postText = await generateCaption(newsLink);
// First message with the AI-generated image and its copy
await interaction.editReply({
content: `📸 **Generated Image Copy:**\n${imageText}`,
files: [imageUrl],
});
// Second message with the Instagram post copy
await interaction.followUp({
content: `📱 **Generated Instagram Post:**\n${postText}`,
});
}
catch (error) {
console.error('Error in modal submission:', error);
const errorMessage = error.message.includes('Failed to')
? error.message
: 'An unexpected error occurred while generating the post.';
if (interaction.deferred) {
await interaction.editReply({
content: `${errorMessage}\nPlease try again or use a different article.`,
ephemeral: true,
});
}
else {
await interaction.reply({
content: `${errorMessage}\nPlease try again or use a different article.`,
ephemeral: true,
});
}
}
},
};

View File

@@ -0,0 +1,33 @@
const { Events } = require('discord.js');
module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
}
catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({
content: 'There was an error while executing this command',
ephemeral: true,
});
}
else {
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true,
});
}
}
},
};

9
events/ready.js Normal file
View File

@@ -0,0 +1,9 @@
const { Events } = require('discord.js');
module.exports = {
name: Events.ClientReady,
once: true,
execute(client) {
console.log(`Ready! Logged in as ${client.user.tag}`);
},
};