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