mirror of
https://github.com/MinazukiAmane/Tinasha-Bot.git
synced 2025-03-15 12:55:59 +08:00
add Gemini support
still not tested
This commit is contained in:
parent
5b1aee1b95
commit
bd8117cc15
@ -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=
|
@ -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:
|
||||
|
68
src/commands/utility/Gemini.js
Normal file
68
src/commands/utility/Gemini.js
Normal 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] };
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user