diff --git a/src/bot/commands/ai.ts b/src/bot/commands/ai.ts index f9f35e8..eb8fcfd 100644 --- a/src/bot/commands/ai.ts +++ b/src/bot/commands/ai.ts @@ -10,6 +10,7 @@ import Logout from "./ai/logout"; import Interogate from "./ai/interogate"; import { ModelGenerationInputStableSamplers } from "../../internal_libs/aihorde"; import Advanced from "./ai/advanced"; +import Give from "./ai/give"; const commandData = new SlashCommandBuilder() @@ -141,7 +142,27 @@ const commandData = new SlashCommandBuilder() "en-GB": "The image to interrogate", "en-US": "The image to interrogate" })) - ).addSubcommandGroup(subcommandGroup => subcommandGroup + ) + .addSubcommand(subcommand => subcommand + .setName("give") + .setDescription("Donner des kudos à un utilisateur") + .setDescriptionLocalizations({ + fr: "Donner des kudos à un utilisateur", + "en-GB": "Give kudos to an user", + "en-US": "Give kudos to an user" + }) + .addUserOption(option => option.setName("user").setDescription("L'utilisateur").setRequired(true).setDescriptionLocalizations({ + fr: "L'utilisateur", + "en-GB": "The user", + "en-US": "The user" + })) + .addNumberOption(option => option.setName("amount").setDescription("Le nombre de kudos à donner").setRequired(false).setDescriptionLocalizations({ + fr: "Le nombre de kudos à donner", + "en-GB": "The number of kudos to give", + "en-US": "The number of kudos to give" + })) + ) + .addSubcommandGroup(subcommandGroup => subcommandGroup .setName("advanced") .setDescription("Commandes avancées de génération").addSubcommand(subcommand => subcommand .setName("imagine") @@ -286,6 +307,8 @@ export class IaCommand extends CommandsBase { case "ask": await Ask(this, interaction); break; + case "give": + await Give(this, interaction); case "interogate": await Interogate(this, interaction); break; diff --git a/src/bot/commands/ai/give.ts b/src/bot/commands/ai/give.ts new file mode 100644 index 0000000..2ea0942 --- /dev/null +++ b/src/bot/commands/ai/give.ts @@ -0,0 +1,79 @@ +import { ActionRowBuilder, CommandInteraction, CommandInteractionOptionResolver, EmbedBuilder, MessageFlags, ModalBuilder, TextInputBuilder, TextInputStyle } from "discord.js"; +import CommandsBase from "../baseCommands"; + +export default async function Give(command: CommandsBase, interaction: CommandInteraction) { + let i = await interaction.deferReply() + let options = interaction.options; + let userSelected = options.getUser("user", true); + let amount = 1; + if(options instanceof CommandInteractionOptionResolver) { + amount = options.getNumber("amount") || 1; + } + i.edit({ + content: "Recherche en cours de l'utilisateur dans la base de donnée", + }); + let giverUser = await command.client.database.users.findFirst({ + where: { + id: interaction.user.id + } + }); + if (!giverUser) return i.edit({ + content: "Vous n'êtes pas enregistré" + `, vous devez vous enregistrer avec la commande `, + }); + i.edit({ + content: "Recherche en cours de l'utilisateur dans l'API", + }); + let token = command.client.decryptString(giverUser.horde_token); + let ai = command.client.aiHorde; + try { + let user = await ai.findUser({ + token + }); + if(user.kudos < amount) return i.edit({ + content: "Vous n'avez pas assez de kudos", + }); + // find the other user + let receiverUser = await command.client.database.users.findFirst({ + where: { + id: userSelected.id + } + }); + if(!receiverUser) return i.edit({ + content: "L'utilisateur n'est pas enregistré", + }); + try{ + let receiverToken = command.client.decryptString(receiverUser.horde_token); + let receiver = await ai.findUser({ + token: receiverToken + }); + // give kudos + + ai.postKudosTransfer({ + username: receiver.username, + amount + },{ + token: token + }).then(async (content) => { + i.edit({ + content:`Vous avez donné ${content.transferred} kudos à <@${userSelected.id}> (${receiver.username})` + }); + }).catch(async (err) => { + i.edit({ + content: "Une erreur est survenue lors du transfert de kudos, réessayer", + }); + }); + }catch(e){ + return i.edit({ + content: "L'utilisateur cible n'est pas enregistré", + }); + } + } catch (e) { + return i.edit({ + content: "Le token est invalide vous devez vous reconnecter", + }); + } +} + +function Capitalize(str: string) { + return `**${str.charAt(0).toUpperCase() + str.slice(1)}**` +} \ No newline at end of file