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

View File

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