danke eslint

This commit is contained in:
Flummi 2017-11-18 11:53:58 +01:00
parent eca4671b0b
commit 10130e3b5c
7 changed files with 206 additions and 182 deletions

28
.eslintrc.json Normal file
View File

@ -0,0 +1,28 @@
{
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
]
}
}

View File

@ -1,16 +1,15 @@
import { cfg, read } from './inc/cfg.js'; import { read } from "./inc/cfg.js";
import { wrapper, clients } from './inc/wrapper.js'; import { wrapper, clients } from "./inc/wrapper.js";
const safeEval = require('safe-eval'); const safeEval = require("safe-eval");
read().then(() => { read().then(() => {
let bot = new wrapper(); let bot = new wrapper();
bot.on('message', e => { // Todo: eventhandler bot.on("message", e => { // Todo: eventhandler
let orig = e.message; let orig = e.message;
let tmp = orig.split(" "); let tmp = orig.split(" ");
let cmd = tmp[0].toLowerCase();
tmp.shift(); tmp.shift();
let args = tmp; let args = tmp;
args[0] = (args[0] == String.empty || typeof args[0] === 'undefined' || args[0] == "") ? e.user.nick : args[0]; args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0];
if (e.message.match(/^\.js /)) { // JS-Sandbox if (e.message.match(/^\.js /)) { // JS-Sandbox
args = e.message.substring(3); args = e.message.substring(3);
@ -21,10 +20,10 @@ read().then(() => {
console: { console: {
log: console.log log: console.log
} }
} };
try { try {
var output = safeEval(args, context); var output = safeEval(args, context);
if (typeof output !== undefined && output !== 'undefined' && output) { if (typeof output !== undefined && output !== "undefined" && output) {
let blah = JSON.stringify(output); let blah = JSON.stringify(output);
if (blah != "Converting circular structure to JSON") { if (blah != "Converting circular structure to JSON") {
e.reply(blah.length > 220 ? `holy fuck, Ausgabe wäre viel zu lang! (${blah.length} Zeichen :DDDDDD)` : blah); e.reply(blah.length > 220 ? `holy fuck, Ausgabe wäre viel zu lang! (${blah.length} Zeichen :DDDDDD)` : blah);
@ -56,7 +55,7 @@ read().then(() => {
e.replyAction(`drischt mit einem großen Stück Butterkäse auf ${args[0]} ein.`); e.replyAction(`drischt mit einem großen Stück Butterkäse auf ${args[0]} ein.`);
} }
}); });
bot.on('ctcp:version', e => { bot.on("ctcp:version", e => {
e.write(`notice ${e.user.nick} :\u0001VERSION Pimmel 2.1\u0001`) e.write(`notice ${e.user.nick} :\u0001VERSION Pimmel 2.1\u0001`);
}); });
}); });

View File

@ -1,4 +1,4 @@
import sql from './sql.js'; import sql from "./sql.js";
let cfg = { let cfg = {
client: {}, client: {},
@ -15,18 +15,14 @@ const read = () => new Promise((resolve, reject) => {
for(let row in rows) { for(let row in rows) {
cfg[rows[row].class][rows[row].key] = ((type, value) => { cfg[rows[row].class][rows[row].key] = ((type, value) => {
switch(type) { switch(type) {
case 'string': case "string":
return value; return value;
break; case "int":
case 'int':
return parseInt(value); return parseInt(value);
break; case "bool":
case 'bool': return value === "true";
return value === 'true'; case "json":
break;
case 'json':
return JSON.parse(value); return JSON.parse(value);
break;
} }
})(rows[row].type, rows[row].value); })(rows[row].type, rows[row].value);
} }

View File

@ -33,8 +33,8 @@ class irc {
this.send(`NICK ${this.nickname}`); this.send(`NICK ${this.nickname}`);
this.send(`USER ${this.username} 0 * : ${this.realname}`); this.send(`USER ${this.username} 0 * : ${this.realname}`);
}); });
this.socket.setEncoding('utf-8'); this.socket.setEncoding("utf-8");
this.socket.on('data', msg => { this.socket.on("data", msg => {
msg = this.parse(msg); msg = this.parse(msg);
let tmpuser = {}; let tmpuser = {};
switch (msg.command) { // auslagern! switch (msg.command) { // auslagern!
@ -111,7 +111,7 @@ class irc {
case "001": // welcome case "001": // welcome
this.server.me = msg.params[0]; this.server.me = msg.params[0];
this.join(this.options.channels); this.join(this.options.channels);
this.emit('data', ['connected', msg.params[1]]); this.emit("data", ["connected", msg.params[1]]);
break; break;
case "352": // who_entry case "352": // who_entry
if(!this.server.channel[msg.params[1]]) if(!this.server.channel[msg.params[1]])
@ -134,7 +134,7 @@ class irc {
break; break;
case "376": // motd_end case "376": // motd_end
this.server.motd += `${msg.params[1]}\n`; this.server.motd += `${msg.params[1]}\n`;
this.emit('data', ['motd', this.server.motd]); this.emit("data", ["motd", this.server.motd]);
break; break;
case "464": // Password required case "464": // Password required
if (this.options.password.length > 0) if (this.options.password.length > 0)
@ -154,12 +154,12 @@ class irc {
break; break;
case "PRIVMSG": case "PRIVMSG":
if (msg.params[1] === "\u0001VERSION\u0001") if (msg.params[1] === "\u0001VERSION\u0001")
this.emit('data', ['ctcp:version', this.reply(msg)]); this.emit("data", ["ctcp:version", this.reply(msg)]);
else else
this.emit('data', ['message', this.reply(msg)]); this.emit("data", ["message", this.reply(msg)]);
break; break;
case "NOTICE": case "NOTICE":
this.emit('data', ['notice', msg.params[1]]); this.emit("data", ["notice", msg.params[1]]);
break; break;
default: default:
console.log(msg); console.log(msg);
@ -170,30 +170,32 @@ class irc {
send() { send() {
for (let i = 0; i < arguments.length; i++) for (let i = 0; i < arguments.length; i++)
this.socket.write(arguments[i]); this.socket.write(arguments[i]);
this.socket.write('\n'); this.socket.write("\n");
} }
parse(data) { parse(data) {
var raw = data; let raw = data;
if (data.charAt(0) === ':') { let i = 0;
var i = data.indexOf(' '); let prefix = "";
var prefix = data.slice(1, i); if (data.charAt(0) === ":") {
i = data.indexOf(" ");
prefix = data.slice(1, i);
data = data.slice(i + 1); data = data.slice(i + 1);
} }
var i = data.indexOf(' '); i = data.indexOf(" ");
if (i === -1) if (i === -1)
i = data.length; i = data.length;
var command = data.slice(0, i); var command = data.slice(0, i);
data = data.slice(i + 1); data = data.slice(i + 1);
var params = []; var params = [];
while (data && data.charAt(0) !== ':') { while (data && data.charAt(0) !== ":") {
var i = data.indexOf(' '); i = data.indexOf(" ");
if (i === -1) if (i === -1)
i = data.length; i = data.length;
params.push(data.slice(0, i)); params.push(data.slice(0, i));
data = data.slice(i + 1); data = data.slice(i + 1);
} }
if (data) { if (data) {
data = data.replace(/\r?\n|\r/g, ''); data = data.replace(/\r?\n|\r/g, "");
params.push(data.slice(1)); params.push(data.slice(1));
} }
return { return {
@ -232,10 +234,10 @@ class irc {
}; };
} }
join(channel) { join(channel) {
this.send(`JOIN ${(typeof channel === "object") ? channel.join(',') : channel}`); this.send(`JOIN ${(typeof channel === "object") ? channel.join(",") : channel}`);
} }
part(channel, msg=false) { part(channel, msg=false) {
this.send(`PART ${(typeof channel === "object") ? channel.join(',') : channel}${msg ? " " + msg : " part"}`); this.send(`PART ${(typeof channel === "object") ? channel.join(",") : channel}${msg ? " " + msg : " part"}`);
} }
whois(user, force = false) { whois(user, force = false) {
user = user.toLowerCase(); user = user.toLowerCase();

View File

@ -1,4 +1,4 @@
let tgapi = require('node-telegram-bot-api'); let tgapi = require("node-telegram-bot-api");
let EventEmitter = require("events").EventEmitter; let EventEmitter = require("events").EventEmitter;
let util = require("util"); let util = require("util");
@ -10,11 +10,11 @@ class tg {
this.options.polling = options.polling || true; this.options.polling = options.polling || true;
this.client = new tgapi(this.options.token, this.options); this.client = new tgapi(this.options.token, this.options);
this.client.on('message', msg => { this.client.on("message", msg => {
if (msg.date >= (~~(Date.now() / 1000) - 10)) { if (msg.date >= (~~(Date.now() / 1000) - 10)) {
try { try {
msg.text = msg.text && msg.text.match(/^\//g) ? msg.text.replace(/^\//g, "\.") : msg.text; msg.text = msg.text && msg.text.match(/^\//g) ? msg.text.replace(/^\//g, ".") : msg.text;
this.emit('data', ['message', this.reply(msg)]); this.emit("data", ["message", this.reply(msg)]);
} }
catch(err) { catch(err) {
console.log(err); console.log(err);

View File

@ -1,4 +1,4 @@
import mysql from 'nodejs-mysql'; import mysql from "nodejs-mysql";
const sql = mysql.getInstance( require(`${__dirname}/../../cfg/mysql.json`) ); const sql = mysql.getInstance( require(`${__dirname}/../../cfg/mysql.json`) );
export default sql; export default sql;

View File

@ -1,11 +1,10 @@
import { cfg, read } from './cfg.js'; import { cfg } from "./cfg.js";
//import { loadEvents } from './lib.js';
const irclib = require('./clients/irc.js'); const irclib = require("./clients/irc.js");
const tglib = require('./clients/tg.js') const tglib = require("./clients/tg.js");
const util = require('util'); const util = require("util");
const EventEmitter = require('events').EventEmitter; const EventEmitter = require("events").EventEmitter;
const clients = []; const clients = [];
const wrapper = function () { const wrapper = function () {