tmp commit

This commit is contained in:
Flummi 2018-03-13 10:55:01 +01:00
parent 7e704f9dc2
commit b62a4c081c
4 changed files with 44 additions and 13 deletions

View File

@ -120,7 +120,8 @@ export class irc extends EventEmitter {
join: chan => this.join(chan),
part: (chan, msg) => this.part(chan, msg),
whois: user => this.whois(user),
write: msg => this.send(msg)
write: msg => this.send(msg),
socket: this.socket
};
}
join(channel) {

View File

@ -6,13 +6,15 @@ import rp from "request-promise";
import stringify from "stringify-object";
let _contexts = new Map();
sql.any("select data from useless where trigger = 'sandbox_js'")
/*sql.any("select data from useless where trigger = 'sandbox_js'")
.then(rows => {
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 => {
bot._trigger.set("sandbox_js", new bot.trigger({
@ -20,13 +22,13 @@ export default bot => {
set: "uwe",
f: e => {
const args = e.message.trim().substring(4);
if (!_contexts.has(`${e.network}.${e.channel}.${e.user.nick}`))
_contexts.set(`${e.network}.${e.channel}.${e.user.nick}`, vm.createContext({ }));
if (!_contexts.has(e.user.prefix))
_contexts.set(e.user.prefix, vm.createContext({ }));
if (args.match(/^reset$/)) {
_contexts.set(`${e.network}.${e.channel}.${e.user.nick}`, vm.createContext({ }));
_contexts.set(e.user.prefix, vm.createContext({ }));
return e.reply("Sandbox resetted!");
}
let context = vm.createContext(_contexts.get(`${e.network}.${e.channel}.${e.user.nick}`));
let context = vm.createContext(_contexts.get(e.user.prefix));
try {
let output = vm.runInContext(args, context, { timeout: 2000 });
if (typeof output !== undefined && output) {
@ -34,12 +36,18 @@ export default bot => {
if (output.length > maxoutput)
return e.reply(`holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)`);
else {
_contexts.set(`${e.network}.${e.channel}.${e.user.nick}`, context);
_contexts.set(e.user.prefix, context);
let tmp = JSON.stringify(stringify([..._contexts])
.replace(/\n/g, "")
.replace(/\t/g, "")
.split("[native code]").join(""));
sql.any("update useless set data = $1 where trigger = 'sandbox_js';", [tmp])
//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)", [
(e.type === "tg"?e.user.username || e.user.nick:e.user.nick),
tmp,
e.user.prefix
])
.then(() => {
e.reply(output);
})

View File

@ -204,7 +204,8 @@ export default bot => {
if(e.args.length > 0 && e.args[0].charAt(0) === "=") {
let tmp = e.args[0].slice(1);
sql.any(
`insert into nxy_users (nick, ${mode}) values (lower($1), $2) on conflict (nick) do update set ${mode} = excluded.${mode}`, [
`insert into nxy_users (prefix, nick, ${mode}) values ($1, lower($2), $3) on conflict (prefix) do update set ${mode} = excluded.${mode}, nick = $2`, [
e.user.prefix,
(e.type === "tg"?e.user.username || e.user.nick:e.user.nick),
tmp
])

View File

@ -355,4 +355,25 @@ export default bot => {
});
}
}));
bot._trigger.set("test", new bot.trigger({
call: /^\.version/i,
set: "uwe",
clients: ["irc"],
f: e => {
e.socket.once("data", res => {
let verstring;
try {
verstring = res.match(/\u0001VERSION (.*?)\u0001/)[1];
}
catch(err) {
verstring = false;
};
if(verstring)
e.reply(`${e.user.nick}: ${verstring}`);
});
e.write(`privmsg ${e.args[0] || e.user.nick} :\u0001VERSION\u0001`);
}
}));
};