/summon fagai ~ ~ ~
This commit is contained in:
parent
fcbfe08096
commit
2235889ae8
2 changed files with 43 additions and 0 deletions
33
src/helper.ts
Normal file
33
src/helper.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import conf from "../config.json" with {type: "json"}
|
||||
import { AiMessage } from "./types"
|
||||
|
||||
export async function fetchSingleMessage(message: string): Promise<string | boolean> {
|
||||
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;
|
||||
}
|
||||
}
|
10
src/main.ts
10
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({
|
||||
|
|
Loading…
Reference in a new issue