masterhandkun

Untitled

Jan 7th, 2022 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getResponse(username) {
  2.     const responses = {
  3.         'GinsStreamCorner': `${userName} ist zu breit für den Stream`,
  4.         'default': `${userName} ist leider nicht da :(`
  5.     };
  6.    
  7.     const inChat = isInChat(username);
  8.     if (inChat) {
  9.         return 'Er ist da! :D';
  10.     }
  11.    
  12.     const key = responses[userName];
  13.     if (key !== undefined) {
  14.         return key;
  15.     } else {
  16.         return responses['default'];
  17.     }
  18. }
  19.  
  20. function isInChat(username) {
  21.     const url = 'https://tmi.twitch.tv/group/user/sic_smash/chatters';
  22.    
  23.     const xmlHttp = new XMLHttpRequest();
  24.     xmlHttp.open( "GET", url, false);
  25.     xmlHttp.send( null );
  26.     const response = xmlHttp.responseText;
  27.    
  28.     const json = JSON.parse(response);
  29.     const chatters = json.chatters;
  30.     if (chatters.moderators.includes(username) {
  31.         return true;
  32.     }
  33.     if (chatters.vips.includes(username) {
  34.         return true;
  35.     }
  36.     if (chatters.viewers.includes(username) {
  37.         return true;
  38.     }
  39.     return false;
  40. }
Add Comment
Please, Sign In to add comment