This commit is contained in:
Flummi 2024-04-24 16:22:40 +02:00
parent 2ac0d2de6f
commit ec7060686a
2 changed files with 50 additions and 23 deletions

View File

@ -18,6 +18,10 @@ export default new class {
return ~~(Math.random() * (max - 1) + 1); return ~~(Math.random() * (max - 1) + 1);
}; };
sleep(ms) {
return new Promise(r => setTimeout(r, ms));
};
async getPlayerlist(world, clanid) { async getPlayerlist(world, clanid) {
const res = await (await fetch(`https://${world}.freewar.de/freewar/dump_players.php`)).text(); const res = await (await fetch(`https://${world}.freewar.de/freewar/dump_players.php`)).text();
return res.split("\n").map(p => { return res.split("\n").map(p => {

View File

@ -94,32 +94,42 @@ bot.on('message', async e => {
} }
} }
let tldr = false;
if(e.message.match(/^!tldr/i)) {
conv.push({
role: 'user',
content: `${e.user.nick} schreibt: schreibe eine kurze Zusammenfassung der letzten 50 Nachrichten.`
});
tldr = true;
}
if(!tldr) {
conv.push({ conv.push({
role: 'user', role: 'user',
content: `${e.user.nick} schreibt: ${e.message.trim()}` content: `${e.user.nick} schreibt: ${e.message.trim()}`
}); });
await fs.writeFile(`./data/conversations/${constr}.json`, JSON.stringify(conv)); await fs.writeFile(`./data/conversations/${constr}.json`, JSON.stringify(conv));
conversations.set(constr, conv); conversations.set(constr, conv);
}
if(!e.message?.match(/ra+i+ne+r/i)) { if(!e.message?.match(/\bra+i+ne+r\b/i) && +e.self.me.id !== +e.raw?.reply_to_message?.from?.id && !tldr) {
if(!config.initiative.includes(constr)) if(!config.initiative.includes(constr))
return; return;
let probability = 20; // default, 5% let probability = 100;
if(e.message.match(/.*\?$/)) { if(e.message.match(/.*\?$/))
probability = 5; // 20% probability = 20;
}
if(lib.rand(probability) !== 1) { if(lib.rand(probability) !== 1)
return; return;
} }
}
// Rainer matched // Rainer matched
if(last) if(typeof e.sendChatAction !== 'undefined')
return await e.reply(`ich antworte bereits ${last}!`); await e.sendChatAction('typing');
while(last) await lib.sleep(500);
const actcon = [{ const actcon = [{
"role": "system", "role": "system",
@ -142,10 +152,12 @@ bot.on('message', async e => {
}); });
} }
actcon.push(...conv, { if(!tldr) {
role: 'user', actcon.push(...conv.slice(-15));
content: `${e.user.nick} schreibt: ${e.message.trim()}` }
}); else {
actcon.push(...conv);
}
const opts = { const opts = {
method: 'POST', method: 'POST',
@ -189,11 +201,18 @@ bot.on('message', async e => {
console.log("Rainer: " + res.choices[0].message.content.trim()); console.log("Rainer: " + res.choices[0].message.content.trim());
try { try {
if(initials[constr] && initials[constr].langmod === 'oger') let orig = res.choices[0].message.content.trim();
await e.reply(oger(res.choices[0].message.content.trim())); for(let i = 0, cl = orig.length; i < cl; i += 1024) {
else const msg = orig.substring(i, i + 1024);
await e.reply(res.choices[0].message.content.trim()); if(initials[constr] && initials[constr].langmod === 'oger') {
await e.reply(oger(msg));
}
else {
await e.reply(msg);
}
}
} catch(err) { } catch(err) {
console.error(err);
await e.reply('ups, kann ich nicht schreiben, wäre zu viel gewesen.'); await e.reply('ups, kann ich nicht schreiben, wäre zu viel gewesen.');
} }
} }
@ -204,3 +223,7 @@ bot.on('message', async e => {
last = false; last = false;
return; return;
}); });
bot.on('error', err => {
console.error(err);
});