Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cache = {};
- local function GetAllEmotes(chan)
- local list = cache[chan:lower()];
- if list ~= nil then
- if type(list) == "table" then
- return list;
- else
- return nil;
- end
- end
- local body, code, headers, status = MOD.HTTPSGet("https://api.twitch.tv/kraken/chat/"..chan.."/emoticons");
- local tbl = JSONDecode(body);
- if tbl.error ~= nil then
- cache[chan:lower()] = 0;
- return nil;
- end
- local lst = {};
- for n=1,#tbl.emoticons do
- if tbl.emoticons[n].subscriber_only and tbl.emoticons[n].state then
- lst[tbl.emoticons[n].regex] = tbl.emoticons[n].url
- end
- end
- cache[chan:lower()] = lst;
- return lst;
- end
- local cmd = function(msg,usr,chan)
- local split = {};
- for match in (msg.." "):gmatch("(.-) ") do
- table.insert(split, match);
- end
- local channel = split[1];
- local emote = split[2];
- if channel == nil or channel == "" then
- channel = chan:lower();
- end
- local lst = GetAllEmotes(channel);
- if lst == nil then
- print("No such channel exists");
- return;
- end
- if emote == nil or emote == "" then
- for k,v in pairs(lst) do
- print(k);
- end
- else
- emote = emote:lower();
- local url = "";
- for k,v in pairs(lst) do
- if k:lower() == emote then
- url = v;
- break;
- end
- end
- if url == "" then
- print("No such emote exists");
- else
- print(url);
- end
- end
- end
- return cmd;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement