rp -> fetch (chatbot)
This commit is contained in:
		@@ -1,23 +1,23 @@
 | 
			
		||||
import rp from "request-promise-native";
 | 
			
		||||
import fetch from "../../fetch";
 | 
			
		||||
import { cfg } from "../../../inc/cfg";
 | 
			
		||||
 | 
			
		||||
class cleverbot {
 | 
			
		||||
  constructor() {
 | 
			
		||||
    this.api = "https://cleverbot.io/1.0";
 | 
			
		||||
    this.nick = "";
 | 
			
		||||
    setTimeout(()=>this.init(), 5000);
 | 
			
		||||
    setTimeout(() => this.init(), 5000);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  init() {
 | 
			
		||||
    const options = {
 | 
			
		||||
      url: `${this.api}/create`,
 | 
			
		||||
      method: "POST",
 | 
			
		||||
      body: Object.assign(cfg.main.chatbot.val, {
 | 
			
		||||
        nick: "uwibot"
 | 
			
		||||
      }),
 | 
			
		||||
      json: true
 | 
			
		||||
      body: {
 | 
			
		||||
        ...cfg.main.chatbot.val,
 | 
			
		||||
        ...{ nick: "uwibot" }
 | 
			
		||||
      }
 | 
			
		||||
    };
 | 
			
		||||
    rp(options)
 | 
			
		||||
    fetch(`${this.api}/create`, options)
 | 
			
		||||
      .then(res => res.json())
 | 
			
		||||
      .then(res => this.nick = res.status === "success" ? res.nick: "uwibot")
 | 
			
		||||
      .catch(err => console.log(err));
 | 
			
		||||
  }
 | 
			
		||||
@@ -25,15 +25,17 @@ class cleverbot {
 | 
			
		||||
  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
 | 
			
		||||
        body: {
 | 
			
		||||
          ...cfg.main.chatbot.val,
 | 
			
		||||
          ...{
 | 
			
		||||
            nick: this.nick,
 | 
			
		||||
            text: msg
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
      rp(options)
 | 
			
		||||
      fetch(`${this.api}/ask`, options)
 | 
			
		||||
        .then(res => res.json())
 | 
			
		||||
        .then(res => res.status === "success"?resolve(res):reject(res.status))
 | 
			
		||||
        .catch(err => reject(err));
 | 
			
		||||
    });
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user