Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
44a8e3f20f |
8 changed files with 1211 additions and 77 deletions
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"groq-key": "",
|
||||
"discord-key": "",
|
||||
"chat-channelID": [""],
|
||||
"chat-channelID": "",
|
||||
"should-send-debug": false,
|
||||
"debug-channelID": ""
|
||||
}
|
|
@ -11,11 +11,12 @@
|
|||
"type": "module",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"discord.js": "^14.15.3"
|
||||
"discord.js": "^14.15.3",
|
||||
"ts-node": "^10.9.2",
|
||||
"sqlite3": "^5.1.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.1.0",
|
||||
"ts-node-esm": "^10.9.2",
|
||||
"typescript": "^5.5.4"
|
||||
}
|
||||
}
|
1050
pnpm-lock.yaml
1050
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
43
src/dbhelper.ts
Normal file
43
src/dbhelper.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { Message, User } from "discord.js";
|
||||
import sqlite3 from "sqlite3";
|
||||
|
||||
export function hasPartner(db: sqlite3.Database, id: string){
|
||||
db.prepare(`SELECT * FROM users WHERE id = (?)`).all(id, resp=> {
|
||||
console.log(resp)
|
||||
}), err => {
|
||||
// i will keep this here just to annoy sunnie
|
||||
err ? console.error("bruh") : null;
|
||||
}
|
||||
}
|
||||
|
||||
export function getid(commandarg: string | User): string {
|
||||
if (typeof commandarg === "string") {
|
||||
if (commandarg.startsWith("<")) {
|
||||
return commandarg.replace(/[<@>]/g, "");
|
||||
} else {
|
||||
return commandarg;
|
||||
}
|
||||
} else {
|
||||
return commandarg.id;
|
||||
}
|
||||
}
|
||||
|
||||
export function getpartner(db: sqlite3.Database, person: string): Promise<any[]|string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.all(`
|
||||
SELECT *
|
||||
FROM users
|
||||
WHERE id = ? OR partner = ?;
|
||||
`, [person, person], (err, rows) => {
|
||||
if (err) {
|
||||
resolve("SQL error. Most likely from echo. Make sure to spam ping her. - " + err)
|
||||
} else {
|
||||
resolve(rows);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function isValidID(...ids: (string | undefined)[]): boolean {
|
||||
return ids.every(id => typeof id === 'string' && /^\d{18}$/.test(id));
|
||||
}
|
|
@ -31,42 +31,3 @@ export async function fetchSingleMessage(message: string): Promise<string | bool
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function explainImage(base64: 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":[
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{"type": "text", "text": "explain this image. be as precise as you can, explain the littlest details"},
|
||||
{
|
||||
"type": "image_url",
|
||||
"image_url": {
|
||||
"url": base64
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
],
|
||||
"model": "llava-v1.5-7b-4096-preview"
|
||||
})
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!data?.choices[0]?.message?.content) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return data.choices[0].message.content;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
73
src/main.ts
73
src/main.ts
|
@ -1,18 +1,49 @@
|
|||
import { Client, DMChannel, Events, GatewayIntentBits, Message } from 'discord.js';
|
||||
import conf from "../config.json" with {type: "json"}
|
||||
import { getfunny } from './joke.ts';
|
||||
import { explainImage, fetchSingleMessage } from './helper.ts';
|
||||
import { fetchSingleMessage } from './helper.ts';
|
||||
import { handlemarriage } from './marriage.ts';
|
||||
import sqlite3 from 'sqlite3';
|
||||
import path from 'path';
|
||||
import { exit } from 'process';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { hasPartner } from './dbhelper.ts';
|
||||
|
||||
let prompt = "reply to everything normally, but have typo in every word."
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
let prompt = "reply to everything normally, but have very bad typos in ever word"
|
||||
|
||||
function getinitmessage() {
|
||||
return {
|
||||
"role": "system",
|
||||
"name": "fagbot",
|
||||
"content": prompt + "\nsince you, as an ai model, cannot understand images, you will be given an explanation of images if they exist.\nthe syntax will be \"{message} - [IMAGE: {explanation of the image}]\""
|
||||
"content": prompt
|
||||
}
|
||||
}
|
||||
|
||||
const db = new sqlite3.Database(path.resolve(__dirname, "../", "incest.db"), (err) => {
|
||||
if (err) {
|
||||
console.error("big fuckup. get mental help")
|
||||
console.error(err)
|
||||
exit(1)
|
||||
} else {
|
||||
console.log("successfully connected to the database")
|
||||
}
|
||||
})
|
||||
db.run(`CREATE TABLE IF NOT EXISTS users
|
||||
(
|
||||
id STRING PRIMARY KEY,
|
||||
partner STRING,
|
||||
daddy STRING,
|
||||
mommy STRING
|
||||
);`
|
||||
, err => {
|
||||
if (err) {
|
||||
console.error('Could not create table', err);
|
||||
} else {
|
||||
console.log('Table initialized');
|
||||
}
|
||||
})
|
||||
|
||||
let messages = [
|
||||
getinitmessage()
|
||||
|
@ -31,9 +62,10 @@ client.on('ready', () => {
|
|||
|
||||
client.on(Events.MessageCreate, (message: Message) => {
|
||||
if (message.author.bot) return
|
||||
if (message.content.startsWith("//")) return
|
||||
if (message.content.startsWith("!fag ")) {
|
||||
const command = message.content.replaceAll("!fag ", "").split(" ")
|
||||
handlemarriage(message, db)
|
||||
hasPartner(db, "712639419785412668")
|
||||
if (command[0] == "reset") {
|
||||
messages = [getinitmessage()]
|
||||
message.reply("i got dementia lmao")
|
||||
|
@ -58,31 +90,12 @@ client.on(Events.MessageCreate, (message: Message) => {
|
|||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (!conf['chat-channelID'].includes(message.channel.id)) return
|
||||
(async function () {
|
||||
let imageexplain: string | boolean = "";
|
||||
|
||||
if (message.attachments.size !== 0) {
|
||||
if (message.attachments.first().contentType.startsWith("image")) {
|
||||
try {
|
||||
const res = await fetch(message.attachments.first().url);
|
||||
const buffer = await res.arrayBuffer();
|
||||
const base64 = Buffer.from(buffer).toString('base64');
|
||||
|
||||
imageexplain = await explainImage("data:" + message.attachments.first().contentType + ";base64," + base64);
|
||||
} catch (error) {
|
||||
console.error("Error processing image:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (message.channel.id !== conf['chat-channelID']) return
|
||||
messages.push({
|
||||
"role": "user",
|
||||
"name": message.author.username,
|
||||
"content": (imageexplain === "" || typeof imageexplain == "boolean") ?
|
||||
message.content : message.content + " - [IMAGE: " + imageexplain + "]"
|
||||
"content": message.content
|
||||
})
|
||||
fetch("https://api.groq.com/openai/v1/chat/completions", {
|
||||
method: "POST",
|
||||
|
@ -92,7 +105,7 @@ client.on(Events.MessageCreate, (message: Message) => {
|
|||
},
|
||||
body: JSON.stringify({
|
||||
"messages": messages,
|
||||
"model": "llama3-groq-70b-8192-tool-use-preview"
|
||||
"model": "llama3-8b-8192"
|
||||
})
|
||||
}).then(a => a.json().then(a => {
|
||||
if (!a?.choices[0]?.message?.content) {
|
||||
|
@ -108,9 +121,7 @@ client.on(Events.MessageCreate, (message: Message) => {
|
|||
})).catch(_ => {
|
||||
message.reply("something shat itself. please try again")
|
||||
})
|
||||
})();
|
||||
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
|
66
src/marriage.ts
Normal file
66
src/marriage.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
import { Message } from "discord.js";
|
||||
import sqlite3 from "sqlite3";
|
||||
import { getid, getpartner, isValidID } from "./dbhelper.ts";
|
||||
import { Person } from "./types.ts";
|
||||
|
||||
export function handlemarriage(message: Message<boolean>, db: sqlite3.Database) {
|
||||
const command = message.content.replaceAll("!fag ", "").split(" ")
|
||||
// if (message[0] === "propose") {
|
||||
// if (hasPartner)
|
||||
// }
|
||||
if (command[0] === "forcemarry") {
|
||||
let husband: string;
|
||||
let wife: string;
|
||||
console.log(command.slice(1))
|
||||
if (command.slice(1).length == 2) {
|
||||
husband = getid(command[1])
|
||||
wife = getid(command[2])
|
||||
console.log("guh")
|
||||
} else if (command.slice(1).length === 1) {
|
||||
console.log("guh2")
|
||||
husband = getid(message.author)
|
||||
wife = getid(command[1])
|
||||
}
|
||||
if (isValidID(husband, wife)) {
|
||||
db.run(`
|
||||
INSERT INTO users
|
||||
(id, partner)
|
||||
VALUES ((?),(?))
|
||||
`, [wife, husband], (err) => {
|
||||
if (err) {
|
||||
message.reply("SQL error. Most likely from echo. Make sure to spam ping her. - " + err);
|
||||
} else {
|
||||
message.reply("Update successful.");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
message.reply("SyntaxError: `error that is passed when im too lazy to set the error`" + wife + " - " + husband)
|
||||
}
|
||||
} else if (command[0] == "getmarriagestatus") {
|
||||
let person: string;
|
||||
try {
|
||||
person = command[1]
|
||||
} catch (err) {
|
||||
message.reply("SyntaxError: `error that is passed when im too lazy to set the error`")
|
||||
return
|
||||
}
|
||||
getpartner(db, person).then((a) => {
|
||||
if (typeof a === "string") {
|
||||
message.reply(a)
|
||||
} else if (!a.length) {
|
||||
message.reply("this mf is single lmaoooooo")
|
||||
} else {
|
||||
const bettera = (a as Person[])
|
||||
if (bettera[0].id == person) {
|
||||
console.log(bettera[0].partner)
|
||||
message.reply(`@silent the personal fag of this person is <@${bettera[0].partner}>`)
|
||||
} else {
|
||||
console.log(bettera[0].id)
|
||||
message.reply(`@silent the personal fag of this person is <@${bettera[0].id}>`)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -3,3 +3,11 @@ export interface AiMessage {
|
|||
"name"?: string;
|
||||
"content": string;
|
||||
}
|
||||
|
||||
export interface Person {
|
||||
"id": string;
|
||||
"married"? : boolean;
|
||||
"mommy" : string | null;
|
||||
"daddy" : string | null;
|
||||
"partner" : string | null
|
||||
}
|
Loading…
Reference in a new issue