diff options
author | RaindropsSys <contact@minteck.org> | 2023-04-05 08:00:10 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-04-05 08:00:10 +0200 |
commit | 164d31aeb4d1e4d4b796fa4c5fbc356ab1a6ad67 (patch) | |
tree | 2675cb1d904c0775ae23f0c93f724419107e787b /includes | |
parent | b9aca19cccf9fd85a05d2ae32846b5b4f25a4dc1 (diff) | |
download | pluralconnect-164d31aeb4d1e4d4b796fa4c5fbc356ab1a6ad67.tar.gz pluralconnect-164d31aeb4d1e4d4b796fa4c5fbc356ab1a6ad67.tar.bz2 pluralconnect-164d31aeb4d1e4d4b796fa4c5fbc356ab1a6ad67.zip |
Added 2 files (automated)
Diffstat (limited to 'includes')
-rw-r--r-- | includes/external/addressbook/twitter-tag-to-id.js | 34 | ||||
-rw-r--r-- | includes/external/addressbook/twitter.js | 62 |
2 files changed, 96 insertions, 0 deletions
diff --git a/includes/external/addressbook/twitter-tag-to-id.js b/includes/external/addressbook/twitter-tag-to-id.js new file mode 100644 index 0000000..663f195 --- /dev/null +++ b/includes/external/addressbook/twitter-tag-to-id.js @@ -0,0 +1,34 @@ +const axios = require('axios'); +const apiVersion = "2"; +const app = require('../../app.json'); + +function sleep(ms) { + return new Promise((res) => { + setTimeout(res, ms); + }); +} + +(async () => { + let user = process.argv[2]; + let id; + + try { + id = BigInt(user); + } catch (e) {} + + if (id) { + console.log(id.toString()); + } else { + if (user.startsWith("@")) { + user = user.substring(1); + } + + try { + console.log((await axios.get(`https://api.twitter.com/${apiVersion}/users/by?usernames=${user}&user.fields=id`, { + headers: { + Authorization: `Bearer ${app.twitter.bearer}` + } + })).data.data[0].id); + } catch (e) {} + } +})();
\ No newline at end of file diff --git a/includes/external/addressbook/twitter.js b/includes/external/addressbook/twitter.js new file mode 100644 index 0000000..b22fca3 --- /dev/null +++ b/includes/external/addressbook/twitter.js @@ -0,0 +1,62 @@ +const axios = require('axios'); +const apiVersion = "2"; +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://api.twitter.com/${apiVersion}/users/${user}?user.fields=id,description,profile_image_url`, { + headers: { + Authorization: `Bearer ${app.twitter.bearer}` + } + })).data.data; + + let obj = { + error: null, + avatar: "https://img.icons8.com/fluency-systems-regular/64/ffffff/twitter.png", + name: data['name'], + description: `@${data['username']}`, + copy: [ + { + title: "Copy link to profile", + text: `https://twitter.com/${data['username']}` + }, + { + title: "Copy username", + text: `@${data['username']}` + }, + { + title: "Copy ID", + text: `${data['id']}` + }, + data['profile_image_url'] ? { + title: "Copy avatar URL", + text: data['profile_image_url'] + } : null + ] + } + + if (data['profile_image_url']) { + obj.avatar = data['profile_image_url']; + } + + 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/twitter.png", + name: user, + description: "Twitter", + copy: [] + }, null, 2)); + } + + +})();
\ No newline at end of file |