Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import axios from 'axios';
- import Credentials from '../credentials/Credentials.js';
- async function pastebinDump(data, name, expiration = '1D') {
- try {
- let paste = `api_dev_key=${Credentials.pastebin}&api_option=paste&api_paste_code=${data}&api_paste_name=${name}&api_paste_expire_date=${expiration}`;
- let postRequest = await axios.post(`https://pastebin.com/api/api_raw.php`, paste, {
- headers: {
- "Content-type": "application/x-www-form-urlencoded"
- }
- }).then(res => res.data);
- return typeof postRequest === 'string' && `https://pastebin.com/raw/${postRequest.split('/').slice(-1)}`;
- } catch (error) {
- console.log(error);
- }
- }
- async function getUser(arg, mode) {
- try {
- let user = await axios(`https://api.twitch.tv/helix/users?${mode}=${arg}`, {
- headers: {
- 'Authorization': `Bearer ${Credentials.helix_token}`,
- 'Client-ID': `${Credentials.clientId}`
- }
- }).then(res => mode === 'login' ? res.data.data[0].id : res.data.data[0].login);
- return user && user;
- } catch (error) {
- console.log(`\n\n\n[*]Error getting user "${arg}"`);
- console.log('\tError:', error?.response?.statusText);
- console.log('\tMessage:', error?.response?.data?.message);
- console.log('\n\n\n');
- }
- }
- export async function follows(event, chat, args) {
- let validName = /^@/.test(args[1]);
- let validID = /^[0-9]+$/.test(args[1]);
- if (!validName && !validID) return;
- const userIdentifier = validName && args[1].slice(1);
- const userID = await getUser(userIdentifier, 'login');
- // get follow list
- let followList = [];
- let follows = await axios(`https://api.twitch.tv/helix/users/follows?from_id=${validID ? args[1] : userID}`, {
- headers: {
- 'Authorization': `Bearer ${Credentials.helix_token}`,
- 'Client-Id': `${Credentials.clientId}`
- }
- }).then(res => res.data.data).then(data => data.forEach(entry => {
- let now = Date.now();
- let cmp = new Date(entry.followed_at);
- let parsedDate = compareDates(now, cmp);
- let format = `${parsedDate.years}y ${parsedDate.months}M ${parsedDate.days}d ${parsedDate.hours}h ${parsedDate.minutes}m ${parsedDate.seconds}s`;
- followList.push({ streamName: entry.to_login, streamID: entry.to_id, followDate: entry.followed_at, followAge: format });
- }));
- let pastebinLink = await pastebinDump(JSON.stringify(followList, null, '\t'), 'Follow list');
- await chat.say(event.channel, pastebinLink);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement