add Gemini support

still not tested
This commit is contained in:
Amane Serenetia 2024-07-01 08:43:47 +07:00
parent 5b1aee1b95
commit bd8117cc15
3 changed files with 72 additions and 6 deletions

View File

@ -19,6 +19,5 @@ WEATHERSTACK_KEY=
# Required for image commands (https://strangeapi.fun/docs)
STRANGE_API_KEY=
# SPOTFIY [Required for Spotify Support]
SPOTIFY_CLIENT_ID=
SPOTIFY_CLIENT_SECRET=
# Required for gemini command (https://aistudio.google.com/app/prompts/new_chat)
GEMINI_API=

View File

@ -23,9 +23,8 @@ WEATHERSTACK_KEY=
# Required for image commands (https://strangeapi.fun/docs)
STRANGE_API_KEY=
# SPOTFIY [Required for Spotify Support]
SPOTIFY_CLIENT_ID=
SPOTIFY_CLIENT_SECRET=
# Required for gemini command (https://aistudio.google.com/app/prompts/new_chat)
GEMINI_API=
```
kalau dapet error sama lavaclient plugin coba ganti ```package.json``` yang ada di ```node_modules/@lavaclient/plugin-queue/``` yang awal nya seperti ini:

View File

@ -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] };
}