es6 native

This commit is contained in:
Flummi 2017-12-04 12:22:53 +01:00
parent f6f882586b
commit 6d5b33bed4
42 changed files with 149 additions and 131 deletions

View File

@ -1,27 +0,0 @@
image: node:latest
stages:
- build
- babel
cache:
paths:
- node_modules/
- dist/
install_dependencies:
stage: build
script:
- npm install
artifacts:
paths:
- node_modules/
expire_in: 1 hour
babel_compile:
stage: babel
script: npm run build
artifacts:
paths:
- dist/
expire_in: 1 week

View File

@ -4,9 +4,7 @@
"description": "Bot, kennste?", "description": "Bot, kennste?",
"main": "bot.js", "main": "bot.js",
"scripts": { "scripts": {
"build": "./node_modules/.bin/babel src --presets=env --plugins=add-module-exports --out-dir dist", "start": "npm run rmlog && node --experimental-modules src/bot.mjs",
"debug": "npm run rmlog && npm run build && node --inspect=9229 dist/bot.js",
"start": "npm run build && node dist/bot.js",
"rmlog": "rm logs/*.log || true" "rmlog": "rm logs/*.log || true"
}, },
"author": "Flummi & jkhsjdhjs", "author": "Flummi & jkhsjdhjs",
@ -18,13 +16,6 @@
"request-promise": "^4.2.2", "request-promise": "^4.2.2",
"stringify-object": "^3.2.1", "stringify-object": "^3.2.1",
"winston": "^2.4.0", "winston": "^2.4.0",
"youtube-dl": "^1.12.2",
"ytdl-core": "^0.18.2" "ytdl-core": "^0.18.2"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-env": "^1.6.1"
} }
} }

View File

