Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Available standard functions:
- _VERSION
- assert
- error
- ipairs
- next
- pairs
- pcall
- select
- tonumber
- tostring
- type
- unpack
- xpcall
- coroutine.create
- coroutine.resume
- coroutine.running
- coroutine.status
- coroutine.wrap
- coroutine.yield
- math.abs
- math.acos
- math.asin
- math.atan
- math.atan2
- math.ceil
- math.cos
- math.cosh
- math.deg
- math.exp
- math.fmod
- math.floor
- math.frexp
- math.huge
- math.ldexp
- math.log
- math.log10
- math.max
- math.min
- math.modf
- math.pi
- math.pow
- math.rad
- math.random
- math.sin
- math.sinh
- math.sqrt
- math.tan
- math.tanh
- os.clock
- os.difftime
- os.time
- string.byte
- string.char
- string.find
- string.format
- string.gmatch
- string.gsub
- string.len
- string.lower
- string.match
- string.reverse
- string.sub
- string.upper
- table.insert
- table.maxn
- table.remove
- table.sort
- Custom functions
- ME(); -> returns the current user
- Channel(); -> returns the name of the channel we're in
- print(string); -> adds string to the response
- GetUsers(); -> returns an array containing all the users in the channel
- UserStatus(string) -> returns 0 if the user isnt here, 1 if the user is here and 2 if the user is here and is a mod. If the user is present it returns a second result which is a string containing the title
- GetCommands() -> returns an array containing the available commands
- GetMsg(user) -> return the last message sent by the user, returns nil if none
- JSONEncode(tbl) -> returns the table as json encoded
- JSONDecode(data) -> decodes a json string into a table
- Timestamp() -> timestamp in CET
- Date(formatting,time) -> wrapper around os.date, if time is nil it takes the current time
- HTML(html) -> decodes html to a lua table (https://github.com/luaforge/html/tree/master/html) as html.parsestr
- (MOD is only available to moderators in the channel)
- The timer functions are defined within this script!
- MOD.Timer(name,seconds,event) -> runs the event after seconds has elapsed (fire&forget), event can be a string or a function, if seconds is 0 or nil the timer is deleted. If the timer already exists its overwritten/restarted.
- he timer functions are defined within this script!
- MOD.GetTimers() -> returns an array containing the names of all running timers
- Get stream is defined inside of this script!
- MOD.GetStream(nameofstream) -> returns a table or nil if the stream is live or not
- MOD.GetVar(key,channel) -> returns a value from the database
- MOD.SetVar(key,value,arrayid) -> Sets or updates a value in the database, arrayid is optional
- MOD.DelVar(key) -> delete a value from the database
- MOD.GetArray(arrayid, chan, descending,limit, offset) -> returns a table containing key:values as set by SetVar with arrayid
- MOD.DelArray(arrayid) -> deletes all records with the arrayid
- MOD.GetGlobalVar(key) -> returns a value from the database, shared across all channels
- MOD.SetGlobalVar(key,value) -> Sets or updates a value in the database, shared across all channels
- MOD.DelGlobalVar(key) -> delete a value from the database, shared across all channels
- MOD.Commercial(sec) -> runs a commercial for sec (30|60|90|120|150|180) default is 30
- MOD.ResetCD(user) -> resets the cooldown, if a user is supplied it resets it for the user too
- MOD.HTTPGet(url) -> returns content and status, content is nil on failure
- MOD.HTTPSGet(url) -> Same as above but HTTPS, returns body, code, headers, status in that order
- MOD.HTTPPost(url,headers,request_body) -> sends a post request, headers should be a table, request_body should be a string
- MOD.HTTPSPost(url,headers,request_body) -> same as above but https/ssl
- -> POST functions returns string resource, number code, table response_headers, table response_body
- MOD.StartupScript(pastebintag*) -> Sets the channel's startup script
- MOD.Save() -> Saves your commands and the saveable content in the MOD table
- MOD.Reload() -> Reloads/Resets the channel environment and reruns the startup script
- MOD.AddCom(string,value); -> creates a command where string is the command without the !.
- if value is a function it must be defined beforehand or within the same chunk as AddCom, IE:
- AddCom("Test", function(msg,usr,channel) print("cat"); end); AddCom additionally runs MOD.Save automatically.
- AddCom passes the message, user and channel name in that order to its calling function.
- MOD.PasteBin(pastebintag*) -> runs a script off pastebin as if it was a local script, returns the result and a status boolean, if the status boolean is false the result will be an error message.
- MOD.Timeout(user,time) -> Timesout a user, if time isnt provided the timeout is 1 second (Kitsunebot must be a mod)
- MOD.Ban(user) -> perma bans user (Kitsunebot must be a mod)
- MOD.Unban(user) -> unbans a previously banned user (Kitsunebot must be a mod)
- MOD.TimestampToSec(stamp) -> Convert a "yyyy-mm-ddThh:mm:ssZ" timestamp to unix
- MOD.SecondToSpan(unixtimestamp) -> Converts a unixtimestamp to timespan DD:HH:MM:SS
- Additional notes:
- pastebintag* = this is the last letters in a pastebin
- for example the link to this script is http://pastebin.com/y68mc6pM
- the tag is as thus y68mc6pM
- The MOD table is only available for moderators and its contents (strings, numbers, tables)
- are saved when MOD.Save is called.
- MOD.MODONLY (default false) if true kitsunebot will only respond to mods (custom commands included).
- IE: !kitsunebot MOD.MODONLY=true (or false) to toggle it on or off.
- MOD.COOLDOWN (default 15) The cooldown of which kitsunebot will respond to commands, channel mods are exempt from this cooldown
- MOD.INDIVIDUAL_CD (default 20) same as above but for the individual user
- ]]
- --Upvalue function
- local function Meow(msg,usr,chan)
- --No param supplied
- if msg == "" then
- local stream = MOD.GetStream(chan:sub(2));
- local streamstatus ="";
- if stream == nil then
- streamstatus = "Stream not online";
- else
- streamstatus = "Stream is online with " .. tostring(stream.viewers) .. " viewers";
- end
- print("MEOW! " .. usr .. " you are in " .. chan .. " there are " .. #GetUsers() .. " users in the chat! " .. streamstatus );
- else
- --Special dumb cases
- if msg:lower() == usr:lower() then
- print("MEOW! " .. usr .. " 4Head");
- return;
- elseif msg:lower() == "kitsunebot" then
- print("MEOW! " .. usr .. " Kreygasm" );
- return;
- end
- --Get the status 1 here, 2 mod, 0 not here
- local status,title = UserStatus(msg);
- if status == 1 then
- print("MEOW! " .. usr .. " " .. msg .. " is here!");
- elseif status == 2 then
- print("MEOW! " .. usr .. " " .. msg .. " is here as a "..title:lower().."!");
- else
- print("MEOW! " .. usr .. " " .. msg .. " is not here!");
- end
- end
- end
- --Helper function
- local function IsBroadcaster(user)
- local channel = Channel():sub(2):lower();
- return channel == user:lower();
- end
- --Turn seconds into a span IE "hh:mm:ss"
- local function SecondToSpan(sec)
- --Break out the components from the seconds
- local days = math.floor((sec/3600)/24);
- local hours = math.floor((sec/3600));
- local mins = math.floor((sec-(hours*3600))/60);
- local seconds = math.floor(sec%60);
- --Pad out the span with 0 when necessary
- if mins < 10 then
- mins = "0"..tostring(mins);
- end
- if seconds < 10 then
- seconds = "0"..tostring(seconds);
- end
- --return as "dd:hh:mm:ss"
- if days > 0 then
- hours = hours - (days*24)
- if hours < 10 then
- hours= "0"..tostring(hours);
- end
- return tostring(days) .. ":" .. tostring(hours) .. ":" .. tostring(mins) .. ":" .. tostring(seconds);
- else
- if hours < 10 then
- hours= "0"..tostring(hours);
- end
- end
- return tostring(hours) .. ":" .. tostring(mins) .. ":" .. tostring(seconds);
- end
- MOD.SecondToSpan = SecondToSpan;
- local function TimestampToSec(stamp)
- local tbl = {};
- tbl.year,tbl.month,tbl.day,tbl.hour,tbl.min,tbl.sec = string.match(stamp, "(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)");
- --+1 gmt
- tbl.hour = tbl.hour + 2;
- return os.time(tbl);
- end
- MOD.TimestampToSec = TimestampToSec;
- --Helper function
- local function GetSub(msg)
- if(msg:find("subscribed!"))then
- local pos = msg:find(" ",0,true);
- return msg:sub(1,pos-1);
- end
- return nil;
- end
- --example message function
- local function Message(user, msg)
- if user:lower() == "twitchnotify" and type(MOD.EventSub) == "function" then
- local sub = GetSub(msg);
- if sub~=nil and sub ~= "" then
- return MOD.EventSub(sub);
- end
- end
- --Save the last message and user
- MOD.LastMsg = msg;
- MOD.LastUsr = user;
- if type(MOD.EventMsg) == "function" then
- return MOD.EventMsg(user,msg);
- end
- end
- 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.time <= now then
- timerevents[k]=nil;
- 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
- 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,event)
- if event == nil then
- timerevents[name]=nil;
- return;
- end
- if type(event) ~= "function" and type(event) ~= "string" then
- error("Event must be a function or a string");
- return;
- end
- local entry = {};
- entry.time = os.time()+seconds;
- entry.action = event;
- timerevents[name] = entry;
- end
- function MOD.GetStream(name)
- local body, code, headers, status = MOD.HTTPSGet("https://api.twitch.tv/kraken/streams/"..name);
- if code ~= 200 then
- return nil,tostring(code);
- elseif 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
- local function SetIVCD(msg, usr, chan)
- if not msg or msg == "" or UserStatus(usr) ~= 2 then
- return;
- end
- msg = tonumber(msg);
- if msg == nil then
- print("Not a number");
- return;
- end
- MOD.INDIVIDUAL_CD = msg;
- print("Individual cooldown set: " .. tostring(MOD.INDIVIDUAL_CD) );
- MOD.Save();
- end
- local function SetCD(msg, usr, chan)
- if not msg or msg == "" or UserStatus(usr) ~= 2 then
- return;
- end
- msg = tonumber(msg);
- if msg == nil then
- print("Not a number");
- return;
- end
- MOD.COOLDOWN = msg;
- print("Global cooldown set: " .. tostring(MOD.COOLDOWN) );
- MOD.Save();
- end
- --Register the function
- MOD.AddCom("meow",Meow);
- MOD.AddCom("ivcd",SetIVCD);
- MOD.AddCom("gcd",SetCD);
- --Set the events; these functions are only available in the startup script
- MOD.SetUserMsgEvent(Message);
- MOD.SetTickEvent(Tick);
- if type(MOD.KitsuneMod)=="string" and MOD.KitsuneMod~="" then
- return MOD.PasteBin(MOD.KitsuneMod);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement