diff options
author | RaindropsSys <contact@minteck.org> | 2023-04-05 15:55:48 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-04-05 15:55:48 +0200 |
commit | 47b8f2299a483024c4a6a8876af825a010954caa (patch) | |
tree | 8c8dc4e99e1e971eeda964a95942340f5a71f546 /includes/external/addressbook/reddit.js | |
parent | 164d31aeb4d1e4d4b796fa4c5fbc356ab1a6ad67 (diff) | |
download | pluralconnect-47b8f2299a483024c4a6a8876af825a010954caa.tar.gz pluralconnect-47b8f2299a483024c4a6a8876af825a010954caa.tar.bz2 pluralconnect-47b8f2299a483024c4a6a8876af825a010954caa.zip |
Updated 2 files and added 3 files (automated)
Diffstat (limited to 'includes/external/addressbook/reddit.js')
-rw-r--r-- | includes/external/addressbook/reddit.js | 63 |
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 |