es6 native
This commit is contained in:
parent
f6f882586b
commit
6d5b33bed4
|
@ -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
|
11
package.json
11
package.json
|
@ -4,9 +4,7 @@
|
|||
"description": "Bot, kennste?",
|
||||
"main": "bot.js",
|
||||
"scripts": {
|
||||
"build": "./node_modules/.bin/babel src --presets=env --plugins=add-module-exports --out-dir dist",
|
||||
"debug": "npm run rmlog && npm run build && node --inspect=9229 dist/bot.js",
|
||||
"start": "npm run build && node dist/bot.js",
|
||||
"start": "npm run rmlog && node --experimental-modules src/bot.mjs",
|
||||
"rmlog": "rm logs/*.log || true"
|
||||
},
|
||||
"author": "Flummi & jkhsjdhjs",
|
||||
|
@ -18,13 +16,6 @@
|
|||
"request-promise": "^4.2.2",
|
||||
"stringify-object": "^3.2.1",
|
||||
"winston": "^2.4.0",
|
||||
"youtube-dl": "^1.12.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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { logger } from "./inc/log.js";
|
||||
import { read, cfg } from "./inc/cfg.js";
|
||||
import { wrapper } from "./inc/wrapper.js";
|
||||
const fs = require("fs");
|
||||
import { logger } from "./inc/log";
|
||||
import { read, cfg } from "./inc/cfg";
|
||||
import { wrapper } from "./inc/wrapper";
|
||||
import fs from "fs";
|
||||
|
||||
import triggers from "./inc/trigger/main";
|
||||
|
||||
read().then(() => {
|
||||
let bot = new wrapper();
|
||||
|
@ -11,11 +13,16 @@ read().then(() => {
|
|||
trigger: trigger
|
||||
};
|
||||
|
||||
fs.readdirSync(`${__dirname}/inc/trigger/`).forEach(file => {
|
||||
/*fs.readdirSync(`${__dirname}/inc/trigger/`).forEach(file => {
|
||||
if(file.substr(-3, 3) === ".js") {
|
||||
logger.info(`(main) loading trigger: ${file}`);
|
||||
require(`${__dirname}/inc/trigger/${file}`)(self);
|
||||
}
|
||||
});*/
|
||||
|
||||
triggers.forEach((mod, i) => {
|
||||
logger.info(`(main) loading trigger: ${i}`)
|
||||
mod(self);
|
||||
});
|
||||
|
||||
bot.on("message", e => { // Todo: eventhandler
|
|
@ -1,4 +1,4 @@
|
|||
import sql from "./sql.js";
|
||||
import sql from "./sql";
|
||||
|
||||
export let admins = [];
|
||||
export const loadAdmins = () => {
|
|
@ -1,4 +1,4 @@
|
|||
import sql from "./sql.js";
|
||||
import sql from "./sql";
|
||||
|
||||
let cfg = {
|
||||
client: {},
|
|
@ -1,5 +1,13 @@
|
|||
import { logger } from "../log.js";
|
||||
import { getLevel } from "../admin.js";
|
||||
import { logger } from "../log";
|
||||
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 = {
|
||||
red: "\x0304$1\x0304",
|
||||
|
@ -13,12 +21,6 @@ const replaceColor = (match, color, text) => {
|
|||
return text;
|
||||
};
|
||||
|
||||
const net = require("net")
|
||||
, tls = require("tls")
|
||||
, EventEmitter = require("events").EventEmitter
|
||||
, util = require("util")
|
||||
, fs = require("fs");
|
||||
|
||||
export class irc {
|
||||
constructor(options) {
|
||||
EventEmitter.call(this);
|
||||
|
@ -37,9 +39,8 @@ export class irc {
|
|||
this._recachetime = 60 * 30; // 30 minutes
|
||||
this._cmd = new Map();
|
||||
|
||||
fs.readdirSync(`${__dirname}/irc/`).forEach(file => {
|
||||
logger.debug(`(${this.network}) loading cmd: ${file}`);
|
||||
require(`${__dirname}/irc/${file}`)(this);
|
||||
modules.forEach(mod => {
|
||||
mod(this);
|
||||
});
|
||||
|
||||
this.server = {
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = client => {
|
||||
export default client => {
|
||||
client._cmd.set("CAP", function (msg) { // capkram
|
||||
switch (msg.params[1]) {
|
||||
case "LS": // list
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = client => {
|
||||
export default client => {
|
||||
client._cmd.set("INVITE", function (msg) { // invite
|
||||
const user = this.parsePrefix(msg.prefix);
|
||||
const channel = msg.params[1];
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = client => {
|
||||
export default client => {
|
||||
client._cmd.set("JOIN", function (msg) { // join
|
||||
this.send(`WHO ${msg.params[0]}`);
|
||||
}.bind(client));
|
19
src/inc/clients/irc/main.mjs
Normal file
19
src/inc/clients/irc/main.mjs
Normal 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
|
||||
];
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = client => {
|
||||
export default client => {
|
||||
client._cmd.set("372", function (msg) { // motd_entry
|
||||
this.server.motd += `${msg.params[1]}\n`;
|
||||
}.bind(client));
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = client => {
|
||||
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));
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = client => {
|
||||
export default client => {
|
||||
client._cmd.set("NICK", function (msg) { // nickchange
|
||||
let prefix = this.parsePrefix(msg.prefix);
|
||||
if (this.server.user.hasi(prefix.nick))
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = client => {
|
||||
export default client => {
|
||||
client._cmd.set("PART", function (msg) { // part
|
||||
//delete this.server.user[msg.params[0]];
|
||||
}.bind(client));
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = client => {
|
||||
export default client => {
|
||||
client._cmd.set("PING", function (msg) { // ping
|
||||
this.send(`PONG ${msg.params.join``}`);
|
||||
}.bind(client));
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = client => {
|
||||
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}`);
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = client => {
|
||||
export default client => {
|
||||
client._cmd.set("001", function (msg) { // welcome
|
||||
this.join(this.options.channels);
|
||||
this.emit("data", ["connected", msg.params[1]]);
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = client => {
|
||||
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();
|
|
@ -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)
|
||||
let tmpuser = {};
|
||||
if (this.server.user.hasi(msg.params[1]))
|
|
@ -1,9 +1,9 @@
|
|||
import { logger } from "../log.js";
|
||||
import { getLevel } from "../admin.js";
|
||||
import { spurdo } from "../spurdo.js";
|
||||
import { logger } from "../log.mjs";
|
||||
import { getLevel } from "../admin.mjs";
|
||||
import { spurdo } from "../spurdo.mjs";
|
||||
|
||||
const rp = require("request-promise")
|
||||
, EventEmitter = require("events").EventEmitter;
|
||||
import rp from "request-promise";
|
||||
import EventEmitter from "events";
|
||||
|
||||
export class tg extends EventEmitter {
|
||||
constructor(options) {
|
|
@ -1,20 +1,21 @@
|
|||
const winston = require("winston");
|
||||
//const winston = require("winston");
|
||||
import winston from "winston";
|
||||
|
||||
const logger = new (winston.Logger)({
|
||||
transports: [
|
||||
new (winston.transports.File)({
|
||||
name: "debug-file",
|
||||
filename: `${__dirname}/../../logs/${~~(Date.now() / 1000)}_debug.log`,
|
||||
filename: `./logs/${~~(Date.now() / 1000)}_debug.log`,
|
||||
level: "debug"
|
||||
}),
|
||||
new (winston.transports.File)({
|
||||
name: "info-file",
|
||||
filename: `${__dirname}/../../logs/${~~(Date.now() / 1000)}_info.log`,
|
||||
filename: `./logs/${~~(Date.now() / 1000)}_info.log`,
|
||||
level: "info"
|
||||
}),
|
||||
new (winston.transports.File)({
|
||||
name: "error-file",
|
||||
filename: `${__dirname}/../../logs/${~~(Date.now() / 1000)}_error.log`,
|
||||
filename: `./logs/${~~(Date.now() / 1000)}_error.log`,
|
||||
level: "error"
|
||||
}),
|
||||
new (winston.transports.Console)({
|
||||
|
@ -23,4 +24,4 @@ const logger = new (winston.Logger)({
|
|||
]
|
||||
});
|
||||
|
||||
export default { logger };
|
||||
export { logger };
|
|
@ -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
7
src/inc/sql.mjs
Normal 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;
|
|
@ -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 _opts = {
|
||||
|
@ -7,7 +7,7 @@ const _opts = {
|
|||
};
|
||||
const _debug = false;
|
||||
|
||||
module.exports = bot => {
|
||||
export default bot => {
|
||||
bot._trigger.set("cfg", new bot.trigger({
|
||||
call: /^\!cfg/i,
|
||||
level: 100,
|
|
@ -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 currencies = {
|
||||
|
@ -14,7 +14,7 @@ const markets = {
|
|||
xmr: "bitfinex"
|
||||
};
|
||||
|
||||
module.exports = bot => {
|
||||
export default bot => {
|
||||
bot._trigger.set("coins", new bot.trigger({
|
||||
call: /^(\.|\/)(btc|eth|xmr)/i,
|
||||
f: e => {
|
|
@ -1,7 +1,7 @@
|
|||
import sql from "../sql.js";
|
||||
import { getLevel, loadAdmins } from "../admin.js";
|
||||
import sql from "../sql";
|
||||
import { getLevel, loadAdmins } from "../admin";
|
||||
|
||||
module.exports = bot => {
|
||||
export default bot => {
|
||||
bot._trigger.set("join", new bot.trigger({
|
||||
call: /^\!join .*/i,
|
||||
level: 100,
|
|
@ -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 context = vm.createContext({
|
||||
|
@ -8,7 +8,7 @@ let context = vm.createContext({
|
|||
bot: null,
|
||||
admins: null,
|
||||
});
|
||||
module.exports = bot => {
|
||||
export default bot => {
|
||||
bot._trigger.set("sandbox_debug", new bot.trigger({
|
||||
call: /^\!debug (.*)/i,
|
||||
level: 100,
|
|
@ -1,4 +1,4 @@
|
|||
import sql from "../sql.js";
|
||||
import sql from "../sql";
|
||||
|
||||
const data = {
|
||||
dope_actions: {},
|
||||
|
@ -12,7 +12,7 @@ Object.keys(data).forEach(cur => {
|
|||
});
|
||||
});
|
||||
|
||||
module.exports = bot => {
|
||||
export default bot => {
|
||||
bot._trigger.set("dope", new bot.trigger({
|
||||
call: /^(\.|\/)dope/i,
|
||||
f: e => {
|
|
@ -1,8 +1,8 @@
|
|||
const rp = require("request-promise");
|
||||
import rp from "request-promise";
|
||||
|
||||
const feed = "https://www.kernel.org/releases.json";
|
||||
|
||||
module.exports = bot => {
|
||||
export default bot => {
|
||||
bot._trigger.set("kernel", new bot.trigger({
|
||||
call: /^(\.|\/)kernel/i,
|
||||
f: e => {
|
|
@ -1,5 +1,5 @@
|
|||
const rp = require("request-promise")
|
||||
, fs = require("fs");
|
||||
import rp from "request-promise";
|
||||
import fs from "fs";
|
||||
|
||||
const maxoutput = 500;
|
||||
|
22
src/inc/trigger/main.mjs
Normal file
22
src/inc/trigger/main.mjs
Normal 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
|
||||
];
|
|
@ -1,4 +1,4 @@
|
|||
import sql from "../sql.js";
|
||||
import sql from "../sql";
|
||||
|
||||
let _query_get = `
|
||||
select item,
|
||||
|
@ -12,7 +12,7 @@ let _query_add = `
|
|||
insert into mcmaniacs (item) values ($1) on conflict do nothing
|
||||
`;
|
||||
|
||||
module.exports = bot => {
|
||||
export default bot => {
|
||||
bot._trigger.set("mcmaniac_add", new bot.trigger({
|
||||
call: /Mc.*iaC/,
|
||||
active: true,
|
|
@ -1,5 +1,5 @@
|
|||
const fs = require("fs")
|
||||
, ytdl = require("ytdl-core");
|
||||
import fs from "fs";
|
||||
import ytdl from "ytdl-core";
|
||||
|
||||
const _args = [
|
||||
"--no-progress",
|
||||
|
@ -11,7 +11,7 @@ const _args = [
|
|||
];
|
||||
|
||||
|
||||
module.exports = bot => {
|
||||
export default bot => {
|
||||
bot._trigger.set("parser", new bot.trigger({
|
||||
call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi,
|
||||
active: false,
|
|
@ -1,4 +1,4 @@
|
|||
import sql from "../sql.js";
|
||||
import sql from "../sql";
|
||||
|
||||
let _query_get = `
|
||||
with ranked_quotes as (
|
||||
|
@ -22,7 +22,7 @@ insert into nxy_quotes
|
|||
($1, $2, $3, $4);
|
||||
`;
|
||||
|
||||
module.exports = bot => {
|
||||
export default bot => {
|
||||
bot._trigger.set("quotes", new bot.trigger({
|
||||
call: /^(\.|\/)q .*/i,
|
||||
active: true,
|
|
@ -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({
|
||||
call: /^(\.|\/)rape/i,
|
||||
f: e => {
|
|
@ -1,9 +1,9 @@
|
|||
import sql from "../sql.js";
|
||||
import { maxoutput, sandbox, bfgen } from "./lib/sandbox.js";
|
||||
import sql from "../sql";
|
||||
import { maxoutput, sandbox, bfgen } from "./lib/sandbox";
|
||||
|
||||
const vm = require("vm")
|
||||
, rp = require("request-promise")
|
||||
, stringify = require("stringify-object");
|
||||
import vm from "vm";
|
||||
import rp from "request-promise";
|
||||
import stringify from "stringify-object";
|
||||
|
||||
let _contexts = new Map();
|
||||
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);
|
||||
});
|
||||
|
||||
module.exports = bot => {
|
||||
export default bot => {
|
||||
bot._trigger.set("sandbox_js", new bot.trigger({
|
||||
call: /^\!js (.*)/i,
|
||||
f: e => {
|
|
@ -1,8 +1,8 @@
|
|||
const rp = require("request-promise");
|
||||
import rp from "request-promise";
|
||||
|
||||
const url = "https://api.urbandictionary.com/v0/define"
|
||||
|
||||
module.exports = bot => {
|
||||
export default bot => {
|
||||
bot._trigger.set("urbandict", new bot.trigger({
|
||||
call: /^(\.|\/)ud .*/i,
|
||||
f: e => {
|
|
@ -1,6 +1,5 @@
|
|||
import sql from "../sql.js";
|
||||
|
||||
const rp = require("request-promise");
|
||||
import sql from "../sql";
|
||||
import rp from "request-promise";
|
||||
|
||||
const data = {
|
||||
yiff: [],
|
||||
|
@ -21,7 +20,7 @@ Object.keys(data).forEach(cur => {
|
|||
});
|
||||
});
|
||||
|
||||
module.exports = bot => {
|
||||
export default bot => {
|
||||
bot._trigger.set("kiss", new bot.trigger({
|
||||
call: /^(\.|\/)kiss/i,
|
||||
f: e => {
|
|
@ -1,6 +1,7 @@
|
|||
import sql from "../sql.js";
|
||||
const rp = require("request-promise")
|
||||
, jsdom = require("jsdom").JSDOM;
|
||||
import sql from "../sql";
|
||||
|
||||
import rp from "request-promise";
|
||||
import JSDOM from "jsdom";
|
||||
|
||||
const data = {
|
||||
abschieben: [],
|
||||
|
@ -19,7 +20,7 @@ Object.keys(data).forEach(cur => {
|
|||
});
|
||||
});
|
||||
|
||||
module.exports = bot => {
|
||||
export default bot => {
|
||||
bot._trigger.set("abschieben", new bot.trigger({
|
||||
call: /^(\.|\/)abschieben/i,
|
||||
f: e => {
|
|
@ -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({
|
||||
call: /^\.wttr .*/i,
|
||||
clients: ["irc"],
|
|
@ -1,9 +1,10 @@
|
|||
import { cfg } from "./cfg.js";
|
||||
import { irc as irclib } from "./clients/irc.js";
|
||||
import { tg as tglib } from "./clients/tg.js";
|
||||
import { cfg } from "./cfg";
|
||||
import { irc as irclib } from "./clients/irc";
|
||||
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 wrapper = function () {
|
||||
|
@ -36,4 +37,4 @@ const wrapper = function () {
|
|||
};
|
||||
|
||||
util.inherits(wrapper, EventEmitter);
|
||||
export default { wrapper, clients };
|
||||
export { wrapper, clients };
|
Loading…
Reference in New Issue
Block a user