Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Standalone Timer() and GetStream() functions since I've got these setup differently on my channel.
- MOD.Ticks=0;
- --timer
- local timerevents = {};
- --example tick function
- local function Tick(channel)
- if type(MOD.EventTick) == "function" then
- local ret = MOD.EventTick(user,msg);
- if ret ~= nil then
- return ret;
- end
- end
- MOD.Ticks = MOD.Ticks + 1;
- local now = os.time();
- for k,v in pairs(timerevents)do
- if v.start + v.interval <= now then
- if v.action ~= nil then
- if v.action ~= nil then
- if type(v.action) == "function" then
- v.action();
- return;
- else
- print(tostring(v.action));
- end
- end
- end
- if v.recurring then
- v.start = v.start + v.interval;
- else
- timerevents[k] = nil;
- end
- end
- end
- end
- function MOD.GetTimers()
- local list = {};
- for k,v in pairs(timerevents)do
- table.insert(list,k);
- end
- return list;
- end
- function MOD.Timer( name, seconds, action, recurring )
- if action == nil then
- timerevents[name] = nil;
- return;
- end
- if recurring == nil then
- recurring = false;
- elseif type( recurring ) ~= "boolean" then
- error( "Recurring must be a boolean value" );
- return;
- end
- if type(action) ~= "function" and type(action) ~= "string" then
- error("Action must be a function or a string");
- return;
- end
- timerevents[name] = {
- ["start"] = os.time(),
- ["action"] = action,
- ["recurring"] = recurring,
- ["interval"] = seconds,
- };
- end
- MOD.SetTickEvent(Tick);
- function MOD.GetStream(name)
- local body, code, headers, status = MOD.HTTPSGet("https://api.twitch.tv/kraken/streams/"..name);
- if body == nil then
- return nil,"not found";
- end
- local raw = JSONDecode(body);
- if raw == nil then
- return nil,"could not decode response";
- elseif raw.error ~= nil then
- return nil,tostring(raw.error);
- elseif type(raw.stream) ~= "table" then
- return nil,"offline";
- end
- local ret = {};
- ret.viewers = raw.stream.viewers;
- ret.game = raw.stream.game;
- ret.name = raw.stream.channel.display_name;
- ret.partner = raw.stream.channel.partner;
- ret.views = raw.stream.channel.views;
- ret.language = raw.stream.channel.language;
- ret.mature = raw.stream.channel.mature;
- ret.status = raw.stream.channel.status;
- ret.started = raw.stream.created_at;
- ret.fps = raw.stream.average_fps;
- ret.followers = raw.stream.channel.followers;
- return ret;
- end
Advertisement
Add Comment
Please, Sign In to add comment