First commit for dscrdbt
This commit is contained in:
59
events/interacionAiPost.js
Normal file
59
events/interacionAiPost.js
Normal 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,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
33
events/interactionCreate.js
Normal file
33
events/interactionCreate.js
Normal 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
9
events/ready.js
Normal 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}`);
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user