-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathutils.js
More file actions
57 lines (51 loc) · 1.62 KB
/
utils.js
File metadata and controls
57 lines (51 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const fetch = require('node-fetch')
const d = require("discord.js")
async function randomText(array) {
return array[Math.floor(Math.random() * array.length)]
}
async function getfromreddit(subreddit) {
const res = await (await fetch(`https://www.reddit.com/r/${subreddit}/random/.json`)).json()
return res[0].data.children[0].data
}
async function redditFetch(subreddit) {
const res = await (await fetch(`https://www.reddit.com/r/${subreddit}/random/.json`)).json()
const self = res[0].data.children[0].data
return {
title: self.title,
image: self.url,
url: `https://${self.permalink}`,
subreddit: `r/${self.subreddit}`,
author: self.author,
upvotes: String(self.ups),
downvotes: String(self.downs),
comments: String(self.num_comments),
upvote_ratio: String(self.upvote_ratio),
nsfw: String(self.over_18),
spoiler: String(self.spoiler)
}
}
async function replaceText(str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace);
}
async function numberSeparator(num,separator=",") {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator);
}
async function jsonRequest(url, property) {
const r = await fetch(url)
const data = await r.json()
if (!property) return data
return data[String(property)]
}
async function fileCount(path) {
const { readdirSync } = require("fs")
return readdirSync(path).length
}
module.exports = {
randomText,
replaceText,
getfromreddit,
redditFetch,
jsonRequest,
fileCount
}
//["d3a625","eeba30","ae0001","740001","1a472a","2a623d","5d5d5d","aaaaaa","ecb939","f0c75e","726255","372e29","000000","0e1a40","222f5b","946b2d"]