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)); } })();