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 { wrapper, clients } from './inc/wrapper.js';
const safeEval = require('safe-eval');
import { read } from "./inc/cfg.js";
import { wrapper, clients } from "./inc/wrapper.js";
const safeEval = require("safe-eval");
read().then(() => {
let bot = new wrapper();
bot.on('message', e => { // Todo: eventhandler
bot.on("message", e => { // Todo: eventhandler
let orig = e.message;
let tmp = orig.split(" ");
let cmd = tmp[0].toLowerCase();
tmp.shift();
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
args = e.message.substring(3);
@ -21,10 +20,10 @@ read().then(() => {
console: {
log: console.log
}
}
};
try {
var output = safeEval(args, context);
if (typeof output !== undefined && output !== 'undefined' && output) {
if (typeof output !== undefined && output !== "undefined" && output) {
let blah = JSON.stringify(output);
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);
@ -56,7 +55,7 @@ read().then(() => {
e.replyAction(`drischt mit einem großen Stück Butterkäse auf ${args[0]} ein.`);
}
});
bot.on('ctcp:version', e => {
e.write(`notice ${e.user.nick} :\u0001VERSION Pimmel 2.1\u0001`)
bot.on("ctcp:version", e => {
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 = {
client: {},
@ -15,18 +15,14 @@ const read = () => new Promise((resolve, reject) => {
for(let row in rows) {
cfg[rows[row].class][rows[row].key] = ((type, value) => {
switch(type) {
case 'string':
case "string":
return value;
break;
case 'int':
case "int":
return parseInt(value);
break;
case 'bool':
return value === 'true';
break;
case 'json':
case "bool":
return value === "true";
case "json":
return JSON.parse(value);
break;
}
})(rows[row].type, rows[row].value);
}

View File

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

View File

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