diff options
author | RaindropsSys <contact@minteck.org> | 2023-04-04 19:07:33 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-04-04 19:07:33 +0200 |
commit | b9aca19cccf9fd85a05d2ae32846b5b4f25a4dc1 (patch) | |
tree | 1ecb5f1c27f159bb175ecded73d4235fcfb4b5ae /includes/external/addressbook/discord.js | |
parent | 704e1c22efe6056b0fc2f59b2766f47e1c8d71cc (diff) | |
download | pluralconnect-b9aca19cccf9fd85a05d2ae32846b5b4f25a4dc1.tar.gz pluralconnect-b9aca19cccf9fd85a05d2ae32846b5b4f25a4dc1.tar.bz2 pluralconnect-b9aca19cccf9fd85a05d2ae32846b5b4f25a4dc1.zip |
Added 147 files (automated)
Diffstat (limited to 'includes/external/addressbook/discord.js')
-rw-r--r-- | includes/external/addressbook/discord.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/includes/external/addressbook/discord.js b/includes/external/addressbook/discord.js new file mode 100644 index 0000000..04ef2d6 --- /dev/null +++ b/includes/external/addressbook/discord.js @@ -0,0 +1,68 @@ +const axios = require('axios'); +const apiVersion = "v10"; +const app = require('../../app.json'); + +function sleep(ms) { + return new Promise((res) => { + setTimeout(res, ms); + }); +} + +(async () => { + let user = process.argv[2]; + + try { + let data = (await axios.get(`https://discord.com/api/${apiVersion}/users/${user}`, { + headers: { + Authorization: `Bot ${app.discord.token}` + } + })).data; + + let obj = { + error: null, + avatar: "https://img.icons8.com/fluency-systems-regular/64/ffffff/discord.png", + name: user, + description: "Discord", + copy: [ + { + title: "Copy full username", + text: `${data['username']}#${data['discriminator']}` + }, + { + title: "Copy mention", + text: `<@${user}>` + }, + { + title: "Copy ID", + text: `${user}` + }, + data['avatar'] ? { + title: "Copy avatar URL", + text: `https://cdn.discordapp.com/avatars/${user}/${data['avatar']}.png` + } : null + ] + } + + if (data['display_name'] || data['global_name']) { + obj.description = data['username'] + "#" + data['discriminator']; + } else { + obj.description = "#" + data['discriminator']; + } + + if (data['avatar']) { + obj.avatar = `https://cdn.discordapp.com/avatars/${user}/${data['avatar']}.png`; + } + + obj.name = data['display_name'] ?? data['global_name'] ?? data['username'] ?? data['id']; + + 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/discord.png", + name: user, + description: "Discord", + copy: [] + }, null, 2)); + } +})();
\ No newline at end of file |