summaryrefslogtreecommitdiff
path: root/includes/external/addressbook/reddit.js
diff options
context:
space:
mode:
Diffstat (limited to 'includes/external/addressbook/reddit.js')
-rw-r--r--includes/external/addressbook/reddit.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/includes/external/addressbook/reddit.js b/includes/external/addressbook/reddit.js
new file mode 100644
index 0000000..3e5dd15
--- /dev/null
+++ b/includes/external/addressbook/reddit.js
@@ -0,0 +1,63 @@
+const axios = require('axios');
+
+function sleep(ms) {
+ return new Promise((res) => {
+ setTimeout(res, ms);
+ });
+}
+
+(async () => {
+ let user = process.argv[2];
+
+ if (user.startsWith("u/")) user = user.substring(2);
+ if (user.startsWith("user/")) user = user.substring(5);
+
+ try {
+ let data = (await axios.get(`https://www.reddit.com/user/${user}/about.json`)).data.data;
+
+ if (data['icon_img']) data['icon_img'] = data['icon_img'].replaceAll("&", "&");
+
+ let obj = {
+ error: null,
+ avatar: "https://img.icons8.com/fluency-systems-regular/64/ffffff/reddit.png",
+ name: data['subreddit']['title'] ?? data['name'],
+ description: data['subreddit']['display_name_prefixed'],
+ link: `https://www.reddit.com${data['subreddit']['url']}`,
+ copy: [
+ {
+ title: "Copy link to profile",
+ text: `https://www.reddit.com${data['subreddit']['url']}`
+ },
+ {
+ title: "Copy username",
+ text: data['username']
+ },
+ {
+ title: "Copy ID",
+ text: data['id']
+ },
+ data['icon_img'] ? {
+ title: "Copy avatar URL",
+ text: data['icon_img']
+ } : null
+ ]
+ }
+
+ if (data['icon_img']) {
+ obj.avatar = data['icon_img'];
+ }
+
+ console.log(JSON.stringify(obj, null, 2));
+ } catch (e) {
+ console.log(JSON.stringify({
+ error: e,
+ avatar: "https://img.icons8.com/fluency-systems-regular/64/ffffff/reddit.png",
+ name: user,
+ description: "Reddit",
+ link: null,
+ copy: []
+ }, null, 2));
+ }
+
+
+})(); \ No newline at end of file