Chatbot..

This commit is contained in:
Flummi 2017-12-05 16:44:26 +01:00
parent f371123c95
commit 16d07a5088
2 changed files with 44 additions and 31 deletions

View File

@ -1,49 +1,61 @@
import { cfg } from "../cfg";
import rp from "request-promise"; import rp from "request-promise";
import jsdom from "jsdom"; import jsdom from "jsdom";
let botcust2 = ""; let sessionid = "";
let api = "sprince/mrsprince"; //"fjosnir/hediko";
export default bot => { export default bot => {
bot._trigger.set("chatbot", new bot.trigger({ bot._trigger.set("chatbot", new bot.trigger({
call: /.*uwe.*/i, call: /.*uwe.*/i,
active: false, clients: ["tg"],
active: true,
f: e => { f: e => {
const chat = e.message; const chat = e.message
.replace(/uwe/gi, "")
.split("?")
.join("");
mitsuku(chat) mitsuku(chat)
.then(res => { .then(res => {
e.reply(res); e.reply(res.responses[0].replace(/mitsuku/gi, "Uwe"));
}) })
.catch(err => { .catch(err => {
console.log(err); e.reply("Darauf habe ich keine Antwort ;;");
console.log(err.message);
}); });
} }
})); }));
}; };
function mitsuku(msg) { const mitsuku = msg => new Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
const options = { const options = {
uri: "https://kakko.pandorabots.com/pandora/talk?botid=87437a824e345a0d&skin=chat", uri: `https://playground.pandorabots.com/talk/${api}?user_key=${cfg.main.chatbotkey.val}&sessionid=${sessionid}&input=${msg}&client_name=uwe`,
method: "POST", method: "POST",
body: { body: {
botcust2: botcust2, recent: true
message: msg
},
headers: {
Cookie: `botcust2=${botcust2}`
}, },
json: true json: true
}; };
rp(options) rp(options)
.then(res => resolve(res)) .then(res => {
console.log(res);
resolve(res);
})
.catch(err => reject(err)); .catch(err => reject(err));
}); });
}
(function init() { const init = () => {
rp("https://kakko.pandorabots.com/pandora/talk?botid=87437a824e345a0d&skin=chat") const options = {
uri: `https://playground.pandorabots.com/talk/${api}?user_key=${cfg.main.chatbotkey.val}&input=Hallo&client_name=uwe`,
method: "POST",
body: {
recent: true
},
json: true
};
rp(options)
.then(res => { .then(res => {
const dom = new jsdom.JSDOM(res); sessionid = res.sessionid;
botcust2 = dom.window.document.querySelector("input[name=botcust2]").value;
}); });
})(); };
setTimeout(()=>init(), 1000);

View File

@ -146,6 +146,7 @@ export default bot => {
bot._trigger.set("fraguwe", new bot.trigger({ bot._trigger.set("fraguwe", new bot.trigger({
call: /^uwe.*\?$/i, call: /^uwe.*\?$/i,
active: false,
f: e => { f: e => {
e.reply("fuck you"); e.reply("fuck you");
} }