sandbox fix

This commit is contained in:
Flummi 2018-03-13 13:12:18 +01:00
parent b62a4c081c
commit b236de177d

View File

@ -6,19 +6,13 @@ import rp from "request-promise";
import stringify from "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 prefix, sandbox from nxy_users where sandbox != 'NULL'")
.then(rows => { .then(rows => rows.forEach(row => eval(`_contexts.set(row.prefix, ${JSON.parse(row.sandbox)});`)))
eval("_contexts = new Map([..."+JSON.parse(rows[0].data)+"])"); .catch(err => console.log("nichts vorhanden lol", err));
}).catch(err => console.log("nichts vorhanden lol", err));*/
sql.any("select sandbox from nxy_users where sandbox != NULL")
.then(rows => {
eval("_contexts.set(rows[0].prefix, "+JSON.parse(rows[0].data)+");");
}).catch(err => console.log("nichts vorhanden lol", err));
export default 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,
set: "uwe", set: "uwe",
f: e => { f: e => {
const args = e.message.trim().substring(4); const args = e.message.trim().substring(4);
@ -37,23 +31,15 @@ export default bot => {
return e.reply(`holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)`); return e.reply(`holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)`);
else { else {
_contexts.set(e.user.prefix, context); _contexts.set(e.user.prefix, context);
let tmp = JSON.stringify(stringify([..._contexts]) let tmp = JSON.stringify(stringify(_contexts.get(e.user.prefix))
.replace(/\n/g, "") .replace(/\n/g, "")
.replace(/\t/g, "") .replace(/\t/g, "")
.split("[native code]").join("")); .split("[native code]").join(""));
//sql.any("update useless set data = $1 where trigger = 'sandbox_js';", [tmp])
//insert into nxy_users (nick, ${mode}) values (lower($1), $2) on conflict (nick) do update set ${mode} = excluded.${mode}
sql.any("insert into nxy_users (nick, prefix, sandbox) values (lower($1), $3, $2) on conflict (prefix) do update set sandbox = $2, nick = lower($1)", [ sql.any("insert into nxy_users (nick, prefix, sandbox) values (lower($1), $3, $2) on conflict (prefix) do update set sandbox = $2, nick = lower($1)", [
(e.type === "tg"?e.user.username || e.user.nick:e.user.nick), (e.type === "tg" ? e.user.username || e.user.nick:e.user.nick), tmp, e.user.prefix
tmp, ]).then(() => {
e.user.prefix e.reply(output);
]) }).catch(err => console.log(err));
.then(() => {
e.reply(output);
})
.catch(err => {
console.log(err);
});
} }
} }
} }