moar trigger

This commit is contained in:
2017-11-21 16:07:02 +01:00
parent 1f7a16282e
commit 47a133e862
3 changed files with 157 additions and 66 deletions

View File

@ -53,6 +53,8 @@ class tg {
} }
format(msg) { format(msg) {
return ""+msg return ""+msg
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace(/\[b\](.*?)\[\/b\]/g, "<b>$1</b>") // bold .replace(/\[b\](.*?)\[\/b\]/g, "<b>$1</b>") // bold
.replace(/\[i\](.*?)\[\/i\]/g, "<i>$1</i>") // italic .replace(/\[i\](.*?)\[\/i\]/g, "<i>$1</i>") // italic
; ;

View File

@ -15,7 +15,8 @@ module.exports = bot => {
f: e => { f: e => {
const args = e.message.substring(3); const args = e.message.substring(3);
const context = { const context = {
e: e e: e,
t: bot._trigger
}; };
try { try {
let output = vm.runInNewContext(args, context); let output = vm.runInNewContext(args, context);
@ -32,79 +33,85 @@ module.exports = bot => {
} }
}); });
bot._trigger.set("sandbox_hs", { function sandbox(lang, code) {
call: /^\!hs (.*)/i, const langs = {
level: 100, cpp: {
active: true, "LanguageChoice": "7",
clients: ["irc", "tg"], "Program": "#include <iostream>\r\nint main() { " + code + "}",
f: e => { "Input": "",
const args = e.message.substring(4); "CompilerArgs": "-Wall -std=c++14 -O2 -o a.out source_file.cpp"
const params = querystring.stringify({ },
hs: {
"LanguageChoice": "11", "LanguageChoice": "11",
"Program": "main = " + args, "Program": "main = " + code,
"Input": "", "Input": "",
"CompilerArgs": "-o a.out source_file.hs" "CompilerArgs": "-o a.out source_file.hs"
}); },
const options = { py: {
hostname: "rextester.com", "LanguageChoice": "24",
port: 80, "Program": "print(" + code + ")",
path: "/rundotnet/api", "Input": "",
method: "POST", "CompilerArgs": "-o a.out source_file.hs"
headers: { },
"Content-Type": "application/x-www-form-urlencoded", bf: {
"Content-Length": Buffer.byteLength(params) "LanguageChoice": "44",
} "Program": code,
}; "Input": "",
"CompilerArgs": ""
const req = http.request(options, res => { },
let content = ""; php: {
res.setEncoding('utf8'); "LanguageChoice": "8",
res.on('data', chunk => content += chunk.toString()); "Program": "<?php\r\n" + code + "\r\n?>",
res.on('end', () => { "Input": "",
content = JSON.parse(content); "CompilerArgs": ""
e.reply(content.Errors ? content.Errors : (content.Result.length > maxoutput) ? `holy fuck, Ausgabe wäre viel zu lang! (${content.Result.length} Zeichen :DDDDDD)` : content.Result); },
}); lua: {
}); "LanguageChoice": "14",
req.write(params); "Program": code,
req.end(); "Input": "",
} "CompilerArgs": ""
}); }
};
bot._trigger.set("sandbox_py", { return new Promise((resolve, reject) => {
call: /^\!py (.*)/i, const options = {
url: "http://rextester.com/rundotnet/api",
method: "POST",
body: langs[lang],
json: true
};
request(options, (err, res, body) => {
if(err)
return reject("Error!");
if(body.Errors) {
if(body.Errors.length > maxoutput)
return reject(`holy fuck, Error wäre viel zu lang! (${body.Errors.length} Zeichen :DDDDDD)`)
return reject(body.Errors);
}
if(body.Result === null)
return reject("Keine Ausgabe :(");
if(body.Result.length > maxoutput)
return reject(`holy fuck, Ausgabe wäre viel zu lang! (${body.Result.length} Zeichen :DDDDDD)`);
resolve(body.Result);
});
});
}
bot._trigger.set("sandbox", {
call: /^\!(hs|py|cpp|bf|php|lua) .*/i,
level: 100, level: 100,
active: true, active: true,
clients: ["irc", "tg"], clients: ["irc", "tg"],
f: e => { f: e => {
const args = e.message.substring(4); let args = e.message.trim().substring(1).split(" ");
const params = querystring.stringify({ const lang = args.shift();
"LanguageChoice": "24", args = args.join(" ");
"Program": "print("+args+")",
"Input": "",
"CompilerArgs": ""
});
const options = {
hostname: "rextester.com",
port: 80,
path: "/rundotnet/api",
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Content-Length": Buffer.byteLength(params)
}
};
const req = http.request(options, res => { sandbox(lang, args).then(
let content = ""; resolve => e.reply(resolve),
res.setEncoding('utf8'); reject => e.reply(reject.replace("\n", " "))
res.on('data', chunk => content += chunk.toString()); );
res.on('end', () => {
content = JSON.parse(content);
e.reply(content.Errors ? content.Errors : (content.Result.length > maxoutput) ? `holy fuck, Ausgabe wäre viel zu lang! (${content.Result.length} Zeichen :DDDDDD)` : content.Result);
});
});
req.write(params);
req.end();
} }
}); });

View File

@ -5,7 +5,12 @@ const data = {
kill_templates: [], kill_templates: [],
kill_parts: {}, kill_parts: {},
abschieben: [], abschieben: [],
kaffee: [] kaffee: [],
quotes_firecooler: [],
quotes_kinski: [],
quotes_stoll: [],
quotes_boll: [],
genders: []
}; };
Object.keys(data).forEach(cur => { Object.keys(data).forEach(cur => {
@ -158,4 +163,81 @@ module.exports = bot => {
); );
} }
}); });
bot._trigger.set("fucken", {
call: /^(.|\/)fucken/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(`fuckt [b]${args[0]}[/b] und tötet [b]${args[0]}[/b] anschließend.`);
}
});
bot._trigger.set("hack", {
call: /^(.|\/)hack/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.reply(`hacking ${args[0]}...`);
}
});
bot._trigger.set("quotes", {
call: /^(.|\/)(boll|firecooler|kinski|stoll)$/i,
level: 0,
active: true,
clients: ["irc", "tg"],
f: e => {
let args = e.message.trim().substring(1);
e.reply(data[`quotes_${args}`][~~(Math.random() * data[`quotes_${args}`].length)]);
}
});
bot._trigger.set("spit", {
call: /^(.|\/)spit/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(`spits on [b]${args[0]}[/b] like a dirty whore.`);
}
});
bot._trigger.set("assume", {
call: /^(.|\/)assume/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.reply(`Assuming [b]${args[0]}'s[/b] gender... they're a ${data.genders[~~(Math.random() * data.genders.length)]}.`);
}
});
bot._trigger.set("wusel", {
call: /^(.|\/)wusel/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(`wuselt [b]${args[0]}[/b] über den Haufen.`);
}
});
}; };