Chatbot overhaul
This commit is contained in:
51
src/inc/trigger/lib/cleverbot.mjs
Normal file
51
src/inc/trigger/lib/cleverbot.mjs
Normal file
@@ -0,0 +1,51 @@
|
||||
import rp from "request-promise";
|
||||
import { cfg } from "../../../inc/cfg";
|
||||
|
||||
class cleverbot {
|
||||
constructor() {
|
||||
this.api = "https://cleverbot.io/1.0";
|
||||
this.nick = "";
|
||||
setTimeout(()=>this.init(), 2000);
|
||||
}
|
||||
|
||||
init() {
|
||||
const options = {
|
||||
url: `${this.api}/create`,
|
||||
method: "POST",
|
||||
body: cfg.main.chatbot.val,
|
||||
json: true
|
||||
};
|
||||
rp(options)
|
||||
.then(res => {
|
||||
if(res.status === "success")
|
||||
this.nick = res.nick;
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
}
|
||||
|
||||
ask(msg) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const options = {
|
||||
url: `${this.api}/ask`,
|
||||
method: "POST",
|
||||
body: Object.assign(cfg.main.chatbot.val, {
|
||||
nick: this.nick,
|
||||
text: msg
|
||||
}),
|
||||
json: true
|
||||
};
|
||||
rp(options)
|
||||
.then(res => {
|
||||
if(res.status === "success")
|
||||
resolve(res);
|
||||
else
|
||||
reject(res.status);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default new cleverbot();
|
Reference in New Issue
Block a user