1
0
forked from keinBot/cuffeo

typescript schmypescript

This commit is contained in:
2025-03-18 09:55:57 +01:00
parent f7ac8ae5cd
commit 52d79e0763
52 changed files with 1948 additions and 891 deletions

View File

@@ -1,21 +0,0 @@
export default bot => {
bot._cmd.set("CAP", msg => { // capkram
switch (msg.params[1]) {
case "LS": // list
bot.send(`CAP REQ :${msg.params[2]}`);
break;
case "ACK": // success
bot.send("AUTHENTICATE PLAIN");
break;
}
});
bot._cmd.set("AUTHENTICATE", msg => { // auth
if (msg.params[0].match(/\+/))
bot.send(`AUTHENTICATE ${new Buffer(bot.username + "\u0000" + bot.username + "\u0000" + bot.options.password).toString("base64")}`);
});
bot._cmd.set("900", msg => { // cap end
bot.send("CAP END");
});
};

26
src/clients/irc/cap.ts Normal file
View File

@@ -0,0 +1,26 @@
import { Bot, Message } from "../../types";
export default (bot: Bot) => {
bot._cmd.set("CAP", (msg: Message) => { // CAP Handling
switch(msg.params[1]) {
case "LS": // List
bot.send(`CAP REQ :${msg.params[2]}`);
break;
case "ACK": // Success
bot.send("AUTHENTICATE PLAIN");
break;
}
});
bot._cmd.set("AUTHENTICATE", (msg: Message) => { // Authentication
if(msg.params[0].match(/\+/)) {
bot.send(`AUTHENTICATE ${Buffer.from(
bot.username + "\u0000" + bot.username + "\u0000" + bot.options.password
).toString("base64")}`);
}
});
bot._cmd.set("900", (msg: Message) => { // End CAP
bot.send("CAP END");
});
};

View File

@@ -1,13 +0,0 @@
export default bot => {
bot._cmd.set("INVITE", msg => { // invite
const user = bot.parsePrefix(msg.prefix);
const channel = msg.params[1];
if(!bot.server.channel.has(channel)) {
bot.join(channel);
setTimeout(() => {
bot.send(`PRIVMSG ${channel} :Hi. Wurde von ${user.nick} eingeladen.`);
}, 1000);
}
});
};

15
src/clients/irc/invite.ts Normal file
View File

@@ -0,0 +1,15 @@
import { Bot, Message, User } from "../../types";
export default (bot: Bot) => {
bot._cmd.set("INVITE", (msg: Message) => {
const user: User = bot.parsePrefix(msg.prefix);
const channel: string = msg.params[1];
if(!bot.server.channel.has(channel)) {
bot.join(channel);
setTimeout(() => {
bot.send(`PRIVMSG ${channel} :Hi. Wurde von ${user.nick} eingeladen.`);
}, 1000);
}
});
};

View File

@@ -1,5 +0,0 @@
export default bot => {
bot._cmd.set("JOIN", msg => { // join
bot.send(`WHO ${msg.params[0]}`);
});
};

7
src/clients/irc/join.ts Normal file
View File

@@ -0,0 +1,7 @@
import { Bot, Message } from "../../types";
export default (bot: Bot) => {
bot._cmd.set("JOIN", (msg: Message) => { // Handle join
bot.send(`WHO ${msg.params[0]}`);
});
};

View File

@@ -1,14 +0,0 @@
export default bot => {
bot._cmd.set("372", msg => { // motd_entry
bot.server.motd += `${msg.params[1]}\n`;
});
bot._cmd.set("375", msg => { // motd_start
bot.server.motd = `${msg.params[1]}\n`;
});
bot._cmd.set("376", msg => { // motd_end
bot.server.motd += `${msg.params[1]}\n`;
bot.emit("data", ["motd", bot.server.motd]);
});
};

16
src/clients/irc/motd.ts Normal file
View File

@@ -0,0 +1,16 @@
import { Bot, Message } from "../../types";
export default (bot: Bot) => {
bot._cmd.set("372", (msg: Message) => { // MOTD Entry
bot.server.motd += `${msg.params[1]}\n`;
});
bot._cmd.set("375", (msg: Message) => { // MOTD Start
bot.server.motd = `${msg.params[1]}\n`;
});
bot._cmd.set("376", (msg: Message) => { // MOTD End
bot.server.motd += `${msg.params[1]}\n`;
bot.emit("data", ["motd", bot.server.motd]);
});
};

View File

