This commit is contained in:
Flummi 2017-11-22 19:23:43 +01:00
parent e2bb64aa2c
commit ef947060d2
8 changed files with 4847 additions and 21 deletions

5
package-lock.json generated
View File

@ -2115,6 +2115,11 @@
"hashish": "0.0.4" "hashish": "0.0.4"
} }
}, },
"string-form-utils": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/string-form-utils/-/string-form-utils-0.1.0.tgz",
"integrity": "sha1-z/J9cobJCf7G8LicngouXl+mSNk="
},
"string_decoder": { "string_decoder": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",

View File

@ -15,6 +15,7 @@
"node-telegram-bot-api": "^0.29.0", "node-telegram-bot-api": "^0.29.0",
"nodejs-mysql": "^0.1.3", "nodejs-mysql": "^0.1.3",
"request": "^2.83.0", "request": "^2.83.0",
"string-form-utils": "^0.1.0",
"winston": "^2.4.0", "winston": "^2.4.0",
"xml2js": "^0.4.19", "xml2js": "^0.4.19",
"youtube-dl": "^1.12.2" "youtube-dl": "^1.12.2"

View File

@ -39,20 +39,22 @@ const write = (kat, key, value, type, cb) => {
if (type === "json") if (type === "json")
value = JSON.stringify(value); value = JSON.stringify(value);
self.sql.query("select * from `cfg` where `class` = ? && `key` = ? limit 1", [kat, key], (err, rows) => { console.log(kat, key, value, type);
sql.exec("select * from `cfg` where `class` = ? && `key` = ? limit 1", [kat, key], (err, rows) => {
console.log(rows);
if (rows.length > 0) { if (rows.length > 0) {
self.sql.query("update `cfg` set `value` = ? where `class` = ? && `key` = ?", [value, kat, key], (err) => { sql.exec("update `cfg` set `value` = ? where `class` = ? && `key` = ?", [value, kat, key], (err) => {
self.read(cfg => { console.log("updated", err);
self.cfg = cfg read().then(() => {
if (cb) cb(err); if(cb) cb();
}); });
}); });
} }
else { else {
self.sql.query("insert into `cfg` (`class`,`key`,`value`,`type`) values (?,?,?,?)", [kat, key, value, type], (err) => { sql.exec("insert into `cfg` (`class`,`key`,`value`,`type`) values (?,?,?,?)", [kat, key, value, type], (err) => {
self.read(cfg => { console.log("inserted", err);
self.cfg = cfg read().then(() => {
if (cb) cb(err); if (cb) cb();
}); });
}); });
} }

View File

@ -5,7 +5,7 @@ const _opts = {
showTypes: { type: "boolean", stdval: false }, showTypes: { type: "boolean", stdval: false },
showHidden: { type: "boolean", stdval: false } showHidden: { type: "boolean", stdval: false }
}; };
const _debug = true; const _debug = false;
module.exports = bot => { module.exports = bot => {
bot._trigger.set("cfg", { bot._trigger.set("cfg", {
@ -15,7 +15,8 @@ module.exports = bot => {
clients: ["irc"], clients: ["irc"],
f: e => { f: e => {
let args = e.message.substring(5); let args = e.message.substring(5);
let opts = {}; // clone let opts = {};
let value = null;
if (args.includes("{") && args.includes(":") && args.charAt(args.length - 1) === "}") { // check if options available if (args.includes("{") && args.includes(":") && args.charAt(args.length - 1) === "}") { // check if options available
try { try {
@ -33,11 +34,20 @@ module.exports = bot => {
if (typeof opts[_opt] !== _opts[_opt].type) if (typeof opts[_opt] !== _opts[_opt].type)
opts[_opt] = _opts[_opt].stdval; opts[_opt] = _opts[_opt].stdval;
if(_debug) e.reply(`opts: ${JSON.stringify(opts)}`); if(_debug)
e.reply(`opts: ${JSON.stringify(opts)}`);
args = args.trim().split(" "); args = args.trim().split(" ");
let mode = args.shift(); let mode = args.shift();
if (mode === "set" && e.message.includes("=")) { // get value if mode = set
args = args.join(" "); // omg
value = args.replace(/.*=(.*?)/, "$1").trim();
args = args.replace(/(.*?)=.*/, "$1").trim().split(" ");
e.reply(`value: ${value}, rest: ${args}`);
}
if (mode === "opts") // maybe replaced by switch in the future if (mode === "opts") // maybe replaced by switch in the future
return e.reply(`options: ${Object.keys(_opts).map(el => `[b]${el}[/b]: [i]${_opts[el].stdval} (${_opts[el].type})[/i]`).join(", ")}`) return e.reply(`options: ${Object.keys(_opts).map(el => `[b]${el}[/b]: [i]${_opts[el].stdval} (${_opts[el].type})[/i]`).join(", ")}`)
@ -58,11 +68,28 @@ module.exports = bot => {
return e.reply(`keys in class [b]${cfgstr[0]}[/b]: ${keys.public.length > 0 ? keys.public.map(el => `${el}${opts.showTypes ? ` [i](${cfg[cfgstr[0]][el].type})[/i]` : ""}`).join(", ") : "none"} (${keys.hidden.length} hidden)`); return e.reply(`keys in class [b]${cfgstr[0]}[/b]: ${keys.public.length > 0 ? keys.public.map(el => `${el}${opts.showTypes ? ` [i](${cfg[cfgstr[0]][el].type})[/i]` : ""}`).join(", ") : "none"} (${keys.hidden.length} hidden)`);
} }
if (!opts.showHidden) if(mode === "get") {
if (cfg[cfgstr[0]][cfgstr[1]].hidden || opts.showHidden) // catch hidden key if (!opts.showHidden)
return e.reply(`key [b]${cfgstr[1]}[/b] in class [b]${cfgstr[0]}[/b] is hidden, kek`); if (cfg[cfgstr[0]][cfgstr[1]].hidden || opts.showHidden) // catch hidden key
return e.reply(`key [b]${cfgstr[1]}[/b] in class [b]${cfgstr[0]}[/b] is hidden, kek`);
}
e.reply(cfg[cfgstr[0]][cfgstr[1]].val); switch (mode) {
case "get":
e.reply(cfg[cfgstr[0]][cfgstr[1]].val);
break;
case "set":
if (cfg[cfgstr[0]][cfgstr[1]].type === "json")
return e.reply("JSON isn't supported yet");
if(value === null)
return e.reply("Error");
write(cfgstr[0], cfgstr[1], value, cfg[cfgstr[0]][cfgstr[1]].type, () => {
e.reply(cfg[cfgstr[0]][cfgstr[1]].val);
})
break;
}
} }
}); });
}; };

View File

@ -1,6 +1,7 @@
const request = require("request"); const request = require("request")
, fs = require("fs");
const maxoutput = 400; const maxoutput = 500;
const hsimports = [ const hsimports = [
"Control.Applicative", "Control.Arrow", "Control.Monad", "Control.Applicative", "Control.Arrow", "Control.Monad",
@ -12,6 +13,7 @@ const hsimports = [
].map(imp => { return `import qualified ${imp}`; }).join("\r\n"); ].map(imp => { return `import qualified ${imp}`; }).join("\r\n");
function sandbox(lang, code) { function sandbox(lang, code) {
console.log(`${ __dirname }/../../../../neofetch`);
const langs = { const langs = {
cpp: { cpp: {
"LanguageChoice": "7", "LanguageChoice": "7",
@ -48,6 +50,18 @@ function sandbox(lang, code) {
"Program": code, "Program": code,
"Input": "", "Input": "",
"CompilerArgs": "" "CompilerArgs": ""
},
bash: {
"LanguageChoice": "38",
"Program": "#!/bin/bash\r\n" + code,
"Input": "",
"CompilerArgs": ""
},
neofetch: {
"LanguageChoice": "38",
"Program": fs.readFileSync(`${__dirname}/../../../../neofetch`, "utf8"),
"Input": "",
"CompilerArgs": ""
} }
}; };

View File

@ -31,7 +31,7 @@ module.exports = bot => {
}); });
bot._trigger.set("sandbox", { bot._trigger.set("sandbox", {
call: /^\!(hs|py|cpp|bf|php|lua) .*/i, call: /^\!(hs|py|cpp|bf|php|lua|bash) .*/i,
level: 100, level: 100,
active: true, active: true,
clients: ["irc", "tg"], clients: ["irc", "tg"],

View File

@ -1,11 +1,14 @@
import sql from "../sql.js"; import sql from "../sql.js";
const sfu = require("string-form-utils");
const data = { const data = {
yiff: [], yiff: [],
kill_templates: [], kill_templates: [],
kill_parts: {}, kill_parts: {},
genders: [], genders: [],
woahs: [] woahs: [],
slap: []
}; };
Object.keys(data).forEach(cur => { Object.keys(data).forEach(cur => {
@ -78,6 +81,7 @@ module.exports = bot => {
e.replyAction(data.yiff[~~(Math.random() * data.yiff.length)] e.replyAction(data.yiff[~~(Math.random() * data.yiff.length)]
.replace("{user}", `[b]${args[0]}[/b]`) .replace("{user}", `[b]${args[0]}[/b]`)
.replace("{yiffer}", `[b]${e.user.nick}[/b]`)
); );
} }
}); });
@ -204,7 +208,7 @@ module.exports = bot => {
bot._trigger.set("meme", { bot._trigger.set("meme", {
call: /^(.|\/)meme .*/i, call: /^(.|\/)meme .*/i,
level: 0, level: 0,
active: false, active: true,
clients: ["irc", "tg"], clients: ["irc", "tg"],
f: e => { f: e => {
const args = e.message.trim().substring(6).split("/"); const args = e.message.trim().substring(6).split("/");
@ -213,4 +217,30 @@ module.exports = bot => {
} }
}); });
bot._trigger.set("slap", {
call: /^(.|\/)slap/i,
level: 0,
active: true,
clients: ["irc", "tg"],
f: e => {
let args = e.message.trim().split(" ");
args.shift();
args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0];
e.replyAction(data.slap[~~(Math.random() * data.slap.length)]
.replace("{user}", `[b]${args[0]}[/b]`)
);
}
});
bot._trigger.set("fw", {
call: /^(.|\/)fw .*/i,
level: 0,
active: true,
clients: ["irc", "tg"],
f: e => {
const args = e.message.substring(4).trim();
e.reply(sfu.transformToFullwidth(args.toUpperCase()));
}
});
}; };

4747
src/neofetch Normal file

File diff suppressed because it is too large Load Diff