rp -> fetch

This commit is contained in:
Flummi 2018-09-14 21:30:13 +02:00
parent 5ba5ff0afb
commit 6624995377

View File

@ -1,4 +1,4 @@
import rp from "request-promise-native";
import fetch from "../fetch";
import url from "url";
const apis = {
@ -24,20 +24,21 @@ export default bot => {
f: e => {
const link = "https://" + e.message.match(regex)[0];
const tmp = url.parse(link).path.substr(1);
rp(apis.reverse + tmp)
fetch(apis.reverse + tmp)
.then(res => res.json())
.then(res => {
res = JSON.parse(res);
if(res.error)
throw res.error;
return res.data.id;
})
.then(id => Promise.all([
rp(apis.pr0gag.list + id.toString()),
rp(apis.pr0gag.item + id.toString()),
fetch(apis.pr0gag.list + id.toString()),
fetch(apis.pr0gag.item + id.toString()),
id
]).then(([list, item, id]) => [
JSON.parse(list).items.filter(item => item.id === id)[0],
JSON.parse(item),
])
.then(([list, item, id]) => [
list.json().items.filter(item => item.id === id)[0],
item.json(),
id
])
.then(([list, item, id]) => ({