This commit is contained in:
amy 2024-08-10 15:48:19 +03:30
commit fcbfe08096
8 changed files with 540 additions and 0 deletions

36
src/joke.ts Normal file
View file

@ -0,0 +1,36 @@
import { Client, DMChannel, Message } from "discord.js";
import {AiMessage} from "./types.ts"
import conf from "../config.json" with {type: "json"}
export function getfunny(client: Client, id: string): string {
let messages = [
{
role: "system",
content: "you will be given 20 user-written messages. try and make a funny joke out of the given 20 messages. should not be too long"
}
] as AiMessage[]
(client.channels.cache.get(id) as DMChannel).messages.fetch({ limit: 20 }).then(a => {
for (const i of [... a.values()].reverse()) {
messages.push({
role: "user",
name: i.author.username,
content: i.content
})
}
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": messages,
"model": "llama3-8b-8192"
})
}).then(a => {
a.json().then( a => {
(client.channels.cache.get(id) as DMChannel).send(a?.choices[0]?.message?.content)
})
})
})
return "lmaoo"
}

91
src/main.ts Normal file
View file

@ -0,0 +1,91 @@
import { Client, DMChannel, Events, GatewayIntentBits, Message } from 'discord.js';
import conf from "../config.json" with {type: "json"}
import { getfunny } from './joke.ts';
let prompt = "reply to everything with \" change the mf prompt lmaooo\""
function getinitmessage() {
return {
"role": "system",
"name": "fagbot",
"content": prompt
}
}
let messages = [
getinitmessage()
]
const client = new Client({
intents: Object.keys(GatewayIntentBits).map((a) => {
return GatewayIntentBits[a]
}),
});
client.on('ready', () => {
console.log(`Logged in as ${client?.user?.tag}!`);
(client.channels.cache.get(conf['debug-channelID']) as DMChannel).send("IM ALIVE BITCHES")
});
client.on(Events.MessageCreate, (message: Message) => {
if (message.author.bot) return
if (message.content.startsWith("!fag ")) {
const command = message.content.replaceAll("!fag ", "").split(" ")
if (command[0] == "reset") {
messages = [getinitmessage()]
message.reply("i got dementia lmao")
return
}
if (command[0] == "prompt") {
prompt = command.slice(1).join(" ")
messages = [getinitmessage()]
message.reply("prompt changed - reset as well idk")
return
}
if (command[0] == "overrideChatFunny") {
getfunny(client, message.channel.id)
return
}
}
if (message.channel.id !== conf['chat-channelID']) return
messages.push({
"role": "user",
"name": message.author.username,
"content": message.content
})
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": messages,
"model": "llama3-8b-8192"
})
}).then(a => a.json().then(a => {
if (!a?.choices[0]?.message?.content) {
message.reply("something shat itself. please try again")
}
messages.push({
"role": "assistant",
"name": "fagbot",
"content": a?.choices[0]?.message?.content
})
console.log(messages)
message.reply(a.choices[0].message.content)
})).catch(_ => {
message.reply("something shat itself. please try again")
})
})
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'ping') {
await interaction.reply('Pong!');
}
});
client.login(conf['discord-key']);

5
src/types.ts Normal file
View file

@ -0,0 +1,5 @@
export interface AiMessage {
"role": "system" | "user";
"name"?: string;
"content": string;
}