blah
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import { exec as _exec } from 'node:child_process';
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
export default new class {
|
||||
exec(cmd) {
|
||||
@ -21,18 +20,4 @@ export default new class {
|
||||
sleep(ms) {
|
||||
return new Promise(r => setTimeout(r, ms));
|
||||
};
|
||||
|
||||
async getPlayerlist(world, clanid) {
|
||||
const res = await (await fetch(`https://${world}.freewar.de/freewar/dump_players.php`)).text();
|
||||
return res.split("\n").map(p => {
|
||||
const player = p.split("\t");
|
||||
return {
|
||||
id: +player[0],
|
||||
name: player[1],
|
||||
xp: +player[2],
|
||||
rasse: player[3],
|
||||
clanid: +player[4]
|
||||
};
|
||||
}).filter(p => p.clanid === clanid)
|
||||
};
|
||||
};
|
||||
|
10
src/inc/trigger/chatbot.mjs
Normal file
10
src/inc/trigger/chatbot.mjs
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
export default async bot => {
|
||||
return [{
|
||||
name: "chatbot",
|
||||
call: /Rainer/i,
|
||||
f: async e => {
|
||||
|
||||
}
|
||||
}];
|
||||
};
|
103
src/index.mjs
103
src/index.mjs
@ -1,16 +1,22 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import cuffeo from 'cuffeo';
|
||||
import fetch from 'node-fetch';
|
||||
import oger from './inc/oger.mjs';
|
||||
import lib from './inc/lib.mjs';
|
||||
import config from '../config.json' assert { type: 'json' };
|
||||
import initials from '../data/initials.json' assert { type: 'json' };
|
||||
import config from '../config.json' with { type: 'json' };
|
||||
import initials from '../data/initials.json' with { type: 'json' };
|
||||
|
||||
const conversations = new Map();
|
||||
const bot = await new cuffeo(config.clients);
|
||||
let last = false;
|
||||
let playerlist = false;
|
||||
|
||||
const parseOutput = text => {
|
||||
text = text.trim().toLowerCase();
|
||||
return text.includes(', ')
|
||||
? text.split(', ')
|
||||
: text.replace(/\d\. /g, '').split('\n');
|
||||
};
|
||||
|
||||
bot.on('message', async e => {
|
||||
if(typeof e.message === 'undefined' || e.message.length <= 2)
|
||||
return;
|
||||
@ -18,21 +24,32 @@ bot.on('message', async e => {
|
||||
console.log(e.user.nick + ": " + e.message);
|
||||
const constr = `${e.network}::${e.channelid}`;
|
||||
|
||||
if(e.message.match(/^!claninfo/i)) {
|
||||
playerlist = await lib.getPlayerlist("welt13", 4760);
|
||||
if(e.message.match(/^!tags \d{1,}$/i)) {
|
||||
try {
|
||||
const id = e.message.substring(6);
|
||||
const f0ck = `https://f0ck.me/t/${id}.webp`;
|
||||
const blob = await (await fetch(f0ck)).arrayBuffer();
|
||||
|
||||
return await e.reply(
|
||||
playerlist.map(p => p.name).join(", ")
|
||||
);
|
||||
}
|
||||
const res = await fetch(`https://api.cloudflare.com/client/v4/accounts/${config.cf.id}/ai/run/${config.cf.model}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${config.cf.key}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
image: [ ...new Uint8Array(blob) ],
|
||||
prompt: "Generate five comma separated tags without colors for this image.",
|
||||
max_tokens: 128
|
||||
})
|
||||
});
|
||||
const json = await res.json();
|
||||
const tags = parseOutput(json.result.description);
|
||||
|
||||
if(e.message.match(/^!gens/i)) {
|
||||
const perf = await (await fetch(`http://${config.api.host}:${config.api.port}/api/extra/perf`)).json();
|
||||
return await e.reply(`total_gens: ${perf.total_gens}`);
|
||||
}
|
||||
|
||||
if(e.message.match(/^!model/i)) {
|
||||
return await e.reply((await (await fetch(`http://${config.api.host}:${config.api.port}/api/v1/model`)).json()).result);
|
||||
return await e.reply(`${f0ck}\n${JSON.stringify(tags)}`);
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(e.message.match(/^!messages/i)) {
|
||||
@ -129,29 +146,16 @@ bot.on('message', async e => {
|
||||
// Rainer matched
|
||||
if(typeof e.sendChatAction !== 'undefined')
|
||||
await e.sendChatAction('typing');
|
||||
while(last) await lib.sleep(500);
|
||||
//while(last) await lib.sleep(500);
|
||||
|
||||
const actcon = [{
|
||||
"role": "system",
|
||||
"content": initials[ initials[constr] ? constr : 'default' ].lore
|
||||
}, {
|
||||
"role": "system",
|
||||
"content": "eingehende Chatnachrichten sind immer folgendermaßen aufgebaut: \"%USERNAME% schreibt: %COMMAND%\". Du schreibst das aber nicht."
|
||||
}, {
|
||||
"role": "system",
|
||||
"content": `Aktuelles Datum und Zeit: ${(new Date()).toLocaleString()}`
|
||||
"content": "Chatnachrichten von anderen sind immer folgendermaßen aufgebaut: \"%USERNAME% schreibt: %COMMAND%\". Du machst das aber nie."
|
||||
}];
|
||||
|
||||
if(constr === 'Discord::1143415824539992206') {
|
||||
if(!playerlist)
|
||||
playerlist = await lib.getPlayerlist('welt13', 4760);
|
||||
|
||||
actcon.push({
|
||||
"role": "user",
|
||||
"content": "Unser Clan besteht aus folgenden Mitgliedern:\n" + playerlist.map(p => `${p.name}: ${p.xp} XP, Rasse: ${p.rasse}`).join("\n")
|
||||
});
|
||||
}
|
||||
|
||||
if(!tldr) {
|
||||
actcon.push(...conv.slice(-15));
|
||||
}
|
||||
@ -164,14 +168,35 @@ bot.on('message', async e => {
|
||||
port: 5001,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${config.api.bearer}`
|
||||
//"Authorization": `Bearer ${config.api.bearer}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
mode: "chat",
|
||||
instruction_template: "Alpaca",
|
||||
model: "em_german_leo_mistral.Q5_K_M.gguf",
|
||||
stream: false,
|
||||
max_tokens: 768,
|
||||
stop: config.stops,
|
||||
max_tokens: 2048,
|
||||
top_k: 40,
|
||||
top_p: 0.92,
|
||||
temperature: 1.0,
|
||||
sampler_order: [6,0,1,3,4,2,5],
|
||||
rep_pen: 1.1,
|
||||
template: {
|
||||
chat: "chat-block",
|
||||
chat_message: "chat"
|
||||
},
|
||||
completion: "completion",
|
||||
context_size: 4096,
|
||||
use_fast_tokenizer: true,
|
||||
roles: {
|
||||
system: "<|im_start|> system",
|
||||
assistant: "<|im_start|> assistant",
|
||||
user: "<|im_start|> user"
|
||||
},
|
||||
stopwords: [
|
||||
"<|im_end|>",
|
||||
"### Response:"
|
||||
],
|
||||
mmap: true,
|
||||
f16: true,
|
||||
messages: actcon
|
||||
})
|
||||
};
|
||||
@ -192,7 +217,7 @@ bot.on('message', async e => {
|
||||
return await e.reply('ich habe dazu nichts zu sagen, du Birne.');
|
||||
|
||||
res.choices[0].message.content = res.choices[0].message.content.split(/(###|---|ASSISTANT)/)[0];
|
||||
res.choices[0].message.content = res.choices[0].message.content.replace(/^Rainer( schreibt| antwortet)?: /, '');
|
||||
res.choices[0].message.content = res.choices[0].message.content.replace(/^.*( schreibt| antwortet)?\: /, '');
|
||||
|
||||
conv.push(res.choices[0].message);
|
||||
conversations.set(constr, conv);
|
||||
@ -202,8 +227,8 @@ bot.on('message', async e => {
|
||||
|
||||
try {
|
||||
let orig = res.choices[0].message.content.trim();
|
||||
for(let i = 0, cl = orig.length; i < cl; i += 1024) {
|
||||
const msg = orig.substring(i, i + 1024);
|
||||
for(let i = 0, cl = orig.length; i < cl; i += 4000) {
|
||||
const msg = orig.substring(i, i + 4000);
|
||||
if(initials[constr] && initials[constr].langmod === 'oger') {
|
||||
await e.reply(oger(msg));
|
||||
}
|
||||
|
Reference in New Issue
Block a user