@@ -1,5 +1,7 @@
export default bot => {
bot._cmd.set("PRIVMSG", msg => { // privmsg
import { Bot, Message } from "../../types";
export default (bot: Bot) => {
bot._cmd.set("PRIVMSG", (msg: Message) => { // Handle PRIVMSG
if(msg.params[1] === "\u0001VERSION\u0001")
return bot.emit("data", ["ctcp:version", bot.reply(msg)]);
else if(msg.params[1].match(/^\u0001PING .*\u0001/i))
@@ -8,7 +10,7 @@ export default bot => {
bot.emit("data", ["message", bot.reply(msg)]);
});
bot._cmd.set("NOTICE", msg => { // notice
bot._cmd.set("NOTICE", (msg: Message) => { // Handle NOTICE
bot.emit("data", ["notice", msg.params[1]]);
});
};

View File

@@ -1,8 +0,0 @@
export default bot => {
bot._cmd.set("NICK", msg => { // nickchange
let prefix = bot.parsePrefix(msg.prefix);
if (bot.server.user.has(prefix.nick))
bot.server.user.delete(prefix.nick);
bot.whois(msg.params[0], true); // force
});
};

12
src/clients/irc/nick.ts Normal file
View File

@@ -0,0 +1,12 @@
import { Bot, Message, User } from "../../types";
export default (bot: Bot) => {
bot._cmd.set("NICK", (msg: Message) => { // Handle nick change
const prefix: User = bot.parsePrefix(msg.prefix);
if(bot.server.user.has(prefix.nick))
bot.server.user.delete(prefix.nick);
bot.whois(msg.params[0], true); // Force whois
});
};

View File

@@ -1,5 +0,0 @@
export default bot => {
bot._cmd.set("PART", msg => { // part
//delete this.server.user[msg.params[0]];
});
};

7
src/clients/irc/part.ts Normal file
View File

@@ -0,0 +1,7 @@
import { Bot, Message } from "../../types";
export default (bot: Bot) => {
bot._cmd.set("PART", (msg: Message) => { // Handle part
delete bot.server.user[msg.params[0]];
});
};

View File

@@ -1,5 +0,0 @@
export default bot => {
bot._cmd.set("PING", msg => { // ping
bot.send(`PONG ${msg.params.join``}`);
});
};

7
src/clients/irc/ping.ts Normal file
View File

@@ -0,0 +1,7 @@
import { Bot, Message } from "../../types";
export default (bot: Bot) => {
bot._cmd.set("PING", (msg: Message) => { // Handle PING
bot.send(`PONG ${msg.params.join('')}`);
});
};

View File

@@ -1,6 +0,0 @@
export default bot => {
bot._cmd.set("464", msg => { // motd_entry
if (bot.options.password.length > 0 && !bot.options.sasl)
bot.send(`PASS ${bot.options.password}`);
});
};

View File

@@ -0,0 +1,8 @@
import { Bot, Message } from "../../types";
export default (bot: Bot) => {
bot._cmd.set("464", (msg: Message) => { // Handle password request
if(bot.options.password.length > 0 && !bot.options.sasl)
bot.send(`PASS ${bot.options.password}`);
});
};

View File

@@ -1,6 +0,0 @@
export default bot => {
bot._cmd.set("001", msg => { // welcome
bot.join(bot.options.channels);
bot.emit("data", ["connected", msg.params[1]]);
});
};

View File

@@ -0,0 +1,8 @@
import { Bot, Message } from "../../types";
export default (bot: Bot) => {
bot._cmd.set("001", (msg: Message) => { // Handle welcome
bot.join(bot.options.channels);
bot.emit("data", ["connected", msg.params[1]]);
});
};

View File

@@ -1,20 +0,0 @@
const max = 400;
let whois = [];
let chan;
export default bot => {
bot._cmd.set("352", msg => { // who_entry
chan = msg.params[1];
whois.push(msg.params[5]);
});
bot._cmd.set("315", msg => { // who_end
bot.server.channel.set(chan, whois);
whois = [...new Set(whois)];
Array(Math.ceil(whois.length / 10)).fill().map(_ => whois.splice(0, 10)).forEach(l => {
//console.log(l);
bot.whois(l);
});
whois = [];
});
};

21
src/clients/irc/who.ts Normal file
View File

@@ -0,0 +1,21 @@
import { Bot, Message } from "../../types";
const max = 400;
let whois: string[] = [];
let chan: string;
export default (bot: Bot) => {
bot._cmd.set("352", (msg: Message) => { // Handle WHO entry
chan = msg.params[1];
whois.push(msg.params[5]);
});
bot._cmd.set("315", (msg: Message) => { // Handle WHO end
bot.server.channel.set(chan, whois);
whois = [...new Set(whois)];
Array(Math.ceil(whois.length / 10)).fill(undefined).map(() => whois.splice(0, 10)).forEach((l: string[]) => {
bot.whois(l);
});
whois = [];
});
};

View File

@@ -1,80 +0,0 @@
export default bot => {
bot._cmd.set("307", msg => { // whois_identified (ircd-hybrid)
let tmpuser = {};
if (bot.server.user.has(msg.params[1]))
tmpuser = bot.server.user.get(msg.params[1]);
tmpuser.account = msg.params[1];
tmpuser.registered = true;
bot.server.user.set(msg.params[1], tmpuser);
});
bot._cmd.set("311", msg => { // whois_userdata
let tmpuser = {};
if (bot.server.user.has(msg.params[1]))
tmpuser = bot.server.user.get(msg.params[1]);
tmpuser.nickname = msg.params[1];
tmpuser.username = msg.params[2];
tmpuser.hostname = msg.params[3];
tmpuser.realname = msg.params[5];
tmpuser.prefix = `${msg.params[1]}!${msg.params[2]}@${msg.params[3]}`;
bot.server.user.set(msg.params[1], tmpuser);
});
bot._cmd.set("313", msg => { // whois_oper
let tmpuser = {};
if (bot.server.user.has(msg.params[1]))
tmpuser = bot.server.user.get(msg.params[1]);
tmpuser.oper = true;
bot.server.user.set(msg.params[1], tmpuser);
});
bot._cmd.set("318", msg => { // whois_end
let tmpuser = {};
//bot.emit("data", ["info", `whois < ${msg.params[1]}`]);
if (bot.server.user.has(msg.params[1]))
tmpuser = bot.server.user.get(msg.params[1]);
tmpuser = {
nickname: tmpuser.nickname || false,
username: tmpuser.username || false,
hostname: tmpuser.hostname || false,
realname: tmpuser.realname || false,
account: tmpuser.account || false,
prefix: tmpuser.prefix || false,
registered: tmpuser.registered || false,
oper: tmpuser.oper || false,
channels: tmpuser.channels || [],
cached: ~~(Date.now() / 1000)
};
bot.server.user.set(msg.params[1], tmpuser);
if(msg.params[0] == msg.params[1]) {
bot.server.me = tmpuser;
bot.server.user.delete(msg.params[1]);
}
});
bot._cmd.set("319", msg => { // whois_chanlist
let tmpchan = new Map()
, tmpuser = {};
if (bot.server.user.has(msg.params[1])) {
tmpuser = bot.server.user.get(msg.params[1]);
if (tmpuser.channels)
tmpchan = new Map(tmpuser.channels);
}
let chans = msg.params[2].trim().split(" ");
for (let chan in chans) {
chan = chans[chan].split("#");
tmpchan.set(`#${chan[1]}`, chan[0]);
}
tmpuser.channels = tmpchan;
bot.server.user.set(msg.params[1], tmpuser);
});
bot._cmd.set("330", msg => { // whois_authed_as (snircd)
let tmpuser = {};
if (bot.server.user.has(msg.params[1]))
tmpuser = bot.server.user.get(msg.params[1]);
tmpuser.account = msg.params[2];
tmpuser.registered = true;
bot.server.user.set(msg.params[1], tmpuser);
});
};

69
src/clients/irc/whois.ts Normal file
View File

@@ -0,0 +1,69 @@
import { Bot, Message, User } from "../../types";
export default (bot: Bot) => {
bot._cmd.set("307", (msg: Message) => { // whois_identified (ircd-hybrid)
let tmpuser: User = bot.server.user.get(msg.params[1]) || {};
tmpuser.account = msg.params[1];
tmpuser.registered = true;
bot.server.user.set(msg.params[1], tmpuser);
});
bot._cmd.set("311", (msg: Message) => { // whois_userdata
let tmpuser: User = bot.server.user.get(msg.params[1]) || {};
tmpuser.nickname = msg.params[1];
tmpuser.username = msg.params[2];
tmpuser.hostname = msg.params[3];
tmpuser.realname = msg.params[5];
tmpuser.prefix = `${msg.params[1]}!${msg.params[2]}@${msg.params[3]}`;
bot.server.user.set(msg.params[1], tmpuser);
});
bot._cmd.set("313", (msg: Message) => { // whois_oper
let tmpuser: User = bot.server.user.get(msg.params[1]) || {};
tmpuser.oper = true;
bot.server.user.set(msg.params[1], tmpuser);
});
bot._cmd.set("318", (msg: Message) => { // whois_end
let tmpuser: User = bot.server.user.get(msg.params[1]) || {};
tmpuser = {
nick: tmpuser.nick || false,
nickname: tmpuser.nickname || false,
username: tmpuser.username || false,
hostname: tmpuser.hostname || false,
realname: tmpuser.realname || false,
account: tmpuser.account || false,
prefix: tmpuser.prefix || false,
registered: tmpuser.registered || false,
oper: tmpuser.oper || false,
channels: tmpuser.channels || [],
cached: Math.floor(Date.now() / 1000),
};
bot.server.user.set(msg.params[1], tmpuser);
if(msg.params[0] === msg.params[1]) {
bot.server.me = tmpuser;
bot.server.user.delete(msg.params[1]);
}
});
bot._cmd.set("319", (msg: Message) => { // whois_chanlist
let tmpchan = new Map<string, string>();
let tmpuser: User = bot.server.user.get(msg.params[1]) || {};
if(tmpuser.channels)
tmpchan = new Map(tmpuser.channels);
const chans = msg.params[2].trim().split(" ");
chans.forEach((chan) => {
const [flags, name] = chan.split("#");
tmpchan.set(`#${name}`, flags);
});
tmpuser.channels = tmpchan;
bot.server.user.set(msg.params[1], tmpuser);
});
bot._cmd.set("330", (msg: Message) => { // whois_authed_as (snircd)
let tmpuser: User = bot.server.user.get(msg.params[1]) || {};
tmpuser.account = msg.params[2];
tmpuser.registered = true;
bot.server.user.set(msg.params[1], tmpuser);
});
};