diff --git a/.env.example b/.env.example index 7fbf4f575..8756648b3 100644 --- a/.env.example +++ b/.env.example @@ -21,4 +21,7 @@ STRANGE_API_KEY= # SPOTFIY [Required for Spotify Support] SPOTIFY_CLIENT_ID= -SPOTIFY_CLIENT_SECRET= \ No newline at end of file +SPOTIFY_CLIENT_SECRET= + +#Required for gemini command (https://aistudio.google.com/app/prompts/new_chat) +GEMINI_API= \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 84860170e..d8173ddd3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "5.5.0", "license": "ISC", "dependencies": { + "@google/generative-ai": "^0.14.0", "@lavaclient/queue": "^2.1.1", "@lavaclient/spotify": "^3.1.0", "@vitalets/google-translate-api": "^9.2.0", @@ -966,6 +967,15 @@ "node": ">=14" } }, + "node_modules/@google/generative-ai": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/@google/generative-ai/-/generative-ai-0.14.0.tgz", + "integrity": "sha512-wNgIGEpInlVd98SapqvnQX8HQz0zM43U9NMvrbIMKQzz2pQm60pJTeHHlICTDcy/yZNLsvFQ/RfD+Ck9H8K7vw==", + "license": "Apache-2.0", + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.14", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", @@ -2554,6 +2564,7 @@ "version": "0.1.4", "resolved": "https://registry.npmjs.org/erlpack/-/erlpack-0.1.4.tgz", "integrity": "sha512-CJYbkEvsB5FqCCu2tLxF1eYKi28PvemC12oqzJ9oO6mDFrFO9G9G7nNJUHhiAyyL9zfXTOJx/tOcrQk+ncD65w==", + "hasInstallScript": true, "license": "MIT", "optional": true, "dependencies": { @@ -5463,6 +5474,7 @@ "version": "0.1.9", "resolved": "https://registry.npmjs.org/zlib-sync/-/zlib-sync-0.1.9.tgz", "integrity": "sha512-DinB43xCjVwIBDpaIvQqHbmDsnYnSt6HJ/yiB2MZQGTqgPcwBSZqLkimXwK8BvdjQ/MaZysb5uEenImncqvCqQ==", + "hasInstallScript": true, "license": "MIT", "optional": true, "dependencies": { diff --git a/package.json b/package.json index 724f5e389..677a4fdbf 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "url": "https://github.com/saiteja-madha/discord-js-bot/issues" }, "dependencies": { + "@google/generative-ai": "^0.14.0", "@lavaclient/queue": "^2.1.1", "@lavaclient/spotify": "^3.1.0", "@vitalets/google-translate-api": "^9.2.0", diff --git a/src/commands/utility/Gemini.js b/src/commands/utility/Gemini.js new file mode 100644 index 000000000..747fc6393 --- /dev/null +++ b/src/commands/utility/Gemini.js @@ -0,0 +1,68 @@ +const { EmbedBuilder, ApplicationCommandOptionType } = require("discord.js"); +const { GoogleGenerativeAI } = require("@google/generative-ai"); +const { EMBED_COLORS, MUSIC } = require("@root/config"); +const MODEL_NAME = "gemini-pro"; + + +/** + * @type {import("@structures/Command")} + */ +module.exports = { + name: "gemini", + description: "talk with gemini", + category: "UTILITY", + botPermissions: ["EmbedLinks"], + command: { + enabled: true, + usage: "Text", + minArgsCount: 1, + }, + slashCommand: { + enabled: true, + options: [ + { + name: "text", + description: "the text for gemini", + type: ApplicationCommandOptionType.String, + required: true, + }, + ], + }, + + async messageRun(message, args) { + const query = args.join(" "); + const response = await play(message, query); + await message.safeReply(response); + }, + + async interactionRun(interaction) { + const query = interaction.options.getString("text"); + const response = await play(interaction, query); + await interaction.followUp(response); + }, +}; + +/** + * @param {import("discord.js").CommandInteraction|import("discord.js").Message} arg0 + * @param {string} query + */ +async function play({ member, guild, channel }, query) { + const genAI = new GoogleGenerativeAI(process.env.GEMINI_API); + + const model = genAI.getGenerativeModel({ model: MODEL_NAME }); + + const result = await model.generateContent(query); + + const reply = result.response.text(); + const embed = new EmbedBuilder() + .setColor(EMBED_COLORS.BOT_EMBED) + .setTitle(query) + .setDescription(reply) + .setFooter({ text: `Request By: ${member.user.username}` }); + + + return { embeds: [embed] }; + + + +}