43 lines
1009 B
JavaScript
43 lines
1009 B
JavaScript
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(), 3000);
|
|
}
|
|
|
|
init() {
|
|
const options = {
|
|
url: `${this.api}/create`,
|
|
method: "POST",
|
|
body: Object.assign(cfg.main.chatbot.val, {
|
|
nick: "uwibot"
|
|
}),
|
|
json: true
|
|
};
|
|
rp(options)
|
|
.then(res => this.nick = res.status === "success" ? res.nick: "uwibot")
|
|
.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 => res.status === "success"?resolve(res):reject(res.status))
|
|
.catch(err => reject(err));
|
|
});
|
|
}
|
|
};
|
|
|
|
export default new cleverbot(); |