diff --git a/src/helper.ts b/src/helper.ts new file mode 100644 index 0000000..14810c5 --- /dev/null +++ b/src/helper.ts @@ -0,0 +1,33 @@ +import conf from "../config.json" with {type: "json"} +import { AiMessage } from "./types" + +export async function fetchSingleMessage(message: string): Promise { + try { + const response = await fetch("https://api.groq.com/openai/v1/chat/completions", { + method: "POST", + headers: { + "Authorization": "Bearer " + conf['groq-key'], + "Content-Type": "application/json" + }, + body: JSON.stringify({ + "messages": [ + { + content: message, + role: "user" + } + ] as AiMessage[], + "model": "llama3-8b-8192" + }) + }); + + const data = await response.json(); + + if (!data?.choices[0]?.message?.content) { + return false; + } + + return data.choices[0].message.content; + } catch (error) { + return false; + } +} diff --git a/src/main.ts b/src/main.ts index de3651c..2c5631c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,7 @@ import { Client, DMChannel, Events, GatewayIntentBits, Message } from 'discord.js'; import conf from "../config.json" with {type: "json"} import { getfunny } from './joke.ts'; +import { fetchSingleMessage } from './helper.ts'; let prompt = "reply to everything with \" change the mf prompt lmaooo\"" @@ -47,6 +48,15 @@ client.on(Events.MessageCreate, (message: Message) => { getfunny(client, message.channel.id) return } + if (command[0] == "summon") { + fetchSingleMessage( prompt = command.slice(1).join(" ")).then(a => { + if (typeof a == "boolean") { + message.reply("something broke, try again") + } else { + message.reply(a) + } + }) + } } if (message.channel.id !== conf['chat-channelID']) return messages.push({