-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLeavaris.lua
131 lines (108 loc) · 3.71 KB
/
Leavaris.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
-- Written By CoolAcid
-- https://github.com/coolacid/ComputerCraft
-- Based on the original work by bacon_donut
-- http://pastebin.com/vhn1z23v
-- http://twitch.tv/bacon_donut
-- This is formatted to fit on a 1x3 wall of Advanced Monitors with an Advanced Computer connected to a side
-- To get this to work you need to edit the streamid variable then run these five commands:
-- label set Leav
-- pastebin get WdiT6sR5 bootstrap
-- bootstrap
-- DO NOT USE THIS LINE ORIGINAL -- github get coolacid/ComputerCraft/master/twitchdisplay.lua startup
-- github get Leavaris/Twitch-ComputerCraft-Display/master/Leavaris.lua startup
-- github get Leavaris/Twitch-ComputerCraft-Display/master/Leavaris.lua startup
-- startup
-- Twitch Name of the Streamer
streamid = "Leavaris"
-- Set the Y line for where you want the different bits to go.
line_streamer = 1
line_followers = 3
line_follower = 4
line_viewers = 5
-- Set Justification
-- 1 - Left
-- 2 - Center
-- 3 - Right
justify_streamer = 1
justify_followers = 1
justify_follower = 1
justify_viewers = 1
-- SleepTime is how often to grab new data. Set here to one minute.
-- Set it too fast and twitch will flag you for spam
-- and stop giving you data
SleepTime = 60
-- Check to see if the JSON api exists. Otherwise, download it.
if not fs.exists('json') then
print("JSON API not found - Downloading")
shell.run("pastebin get 4nRg9CHU json")
end
if not fs.exists('functions') then
print("internal functions not found - Downloading")
shell.run("github get coolacid/ComputerCraft/master/functions.lua functions")
end
os.loadAPI("json")
os.loadAPI("functions")
local m = peripheral.find("monitor")
m.setTextColor(colors.blue)
m.setTextScale(1)
function getFollowers()
str = http.get("https://api.twitch.tv/kraken/channels/" .. streamid .. "/follows?limit=1").readAll()
obj = json.decode(str)
follows = json.encodePretty(obj._total)
follower = json.encodePretty(obj.follows[1].user.name)
follower = follower:gsub('"', '')
return follows, follower
end
function getViewerCount()
str = http.get("https://api.twitch.tv/kraken/streams/" .. streamid).readAll()
obj = json.decode(str)
if obj.stream == nil then
return nil
else
return json.encodePretty(obj.stream.viewers)
end
end
function localwrite(text, justify, line)
if justify == 1 then
-- Right
m.setCursorPos(1,line)
elseif justify == 2 then
functions.centerText(m, text, line)
elseif justify == 3 then
functions.rightJustify(m, text, line)
end
m.write(text)
end
while true do
local status, live = pcall(getViewerCount)
if status then
if live == nil then
m.setBackgroundColor(colors.white)
m.clear()
localwrite(streamid, justify_streamer, line_streamer)
localwrite("Live Viewers: Offline", justify_viewers, line_viewers)
else
m.setBackgroundColor(colors.yellow)
m.clear()
localwrite(streamid, justify_streamer, line_streamer)
localwrite("Live Viewers: " .. live, justify_viewers, line_viewers)
end
else
m.setBackgroundColor(colors.white)
m.clear()
localwrite(streamid, justify_streamer, line_streamer)
localwrite("Live Viewers: ERROR", justify_viewers, line_viewers)
end
local status, followers, follower = pcall(getFollowers)
if status then
localwrite("Twitch Followers: " .. followers, justify_followers, line_followers)
m.setCursorPos(1,line_follower)
localwrite("Last Follower: " .. follower, justify_follower, line_follower)
else
m.setCursorPos(1,line_followers)
localwrite("Twitch Followers: ERROR", justify_followers, line_followers)
m.setCursorPos(1,line_follower)
localwrite("Last Follower: ERROR", justify_follower, line_follower)
end
sleep(SleepTime)
end