diff --git a/src/controllers/plugins/chat-gpt.controller.ts b/src/controllers/plugins/chat-gpt.controller.ts index 243af15..52246ea 100644 --- a/src/controllers/plugins/chat-gpt.controller.ts +++ b/src/controllers/plugins/chat-gpt.controller.ts @@ -46,7 +46,7 @@ export const chatGTPController = async (prompt: string, apiKey: string, organiza */ export const sendPrompt = async ({ input, - model = 'gpt-3.5-turbo', + model = 'gpt-4o-mini', max_tokens = 300, temperature = 0.7, presence_penalty = 0.5, diff --git a/src/controllers/plugins/verify.controller.ts b/src/controllers/plugins/verify.controller.ts index 79d1262..325dbd4 100644 --- a/src/controllers/plugins/verify.controller.ts +++ b/src/controllers/plugins/verify.controller.ts @@ -16,106 +16,123 @@ import { deleteFromCache, getFromCache, setToCache } from '../../libs/node-cache import { updateMetadataGuildPlugin } from '../bot/plugins.controller' export const verifyGuildPluginSettings = async (interaction: ChatInputCommandInteraction) => { - const role = interaction.options.get('role')?.value as string + try { + const role = interaction.options.get('role')?.value as string - const guildRole = interaction.guild.roles.cache.get(role) + const guildRole = interaction.guild.roles.cache.get(role) - await updateMetadataGuildPlugin({ role }, 'verify', interaction.guildId) + await updateMetadataGuildPlugin({ role }, 'verify', interaction.guildId) - const button = new ButtonBuilder() - .setCustomId('open_verify_modal') - .setLabel('Verify') - .setStyle(ButtonStyle.Primary) + const button = new ButtonBuilder() + .setCustomId('open_verify_modal') + .setLabel('Verify') + .setStyle(ButtonStyle.Primary) - // Send the button to a channel - await (interaction.channel as TextChannel).send({ - content: ` + // Send the button to a channel + await (interaction.channel as TextChannel).send({ + content: ` ## 🤖 Captcha Verification Please click the button below to verify that you are human. `, - components: [new ActionRowBuilder().addComponents(button)], - }) - - await interaction.editReply({ - content: `Verify plugin settings updated. All verified users will receive the ${guildRole} role.`, - }) + components: [new ActionRowBuilder().addComponents(button)], + }) + + await interaction.editReply({ + content: `Verify plugin settings updated. All verified users will receive the ${guildRole} role.`, + }) + } catch (error) { + console.error(error) + await interaction.editReply({ + content: `Failed to update the plugin settings.`, + }) + } } export const verifyModal = async (interaction: Interaction) => { - const emojiMap = [ - { emoji: '😊', name: 'happy' }, - { emoji: '😢', name: 'sad' }, - { emoji: '😡', name: 'angry' }, - ] - - if (interaction.isButton()) { - if (interaction.customId !== 'open_verify_modal') return - - const userCaptchaChallenge = emojiMap[Math.floor(Math.random() * emojiMap.length)] - deleteFromCache(`userCaptchaChallenge#${interaction.user.id}`) - setToCache(`userCaptchaChallenge#${interaction.user.id}`, userCaptchaChallenge, 1) - - // Define a modal - const modal = new ModalBuilder() - .setCustomId('verify_modal') - .setTitle('Captcha verification') - .addComponents( - new ActionRowBuilder().addComponents( - new TextInputBuilder() - .setCustomId('input1') - .setLabel(`Which emotion does this emoji ${userCaptchaChallenge.emoji} represent?`) - .setPlaceholder( - `Type the name of the emotion, ex: ${emojiMap.map((e) => e.name).join(', ')}`, - ) - .setStyle(TextInputStyle.Short), - ), - ) - - // Show the modal to the user - await interaction.showModal(modal) + try { + const emojiMap = [ + { emoji: '😊', name: 'happy' }, + { emoji: '😢', name: 'sad' }, + { emoji: '😡', name: 'angry' }, + ] + + if (interaction.isButton()) { + if (interaction.customId !== 'open_verify_modal') return + + const userCaptchaChallenge = emojiMap[Math.floor(Math.random() * emojiMap.length)] + deleteFromCache(`userCaptchaChallenge#${interaction.user.id}`) + setToCache(`userCaptchaChallenge#${interaction.user.id}`, userCaptchaChallenge, 1) + + // Define a modal + const modal = new ModalBuilder() + .setCustomId('verify_modal') + .setTitle('Captcha verification') + .addComponents( + new ActionRowBuilder().addComponents( + new TextInputBuilder() + .setCustomId('input1') + .setLabel(`Which emotion does this emoji ${userCaptchaChallenge.emoji} represent?`) + .setPlaceholder( + `Type the name of the emotion, ex: ${emojiMap.map((e) => e.name).join(', ')}`, + ) + .setStyle(TextInputStyle.Short), + ), + ) + + // Show the modal to the user + await interaction.showModal(modal) + } + } catch (error) { + console.error(error) } } export const verifyModalSubmit = async (interaction: Interaction) => { - if (interaction.type === InteractionType.ModalSubmit) { - if (interaction.customId !== 'verify_modal') return - const input = interaction.fields.getTextInputValue('input1').toLocaleLowerCase() - const userCaptchaChallenge = getFromCache(`userCaptchaChallenge#${interaction.user.id}`) as { - emoji: string - name: string - } + try { + if (interaction.type === InteractionType.ModalSubmit) { + if (interaction.customId !== 'verify_modal') return + const input = interaction.fields.getTextInputValue('input1').toLocaleLowerCase() + const userCaptchaChallenge = getFromCache(`userCaptchaChallenge#${interaction.user.id}`) as { + emoji: string + name: string + } - if (input !== userCaptchaChallenge.name) { - await interaction.reply({ - content: `❌ Failed to verify that you are human. Please try again.`, - ephemeral: true, - }) - } else { - const member = interaction.member - - // Ensure the member is indeed a GuildMember object to access the GuildMemberRoleManager - if (member instanceof GuildMember) { - const guildPluginSettings = await Hans.guildPluginSettings(interaction.guildId, 'verify') - - const guildRole = interaction.guild.roles.cache.get(guildPluginSettings.metadata.role) - - if (guildRole) { - await member.roles - .add(guildRole) - .then(() => interaction.reply({ content: '✅ You are now verified.', ephemeral: true })) - .catch((error) => { - // Handle errors, like missing permissions - console.error(error) - interaction.reply({ content: 'Failed to add the role.', ephemeral: true }) - }) + if (input !== userCaptchaChallenge.name) { + await interaction.reply({ + content: `❌ Failed to verify that you are human. Please try again.`, + ephemeral: true, + }) + } else { + const member = interaction.member + + // Ensure the member is indeed a GuildMember object to access the GuildMemberRoleManager + if (member instanceof GuildMember) { + const guildPluginSettings = await Hans.guildPluginSettings(interaction.guildId, 'verify') + + const guildRole = interaction.guild.roles.cache.get(guildPluginSettings.metadata.role) + + if (guildRole) { + await member.roles + .add(guildRole) + .then(() => + interaction.reply({ content: '✅ You are now verified.', ephemeral: true }), + ) + .catch((error) => { + // Handle errors, like missing permissions + console.error(error) + interaction.reply({ content: 'Failed to add the role.', ephemeral: true }) + }) + } else { + // Role not found + interaction.reply({ content: 'Role not found.', ephemeral: true }) + } } else { - // Role not found - interaction.reply({ content: 'Role not found.', ephemeral: true }) + // Member is not a GuildMember object + interaction.reply({ content: 'Could not resolve member details.', ephemeral: true }) } - } else { - // Member is not a GuildMember object - interaction.reply({ content: 'Could not resolve member details.', ephemeral: true }) } } + } catch (error) { + console.error(error) } } diff --git a/src/realtime/presence.realtime.ts b/src/realtime/presence.realtime.ts index 162f248..9fcaca0 100644 --- a/src/realtime/presence.realtime.ts +++ b/src/realtime/presence.realtime.ts @@ -16,7 +16,7 @@ export const configsRealtime = () => { table: 'configs', }, async (payload) => { - if (!!process.env.ISDEV) { + if (!!process.env.ISDEV) { console.log('Guild plugin updated:', payload.new) }