Riekelt

copycat v2

Nov 23rd, 2020
513
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // var api = require('twitch-api-v5');
  2. var fetch = require('node-fetch');
  3. var irc = require("tmi.js");
  4. var esaGame = "";
  5. var bsgGame = "";
  6. var esaTitle = "";
  7. var bsgTitle = "";
  8. var interval = "5"; //in minutes
  9.  
  10. const OPTIONS = {
  11.   options: {
  12.     debug: true
  13.   },
  14.   connection: {
  15.     //server: "irc.swiftirc.net",
  16.     //port: 6667,
  17.     random: "chat",
  18.     reconnect: true
  19.   },
  20.   identity: {
  21.     username: "nuhh",
  22.     password: "nuhh"
  23.   },
  24.   channels: ["#botikelt"]
  25. };
  26.  
  27. var client = new irc.client(OPTIONS);
  28. // Connect the client to the server..
  29. client.connect();
  30.  
  31. logic();
  32. setInterval(function() {
  33.   logic();
  34. }, interval * 60 * 1000);
  35.  
  36.  
  37. function logic() {
  38.   getGame();
  39.   setTimeout(function() {
  40.     if (esaGame !== bsgGame) {
  41.       setGame();
  42.     } else {
  43.       console.log("No update");
  44.     }
  45.   }, (2 * 1000));
  46. }
  47.  
  48. function getGame() {
  49.   client.api({ //esamarathon
  50.     url: "https://api.twitch.tv/helix/channels?broadcaster_id=54739364",
  51.     headers: {
  52.       'Client-ID': '<key>',
  53.       'Authorization': 'Bearer <key>'
  54.     }
  55.   }, (err, res, body) => {
  56.     // console.log(body);
  57.     esaGame = body.data[0].game_name;
  58.     esaTitle = body.data[0].title;
  59.     console.log("ESA Game saved: " + esaGame);
  60.   });
  61.   client.api({ //bsg_marathon
  62.     url: "https://api.twitch.tv/helix/channels?broadcaster_id=30685577",
  63.     headers: {
  64.       'Client-ID': '<key>',
  65.       'Authorization': 'Bearer <key>'
  66.     }
  67.   }, (err, res, body) => {
  68.     // console.log(body);
  69.     bsgGame = body.data[0].game_name;
  70.     bsgTitle = body.data[0].title;
  71.     console.log("BSG Game saved: " + bsgGame);
  72.   });
  73. }
  74.  
  75. function setGame() {
  76.  
  77.   postRequest('https://api.twitch.tv/kraken/channels/30685577')
  78.     // .then(data => console.log(data)) // Result from the `response.json()` call
  79.     .then(data => console.log(""))
  80.     .catch(error => console.error(error))
  81.  
  82.   function postRequest(url, data) {
  83.     return fetch(url, {
  84.         method: 'PUT', // 'GET', 'PUT', 'DELETE', etc.
  85.         body: '{"channel": {"game": "' + esaGame + '", "status": "' + esaTitle + '"}}', // Coordinate the body type with 'Content-Type'
  86.         headers: {
  87.           'Client-ID': '<key>',
  88.           'Authorization': 'OAuth <key>', //scope channel_editor
  89.           'Accept': 'application/vnd.twitchtv.v5+json',
  90.           'Content-Type': 'application/json'
  91.         },
  92.       })
  93.       .then(response => response.json());
  94.   }
  95.   console.log("UPDATE: Changed BSG game to " + esaGame)
  96. }
  97. // fetch('https://api.twitch.tv/helix/channels?broadcaster_id=26082881', {
  98. //     method: 'GET',
  99. //     headers: {
  100. //         'Client-ID': '<key, but commented out anyways>',
  101. //         'Authorization': 'Bearer <key but it is commented out anyways>'
  102. //     }
  103. // })
  104. //  .then(res => res.json())
  105. //  .then(res => {
  106. //      console.log(res) // I keep getting "OAuth token is missing"
  107. //      console.log("De game is "+res.data[0].game_name);
  108. //      console.log(res.data[0].title);
  109. //  });
  110.  
RAW Paste Data