@ -1,7 +1,9 @@
import { logger } from "./inc/log.js"; import { logger } from "./inc/log";
import { read, cfg } from "./inc/cfg.js"; import { read, cfg } from "./inc/cfg";
import { wrapper } from "./inc/wrapper.js"; import { wrapper } from "./inc/wrapper";
const fs = require("fs"); import fs from "fs";
import triggers from "./inc/trigger/main";
read().then(() => { read().then(() => {
let bot = new wrapper(); let bot = new wrapper();
@ -11,11 +13,16 @@ read().then(() => {
trigger: trigger trigger: trigger
}; };
fs.readdirSync(`${__dirname}/inc/trigger/`).forEach(file => { /*fs.readdirSync(`${__dirname}/inc/trigger/`).forEach(file => {
if(file.substr(-3, 3) === ".js") { if(file.substr(-3, 3) === ".js") {
logger.info(`(main) loading trigger: ${file}`); logger.info(`(main) loading trigger: ${file}`);
require(`${__dirname}/inc/trigger/${file}`)(self); require(`${__dirname}/inc/trigger/${file}`)(self);
} }
});*/
triggers.forEach((mod, i) => {
logger.info(`(main) loading trigger: ${i}`)
mod(self);
}); });
bot.on("message", e => { // Todo: eventhandler bot.on("message", e => { // Todo: eventhandler

View File

@ -1,4 +1,4 @@
import sql from "./sql.js"; import sql from "./sql";
export let admins = []; export let admins = [];
export const loadAdmins = () => { export const loadAdmins = () => {

View File

@ -1,4 +1,4 @@
import sql from "./sql.js"; import sql from "./sql";
let cfg = { let cfg = {
client: {}, client: {},

View File

@ -1,5 +1,13 @@
import { logger } from "../log.js"; import { logger } from "../log";
import { getLevel } from "../admin.js"; import { getLevel } from "../admin";
import modules from "./irc/main";
import net from "net";
import tls from "tls";
import EventEmitter from "events";
import util from "util";
import fs from "fs";
const colors = { const colors = {
red: "\x0304$1\x0304", red: "\x0304$1\x0304",
@ -13,12 +21,6 @@ const replaceColor = (match, color, text) => {
return text; return text;
}; };
const net = require("net")
, tls = require("tls")
, EventEmitter = require("events").EventEmitter
, util = require("util")
, fs = require("fs");
export class irc { export class irc {
constructor(options) { constructor(options) {
EventEmitter.call(this); EventEmitter.call(this);
@ -37,9 +39,8 @@ export class irc {
this._recachetime = 60 * 30; // 30 minutes this._recachetime = 60 * 30; // 30 minutes
this._cmd = new Map(); this._cmd = new Map();
fs.readdirSync(`${__dirname}/irc/`).forEach(file => { modules.forEach(mod => {
logger.debug(`(${this.network}) loading cmd: ${file}`); mod(this);
require(`${__dirname}/irc/${file}`)(this);
}); });
this.server = { this.server = {

View File

@ -1,4 +1,4 @@
module.exports = client => { export default client => {
client._cmd.set("CAP", function (msg) { // capkram client._cmd.set("CAP", function (msg) { // capkram
switch (msg.params[1]) { switch (msg.params[1]) {
case "LS": // list case "LS": // list

View File

@ -1,4 +1,4 @@
module.exports = client => { export default client => {
client._cmd.set("INVITE", function (msg) { // invite client._cmd.set("INVITE", function (msg) { // invite
const user = this.parsePrefix(msg.prefix); const user = this.parsePrefix(msg.prefix);
const channel = msg.params[1]; const channel = msg.params[1];

View File

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

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
];

View File

@ -1,4 +1,4 @@
module.exports = client => { export default client => {
client._cmd.set("372", function (msg) { // motd_entry client._cmd.set("372", function (msg) { // motd_entry
this.server.motd += `${msg.params[1]}\n`; this.server.motd += `${msg.params[1]}\n`;
}.bind(client)); }.bind(client));

View File

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

View File

@ -1,4 +1,4 @@
module.exports = client => { export default client => {
client._cmd.set("NICK", function (msg) { // nickchange client._cmd.set("NICK", function (msg) { // nickchange
let prefix = this.parsePrefix(msg.prefix); let prefix = this.parsePrefix(msg.prefix);
if (this.server.user.hasi(prefix.nick)) if (this.server.user.hasi(prefix.nick))

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
module.exports = client => { export default client => {
client._cmd.set("352", function (msg) { // who_entry client._cmd.set("352", function (msg) { // who_entry
if (!this.server.channel[msg.params[1]]) if (!this.server.channel[msg.params[1]])
this.server.channel[msg.params[1]] = new Map(); this.server.channel[msg.params[1]] = new Map();

View File

@ -1,6 +1,6 @@
import { getLevel } from "../../admin.js"; import { getLevel } from "../../admin";
module.exports = client => { export default client => {
client._cmd.set("307", function (msg) { // whois_identified (ircd-hybrid) client._cmd.set("307", function (msg) { // whois_identified (ircd-hybrid)
let tmpuser = {}; let tmpuser = {};
if (this.server.user.hasi(msg.params[1])) if (this.server.user.hasi(msg.params[1]))

View File

@ -1,9 +1,9 @@
import { logger } from "../log.js"; import { logger } from "../log.mjs";
import { getLevel } from "../admin.js"; import { getLevel } from "../admin.mjs";
import { spurdo } from "../spurdo.js"; import { spurdo } from "../spurdo.mjs";
const rp = require("request-promise") import rp from "request-promise";
, EventEmitter = require("events").EventEmitter; import EventEmitter from "events";
export class tg extends EventEmitter { export class tg extends EventEmitter {
constructor(options) { constructor(options) {

View File

@ -1,20 +1,21 @@
const winston = require("winston"); //const winston = require("winston");
import winston from "winston";
const logger = new (winston.Logger)({ const logger = new (winston.Logger)({
transports: [ transports: [
new (winston.transports.File)({ new (winston.transports.File)({
name: "debug-file", name: "debug-file",
filename: `${__dirname}/../../logs/${~~(Date.now() / 1000)}_debug.log`, filename: `./logs/${~~(Date.now() / 1000)}_debug.log`,
level: "debug" level: "debug"
}), }),
new (winston.transports.File)({ new (winston.transports.File)({
name: "info-file", name: "info-file",
filename: `${__dirname}/../../logs/${~~(Date.now() / 1000)}_info.log`, filename: `./logs/${~~(Date.now() / 1000)}_info.log`,
level: "info" level: "info"
}), }),
new (winston.transports.File)({ new (winston.transports.File)({
name: "error-file", name: "error-file",
filename: `${__dirname}/../../logs/${~~(Date.now() / 1000)}_error.log`, filename: `./logs/${~~(Date.now() / 1000)}_error.log`,
level: "error" level: "error"
}), }),
new (winston.transports.Console)({ new (winston.transports.Console)({
@ -23,4 +24,4 @@ const logger = new (winston.Logger)({
] ]
}); });
export default { logger }; export { logger };

View File

@ -1,4 +0,0 @@
const pgp = require("pg-promise")();
const sql = pgp(require(`${__dirname}/../../cfg/sql.json`));
//const sql = mysql.getInstance( require(`${__dirname}/../../cfg/mysql.json`) );
export default sql;

7
src/inc/sql.mjs Normal file
View File

@ -0,0 +1,7 @@
import PG from "pg-promise";
import { default as cfg } from "../../cfg/sql.json";
//const pgp = new PG();
const sql = (new PG())(cfg);
export default sql;

View File

@ -1,4 +1,4 @@
import { read, write, cfg } from "../cfg.js"; import { read, write, cfg } from "../cfg";
const _modes = ["get", "set", "rm", "add", "opts"]; const _modes = ["get", "set", "rm", "add", "opts"];
const _opts = { const _opts = {
@ -7,7 +7,7 @@ const _opts = {
}; };
const _debug = false; const _debug = false;
module.exports = bot => { export default bot => {
bot._trigger.set("cfg", new bot.trigger({ bot._trigger.set("cfg", new bot.trigger({
call: /^\!cfg/i, call: /^\!cfg/i,
level: 100, level: 100,

View File

@ -1,4 +1,4 @@
const rp = require("request-promise"); import rp from "request-promise";
const api_url = ({ market, crypto, currency }) => `https://api.cryptowat.ch/markets/${market}/${crypto}${currency}/summary`; const api_url = ({ market, crypto, currency }) => `https://api.cryptowat.ch/markets/${market}/${crypto}${currency}/summary`;
const currencies = { const currencies = {
@ -14,7 +14,7 @@ const markets = {
xmr: "bitfinex" xmr: "bitfinex"
}; };
module.exports = bot => { export default bot => {
bot._trigger.set("coins", new bot.trigger({ bot._trigger.set("coins", new bot.trigger({
call: /^(\.|\/)(btc|eth|xmr)/i, call: /^(\.|\/)(btc|eth|xmr)/i,
f: e => { f: e => {

View File

@ -1,7 +1,7 @@
import sql from "../sql.js"; import sql from "../sql";
import { getLevel, loadAdmins } from "../admin.js"; import { getLevel, loadAdmins } from "../admin";
module.exports = bot => { export default bot => {
bot._trigger.set("join", new bot.trigger({ bot._trigger.set("join", new bot.trigger({
call: /^\!join .*/i, call: /^\!join .*/i,
level: 100, level: 100,

View File

@ -1,6 +1,6 @@
import { admins, getLevel } from "../admin.js"; import { admins, getLevel } from "../admin";
const vm = require("vm"); import vm from "vm";
let maxoutput = 750; let maxoutput = 750;
let context = vm.createContext({ let context = vm.createContext({
@ -8,7 +8,7 @@ let context = vm.createContext({
bot: null, bot: null,
admins: null, admins: null,
}); });
module.exports = bot => { export default bot => {
bot._trigger.set("sandbox_debug", new bot.trigger({ bot._trigger.set("sandbox_debug", new bot.trigger({
call: /^\!debug (.*)/i, call: /^\!debug (.*)/i,
level: 100, level: 100,

View File

@ -1,4 +1,4 @@
import sql from "../sql.js"; import sql from "../sql";
const data = { const data = {
dope_actions: {}, dope_actions: {},
@ -12,7 +12,7 @@ Object.keys(data).forEach(cur => {
}); });
}); });
module.exports = bot => { export default bot => {
bot._trigger.set("dope", new bot.trigger({ bot._trigger.set("dope", new bot.trigger({
call: /^(\.|\/)dope/i, call: /^(\.|\/)dope/i,
f: e => { f: e => {

View File

@ -1,8 +1,8 @@
const rp = require("request-promise"); import rp from "request-promise";
const feed = "https://www.kernel.org/releases.json"; const feed = "https://www.kernel.org/releases.json";
module.exports = bot => { export default bot => {
bot._trigger.set("kernel", new bot.trigger({ bot._trigger.set("kernel", new bot.trigger({
call: /^(\.|\/)kernel/i, call: /^(\.|\/)kernel/i,
f: e => { f: e => {

View File

@ -1,5 +1,5 @@
const rp = require("request-promise") import rp from "request-promise";
, fs = require("fs"); import fs from "fs";
const maxoutput = 500; const maxoutput = 500;

22
src/inc/trigger/main.mjs Normal file
View File

@ -0,0 +1,22 @@
import cfg from "./cfg";
import coins from "./coins";
import core from "./core";
import debug from "./debug";
import drugs from "./drugs";
import kernel from "./kernel";
import mcmaniac from "./mcmaniac";
import parser from "./parser";
import quotes from "./quotes";
import rape from "./rape";
import sandbox from "./sandbox";
import urban from "./urban";
import nxy from "./useless_nxy";
import uwe from "./useless_uwe";
import wttr from "./wttr";
export default [
cfg, coins, core, debug,
drugs, kernel, mcmaniac,
parser, quotes, rape, sandbox,
urban, nxy, uwe, wttr
];

View File

@ -1,4 +1,4 @@
import sql from "../sql.js"; import sql from "../sql";
let _query_get = ` let _query_get = `
select item, select item,
@ -12,7 +12,7 @@ let _query_add = `
insert into mcmaniacs (item) values ($1) on conflict do nothing insert into mcmaniacs (item) values ($1) on conflict do nothing
`; `;
module.exports = bot => { export default bot => {
bot._trigger.set("mcmaniac_add", new bot.trigger({ bot._trigger.set("mcmaniac_add", new bot.trigger({
call: /Mc.*iaC/, call: /Mc.*iaC/,
active: true, active: true,

View File

@ -1,5 +1,5 @@
const fs = require("fs") import fs from "fs";
, ytdl = require("ytdl-core"); import ytdl from "ytdl-core";
const _args = [ const _args = [
"--no-progress", "--no-progress",
@ -11,7 +11,7 @@ const _args = [
]; ];
module.exports = bot => { export default bot => {
bot._trigger.set("parser", new bot.trigger({ bot._trigger.set("parser", new bot.trigger({
call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi, call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi,
active: false, active: false,

View File

@ -1,4 +1,4 @@
import sql from "../sql.js"; import sql from "../sql";
let _query_get = ` let _query_get = `
with ranked_quotes as ( with ranked_quotes as (
@ -22,7 +22,7 @@ insert into nxy_quotes
($1, $2, $3, $4); ($1, $2, $3, $4);
`; `;
module.exports = bot => { export default bot => {
bot._trigger.set("quotes", new bot.trigger({ bot._trigger.set("quotes", new bot.trigger({
call: /^(\.|\/)q .*/i, call: /^(\.|\/)q .*/i,
active: true, active: true,

View File

@ -1,6 +1,6 @@
import sql from "../sql.js"; import sql from "../sql";
module.exports = bot => { export default bot => {
bot._trigger.set("rape", new bot.trigger({ bot._trigger.set("rape", new bot.trigger({
call: /^(\.|\/)rape/i, call: /^(\.|\/)rape/i,
f: e => { f: e => {

View File

@ -1,9 +1,9 @@
import sql from "../sql.js"; import sql from "../sql";
import { maxoutput, sandbox, bfgen } from "./lib/sandbox.js"; import { maxoutput, sandbox, bfgen } from "./lib/sandbox";
const vm = require("vm") import vm from "vm";
, rp = require("request-promise") import rp from "request-promise";
, stringify = require("stringify-object"); import stringify from "stringify-object";
let _contexts = new Map(); let _contexts = new Map();
sql.any("select data from useless where trigger = 'sandbox_js'") sql.any("select data from useless where trigger = 'sandbox_js'")
@ -14,7 +14,7 @@ sql.any("select data from useless where trigger = 'sandbox_js'")
console.log("nichts vorhanden lol", err); console.log("nichts vorhanden lol", err);
}); });
module.exports = bot => { export default bot => {
bot._trigger.set("sandbox_js", new bot.trigger({ bot._trigger.set("sandbox_js", new bot.trigger({
call: /^\!js (.*)/i, call: /^\!js (.*)/i,
f: e => { f: e => {

View File

@ -1,8 +1,8 @@
const rp = require("request-promise"); import rp from "request-promise";
const url = "https://api.urbandictionary.com/v0/define" const url = "https://api.urbandictionary.com/v0/define"
module.exports = bot => { export default bot => {
bot._trigger.set("urbandict", new bot.trigger({ bot._trigger.set("urbandict", new bot.trigger({
call: /^(\.|\/)ud .*/i, call: /^(\.|\/)ud .*/i,
f: e => { f: e => {

View File

@ -1,6 +1,5 @@
import sql from "../sql.js"; import sql from "../sql";
import rp from "request-promise";
const rp = require("request-promise");
const data = { const data = {
yiff: [], yiff: [],
@ -21,7 +20,7 @@ Object.keys(data).forEach(cur => {
}); });
}); });
module.exports = bot => { export default bot => {
bot._trigger.set("kiss", new bot.trigger({ bot._trigger.set("kiss", new bot.trigger({
call: /^(\.|\/)kiss/i, call: /^(\.|\/)kiss/i,
f: e => { f: e => {

View File

@ -1,6 +1,7 @@
import sql from "../sql.js"; import sql from "../sql";
const rp = require("request-promise")
, jsdom = require("jsdom").JSDOM; import rp from "request-promise";
import JSDOM from "jsdom";
const data = { const data = {
abschieben: [], abschieben: [],
@ -19,7 +20,7 @@ Object.keys(data).forEach(cur => {
}); });
}); });
module.exports = bot => { export default bot => {
bot._trigger.set("abschieben", new bot.trigger({ bot._trigger.set("abschieben", new bot.trigger({
call: /^(\.|\/)abschieben/i, call: /^(\.|\/)abschieben/i,
f: e => { f: e => {

View File

@ -1,6 +1,6 @@
const rp = require("request-promise"); import rp from "request-promise";
module.exports = bot => { export default bot => {
bot._trigger.set("wttr", new bot.trigger({ bot._trigger.set("wttr", new bot.trigger({
call: /^\.wttr .*/i, call: /^\.wttr .*/i,
clients: ["irc"], clients: ["irc"],

View File

@ -1,9 +1,10 @@
import { cfg } from "./cfg.js"; import { cfg } from "./cfg";
import { irc as irclib } from "./clients/irc.js"; import { irc as irclib } from "./clients/irc";
import { tg as tglib } from "./clients/tg.js"; import { tg as tglib } from "./clients/tg";
import util from "util";
import EventEmitter from "events";
const util = require("util");
const EventEmitter = require("events").EventEmitter;
const clients = []; const clients = [];
const wrapper = function () { const wrapper = function () {
@ -36,4 +37,4 @@ const wrapper = function () {
}; };
util.inherits(wrapper, EventEmitter); util.inherits(wrapper, EventEmitter);
export default { wrapper, clients }; export { wrapper, clients };