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