From 302cb8ffe4cff969ee6606582c802028e135f1f1 Mon Sep 17 00:00:00 2001 From: Flummi Date: Thu, 30 Aug 2018 18:09:28 +0200 Subject: [PATCH] pr0gag parser test --- src/inc/trigger/index.mjs | 5 +-- src/inc/trigger/pr0gag.mjs | 67 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/inc/trigger/pr0gag.mjs diff --git a/src/inc/trigger/index.mjs b/src/inc/trigger/index.mjs index 7343b68..93a79b7 100644 --- a/src/inc/trigger/index.mjs +++ b/src/inc/trigger/index.mjs @@ -11,6 +11,7 @@ import kernel from "./kernel"; import lastfm from "./lastfm"; import mcmaniac from "./mcmaniac"; import parser from "./parser"; +import pr0gag from "./pr0gag"; import quotes from "./quotes"; import rape from "./rape"; import sandbox from "./sandbox"; @@ -24,6 +25,6 @@ import wttr from "./wttr"; export default [ cfg, chatbot, coins, cookie, core, debug, drugs, help, irpg, kernel, lastfm, mcmaniac, - parser, quotes, rape, sandbox, soundcloud, + parser, pr0gag, quotes, rape, sandbox, soundcloud, timer, urban, nxy, uwe, wttr -]; \ No newline at end of file +]; diff --git a/src/inc/trigger/pr0gag.mjs b/src/inc/trigger/pr0gag.mjs new file mode 100644 index 0000000..8cbd53c --- /dev/null +++ b/src/inc/trigger/pr0gag.mjs @@ -0,0 +1,67 @@ +import rp from "request-promise"; +import url from "url"; + +const apis = { + reverse: "https://totally.rip/pr0/img_reverse_lookup.php?image=", + pr0gag: { + list: "https://pr0gramm.com/api/items/get/?flags=15&id=", + item: "https://pr0gramm.com/api/items/info?flags=15&itemId=" + } +}; +const flags = { + 1: "sfw", + 2: "nsfw", + 4: "nsfl", + 8: "nsfp" +}; +const regex = /img\.pr0gramm\.com\/((?:\d+){4}\/(?:\d+){2}\/(?:\d+){2}\/(?:\w{16})\.(?:webm|png|jpg|mp4|webm)?)/gi; +const site = "https://pr0gramm.com/new/"; + +export default bot => { + bot._trigger.set("pr0gag", new bot.trigger({ + call: /img\.programm\.com.*/i, + set: "uwe", + f: e => { + const link = e.message.match(regex)[0]; + const tmp = url.parse(link).path.substr(1); + rp(apis.reverse + tmp) + .then(res => JSON.parse(res).id) + .then(id => Promise.all([ + rp(apis.pr0gag.list + id.toString()), + rp(apis.pr0gag.item + id.toString()), + id + ]) + .then(([list, item, id]) => [ + JSON.parse(list).items.filter(item => item.id === id)[0], + JSON.parse(item), + id + ]) + .then(([list, item, id]) => ({ + created: list.created, + up: list.up, + down: list.down, + score: list.up - list.down, + ratio: (list.up / (list.up + list.down)).toFixed(2), + flags: flags[list.flags], + user: list.user, + comments: item.comments.length, + toptags: item.tags.splice(0, 3).map(tag => tag.tag), + link: site + id.toString() + })) + .then(meta => [ + `c: ${meta.created}`, + `u: ${meta.up}`, + `d: ${meta.down}`, + `s: ${meta.score}`, + `r: ${meta.ratio}`, + `f: ${meta.flags}`, + `u: ${meta.user}`, + `co: ${meta.comments}`, + `t: ${meta.toptags}`, + `l: ${meta.link}` + ].join("; ")) + .then(out => e.reply(out)) + ); + } + })); +};