get data from reddit api
This commit is contained in:
parent
29dbe6d309
commit
90a08897e0
2 changed files with 25 additions and 4 deletions
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
24
src/functions/reddit.ts
Normal file
24
src/functions/reddit.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import axios from "axios";
|
||||
/**
|
||||
* Sends an embed of reddit
|
||||
* @return {Promise<Object>}
|
||||
*/
|
||||
export async function getreddit(sub: string): Promise<object> {
|
||||
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;
|
||||
}
|
Loading…
Reference in a new issue