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

20
dist/clients/irc/cap.js vendored Normal file
View File

@ -0,0 +1,20 @@
export default (bot) => {
bot._cmd.set("CAP", (msg) => {
switch (msg.params[1]) {
case "LS":
bot.send(`CAP REQ :${msg.params[2]}`);
break;
case "ACK":
bot.send("AUTHENTICATE PLAIN");
break;
}
});
bot._cmd.set("AUTHENTICATE", (msg) => {
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) => {
bot.send("CAP END");
});
};

12
dist/clients/irc/invite.js vendored Normal file
View File

@ -0,0 +1,12 @@
export default (bot) => {
bot._cmd.set("INVITE", (msg) => {
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);
}
});
};

5
dist/clients/irc/join.js vendored Normal file
View File

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

12
dist/clients/irc/motd.js vendored Normal file
View File

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

13
dist/clients/irc/msg.js vendored Normal file
View File

@ -0,0 +1,13 @@
export default (bot) => {
bot._cmd.set("PRIVMSG", (msg) => {
if (msg.params[1] === "\u0001VERSION\u0001")
return bot.emit("data", ["ctcp:version", bot.reply(msg)]);
else if (msg.params[1].match(/^\u0001PING .*\u0001/i))
return bot.emit("data", ["ctcp:ping", bot.reply(msg)]);
else
bot.emit("data", ["message", bot.reply(msg)]);
});
bot._cmd.set("NOTICE", (msg) => {
bot.emit("data", ["notice", msg.params[1]]);
});
};

8
dist/clients/irc/nick.js vendored Normal file
View File

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

5
dist/clients/irc/part.js vendored Normal file
View File

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

5
dist/clients/irc/ping.js vendored Normal file
View File

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

6
dist/clients/irc/pwdreq.js vendored Normal file
View File

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

6
dist/clients/irc/welcome.js vendored Normal file
View File

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

17
dist/clients/irc/who.js vendored Normal file
View File

@ -0,0 +1,17 @@
const max = 400;
let whois = [];
let chan;
export default (bot) => {
bot._cmd.set("352", (msg) => {
chan = msg.params[1];
whois.push(msg.params[5]);
});
bot._cmd.set("315", (msg) => {
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) => {
bot.whois(l);
});
whois = [];
});
};

62
dist/clients/irc/whois.js vendored Normal file
View File

@ -0,0 +1,62 @@
export default (bot) => {
bot._cmd.set("307", (msg) => {
let 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) => {
let 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) => {
let tmpuser = bot.server.user.get(msg.params[1]) || {};
tmpuser.oper = true;
bot.server.user.set(msg.params[1], tmpuser);
});
bot._cmd.set("318", (msg) => {
let tmpuser = 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) => {
let tmpchan = new Map();
let tmpuser = 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) => {
let tmpuser = bot.server.user.get(msg.params[1]) || {};
tmpuser.account = msg.params[2];
tmpuser.registered = true;
bot.server.user.set(msg.params[1], tmpuser);
});
};