moved clients out of inc/

This commit is contained in:
Flummi
2017-12-04 13:12:02 +01:00
parent e7b8f0b456
commit cf2e1ae799
16 changed files with 7 additions and 9 deletions

21
src/clients/irc/cap.mjs Normal file
View File

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

View File

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

5
src/clients/irc/join.mjs Normal file
View File

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

19
src/clients/irc/main.mjs Normal file
View File

@ -0,0 +1,19 @@
import cap from "./cap";
import invite from "./invite";
import join from "./join";
import motd from "./motd";
import msg from "./msg";
import nick from "./nick";
import part from "./part";
import ping from "./ping";
import pwdreq from "./pwdreq";
import welcome from "./welcome";
import who from "./who";
import whois from "./whois";
export default [
cap, invite, join,
motd, msg, nick,
part, ping, pwdreq,
welcome, who, whois
];

14
src/clients/irc/motd.mjs Normal file
View File

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

9
src/clients/irc/msg.mjs Normal file
View File

@ -0,0 +1,9 @@
export default client => {
client._cmd.set("PRIVMSG", function (msg) { // privmsg
this.emit("data", msg.params[1] === "\u0001VERSION\u0001" ? ["ctcp:version", this.reply(msg)] : ["message", this.reply(msg)]);
}.bind(client));
client._cmd.set("NOTICE", function (msg) { // notice
this.emit("data", ["notice", msg.params[1]]);
}.bind(client));
};

8
src/clients/irc/nick.mjs Normal file
View File

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

5
src/clients/irc/part.mjs Normal file
View File

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

5
src/clients/irc/ping.mjs Normal file
View File

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

View File

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

View File

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

16
src/clients/irc/who.mjs Normal file
View File

@ -0,0 +1,16 @@
export default client => {
client._cmd.set("352", function (msg) { // who_entry
if (!this.server.channel[msg.params[1]])
this.server.channel[msg.params[1]] = new Map();
this.server.channel[msg.params[1]].set(msg.params[5], { // chan
nick: msg.params[5],
username: msg.params[2],
hostname: msg.params[3]
});
this.whois(msg.params[5]);
}.bind(client));
client._cmd.set("315", function (msg) { // who_end
//
}.bind(client));
};

95
src/clients/irc/whois.mjs Normal file
View File

@ -0,0 +1,95 @@
export default client => {
client._cmd.set("307", function (msg) { // whois_identified (ircd-hybrid)
let tmpuser = {};
if (this.server.user.hasi(msg.params[1]))
tmpuser = this.server.user.geti(msg.params[1]);
tmpuser.account = msg.params[1];
tmpuser.registered = true;
this.server.user.set(msg.params[1], tmpuser);
}.bind(client));
client._cmd.set("311", function (msg) { // whois_userdata
let tmpuser = {};
if (this.server.user.hasi(msg.params[1]))
tmpuser = this.server.user.geti(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]}`;
this.server.user.set(msg.params[1], tmpuser);
}.bind(client));
client._cmd.set("313", function (msg) { // whois_oper
let tmpuser = {};
if (this.server.user.hasi(msg.params[1]))
tmpuser = this.server.user.geti(msg.params[1]);
tmpuser.oper = true;
this.server.user.set(msg.params[1], tmpuser);
}.bind(client));
client._cmd.set("318", function (msg) { // whois_end
let tmpuser = {};
if (this.server.user.hasi(msg.params[1]))
tmpuser = this.server.user.geti(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)
};
if(msg.params[0] === msg.params[1])
this.server.me = tmpuser;
this.server.user.set(msg.params[1], tmpuser);
}.bind(client));
client._cmd.set("319", function (msg) { // whois_chanlist
let tmpchan = new Map()
, tmpuser = {};
if (this.server.user.hasi(msg.params[1])) {
tmpuser = this.server.user.geti(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;
this.server.user.set(msg.params[1], tmpuser);
}.bind(client));
client._cmd.set("330", function (msg) { // whois_authed_as (snircd)
let tmpuser = {};
if (this.server.user.hasi(msg.params[1]))
tmpuser = this.server.user.geti(msg.params[1]);
tmpuser.account = msg.params[2];
tmpuser.registered = true;
this.server.user.set(msg.params[1], tmpuser);
}.bind(client));
};
Map.prototype.hasi = function (val) {
for (let [key] of this)
if (key.toLowerCase() === val.toLowerCase())
return true;
return false;
};
Map.prototype.geti = function (val) {
for (let [key, value] of this)
if (key.toLowerCase() === val.toLowerCase())
return value;
return false;
};
Map.prototype.deli = function (val) {
for (let [key] of this)
if (key.toLowerCase() === val.toLowerCase())
this.delete(key);
};