Advertisement
kd8lvt

TwitchApi Example

Nov 9th, 2015
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.67 KB | None | 0 0
  1. -----CONFIG-----
  2. streamer = "choobtastic" --This variable is REQUIRED!
  3. --streamer2 = "wolftaz" --Uncomment this line to add a second streamer! Requires a 2 high monitor!
  4. -----CONFIG-----
  5. -----MAIN CODE! DO NOT EDIT!-----
  6. --Checking for my twitch api
  7. if fs.exists("twitchapi") == false then
  8.   shell.run("pastebin get vh4Jd1B6 twitchapi")
  9. end
  10. --Loading my twitch api
  11. os.loadAPI("twitchapi")
  12. --Is there a monitor?
  13. if peripheral.find("monitor") then
  14.   mon = peripheral.find("monitor")
  15.   monitor = true
  16. end
  17. --Is there a second streamer specified? If so, is the monitor large enough to support it?
  18. if streamer2 then
  19.   if monitor then
  20.     x, y = mon.getSize()
  21.     if y > 5 then
  22.       --Good to go!
  23.     else
  24.       error("You need a two tall monitor to allow two streamers!")
  25.     end
  26.   end
  27. end
  28. --Main loop. Does all the visible stuff!
  29. while true do
  30.   if monitor then --Do we have a monitor?
  31.     if twitchapi.checkLive(streamer) then --Is the main streamer live?
  32.       mon.clear()
  33.       mon.setCursorPos(1,1)
  34.       mon.write("LATEST FOLLOWER: "..twitchapi.lastFollower(streamer))
  35.       mon.setCursorPos(1,2)
  36.       mon.write("FOLLOWER COUNT: "..twitchapi.followerCount(streamer))
  37.       mon.setCursorPos(1,3)
  38.       mon.write("LIVE VIEWERS: "..twitchapi.viewerCount(streamer))
  39.     else --The main streamer isn't live.
  40.       mon.clear()
  41.       mon.setCursorPos(1,1)
  42.       mon.write(streamer.." is not live!")
  43.       mon.setCursorPos(1,2)
  44.       mon.write("Written by Kd8lvt for his streamer friends in the Minecraft Twitch Community!")
  45.       mon.setCursorPos(1,3)
  46.       mon.write("-----------------")
  47.     end
  48.     if streamer2 then --Is the secondary streamer specified?
  49.       mon.setCursorPos(1,5)
  50.       mon.write("-----------------")
  51.       if twitchapi.checkLive(streamer2) then --Is the secondary streamer live?
  52.         term.setCursorPos(1,6)
  53.         term.write("LATEST FOLLOWER: "..twitchapi.lastFollower(streamer2))
  54.         term.setCursorPos(1,7)
  55.         term.write("FOLLOWER COUNT: "..twitchapi.followerCount(streamer2))
  56.         term.setCursorPos(1,8)
  57.         term.write("LIVE VIEWERS: "..twitchapi.viewerCount(streamer2))
  58.       else --The secondary streamer isn't live.
  59.             if twitchapi.checkLive(streamer) then
  60.           term.setCursorPos(1,6)
  61.           term.write(streamer2.." is not live!")
  62.         else
  63.           term.setCursorPos(1,4)
  64.           term.write(streamer2.." is not live!")
  65.         end
  66.       end --For some reason all this code got derped up when I put it on pastebin... just looks messy. Still works!
  67.     else
  68.     mon.setCursorPos(1,5)
  69.     mon.write("Written by Kd8lvt for his streamer friends in the Minecraft Twitch community!")
  70.   end
  71.   end
  72.   if monitor == null then --There isn't a monitor!
  73.     if twitchapi.checkLive(streamer) then --Is the main streamer live?
  74.       shell.run("clear")
  75.           print("LATEST FOLLOWER: "..twitchapi.lastFollower(streamer))
  76.       print("FOLLOWER COUNT: "..twitchapi.followerCount(streamer))
  77.       print("LIVE VIEWERS: "..twitchapi.viewerCount(streamer))
  78.     else
  79.       shell.run("clear")
  80.       print(streamer.." is not live!")
  81.       print("Written by Kd8lvt for his streamer friends in the Minecraft Twitch community!")
  82.     end
  83.     if streamer2 then --Is the secondary streamer specified?
  84.       print("-----------------")
  85.       if twitchapi.checkLive(streamer2) then --Is the secondary streamer live?
  86.         print("LATEST FOLLOWER: "..twitchapi.lastFollower(streamer2))
  87.             print("FOLLOWER COUNT: "..twitchapi.followerCount(streamer2))
  88.         print("LIVE VIEWERS: "..twitchapi.viewerCount(streamer2))
  89.       else --Thye secondary streamer isn't live... :(
  90.         print(streamer2.." is not live!")
  91.       end
  92.     else --There is no secondary streamer specified!
  93.       print("Written by Kd8lvt for his streamer friends in the Minecraft Twitch community!")
  94.     end
  95.   end
  96.   sleep(5)
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement