Advertisement
Profesar

Untitled

Nov 26th, 2021
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. import axios from 'axios';
  2. import Credentials from '../credentials/Credentials.js';
  3.  
  4. async function pastebinDump(data, name, expiration = '1D') {
  5. try {
  6. let paste = `api_dev_key=${Credentials.pastebin}&api_option=paste&api_paste_code=${data}&api_paste_name=${name}&api_paste_expire_date=${expiration}`;
  7. let postRequest = await axios.post(`https://pastebin.com/api/api_raw.php`, paste, {
  8. headers: {
  9. "Content-type": "application/x-www-form-urlencoded"
  10. }
  11. }).then(res => res.data);
  12. return typeof postRequest === 'string' && `https://pastebin.com/raw/${postRequest.split('/').slice(-1)}`;
  13. } catch (error) {
  14. console.log(error);
  15. }
  16. }
  17.  
  18. async function getUser(arg, mode) {
  19. try {
  20. let user = await axios(`https://api.twitch.tv/helix/users?${mode}=${arg}`, {
  21. headers: {
  22. 'Authorization': `Bearer ${Credentials.helix_token}`,
  23. 'Client-ID': `${Credentials.clientId}`
  24. }
  25. }).then(res => mode === 'login' ? res.data.data[0].id : res.data.data[0].login);
  26. return user && user;
  27. } catch (error) {
  28. console.log(`\n\n\n[*]Error getting user "${arg}"`);
  29. console.log('\tError:', error?.response?.statusText);
  30. console.log('\tMessage:', error?.response?.data?.message);
  31. console.log('\n\n\n');
  32. }
  33. }
  34.  
  35. export async function follows(event, chat, args) {
  36. let validName = /^@/.test(args[1]);
  37. let validID = /^[0-9]+$/.test(args[1]);
  38. if (!validName && !validID) return;
  39. const userIdentifier = validName && args[1].slice(1);
  40. const userID = await getUser(userIdentifier, 'login');
  41. // get follow list
  42. let followList = [];
  43. let follows = await axios(`https://api.twitch.tv/helix/users/follows?from_id=${validID ? args[1] : userID}`, {
  44. headers: {
  45. 'Authorization': `Bearer ${Credentials.helix_token}`,
  46. 'Client-Id': `${Credentials.clientId}`
  47. }
  48. }).then(res => res.data.data).then(data => data.forEach(entry => {
  49. let now = Date.now();
  50. let cmp = new Date(entry.followed_at);
  51. let parsedDate = compareDates(now, cmp);
  52. let format = `${parsedDate.years}y ${parsedDate.months}M ${parsedDate.days}d ${parsedDate.hours}h ${parsedDate.minutes}m ${parsedDate.seconds}s`;
  53. followList.push({ streamName: entry.to_login, streamID: entry.to_id, followDate: entry.followed_at, followAge: format });
  54. }));
  55. let pastebinLink = await pastebinDump(JSON.stringify(followList, null, '\t'), 'Follow list');
  56. await chat.say(event.channel, pastebinLink);
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement