From 90a08897e0b3d108e8a0c0224315119f022c820c Mon Sep 17 00:00:00 2001 From: night0721 Date: Tue, 14 Sep 2021 02:02:25 +0800 Subject: [PATCH] get data from reddit api --- package.json | 5 +---- src/functions/reddit.ts | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/functions/reddit.ts diff --git a/package.json b/package.json index f256220..28d81d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cath", - "version": "1.1.3-dev", + "version": "1.2.0-dev", "description": "A powerful package that can interact with Cath API", "main": "./dist/index.js", "types": "./dist/index.d.ts", @@ -38,9 +38,6 @@ "discord.js": "^13.1.0" }, "devDependencies": { - "@types/jsdom": "^16.2.13", - "ts-node": "^10.2.1", - "typedoc": "^0.21.9", "typescript": "^4.4.3" } } diff --git a/src/functions/reddit.ts b/src/functions/reddit.ts new file mode 100644 index 0000000..2deebd3 --- /dev/null +++ b/src/functions/reddit.ts @@ -0,0 +1,24 @@ +import axios from "axios"; +/** + * Sends an embed of reddit + * @return {Promise} + */ +export async function getreddit(sub: string): Promise { + const content = await axios + .get(`https://www.reddit.com/r/${sub}/random/.json`) + .then(res => res.data); + let permalink = content[0].data.children[0].data.permalink; + let memeURL = `https://reddit.com${permalink}`; + let memeImage = content[0].data.children[0].data.url; + let memeTitle = content[0].data.children[0].data.title; + let memeUpvotes = content[0].data.children[0].data.ups; + let memeDownvotes = content[0].data.children[0].data.downs; + let memeNumComments = content[0].data.children[0].data.num_comments; + const obj: object = { + title: `A cat image | ${memeTitle}`, + url: `${memeURL}`, + image: memeImage, + footer: ` 👍 ${memeUpvotes} 💬 ${memeNumComments}`, + }; + return obj; +}