View difference between Paste ID: rXL3ZRYw and y68mc6pM
SHOW: | | - or go back to the newest paste.
1-
--[[
1+
--[[To activate the kitsunemod script run the following:
2
	!kitsunebot MOD.KitsuneMod="rXL3ZRYw"; MOD.Save(); MOD.Reload();
3-
Available standard functions:
3+
4
5-
    _VERSION
5+
local domains = [[.ac.ad.ae.aero.af.ag.ai.al.am.an.ao.aq.ar.arpa.as.asia.at.au
6-
    assert
6+
   .aw.ax.az.ba.bb.bd.be.bf.bg.bh.bi.biz.bj.bm.bn.bo.br.bs.bt.bv.bw.by.bz.ca
7-
    error
7+
   .cat.cc.cd.cf.cg.ch.ci.ck.cl.cm.cn.co.com.coop.cr.cs.cu.cv.cx.cy.cz.dd.de
8-
    ipairs
8+
   .dj.dk.dm.do.dz.ec.edu.ee.eg.eh.er.es.et.eu.fi.firm.fj.fk.fm.fo.fr.fx.ga
9-
    next
9+
   .gb.gd.ge.gf.gh.gi.gl.gm.gn.gov.gp.gq.gr.gs.gt.gu.gw.gy.hk.hm.hn.hr.ht.hu
10-
    pairs
10+
   .id.ie.il.im.in.info.int.io.iq.ir.is.it.je.jm.jo.jobs.jp.ke.kg.kh.ki.km.kn
11-
    pcall
11+
   .kp.kr.kw.ky.kz.la.lb.lc.li.lk.lr.ls.lt.lu.lv.ly.ma.mc.md.me.mg.mh.mil.mk
12-
    select
12+
   .ml.mm.mn.mo.mobi.mp.mq.mr.ms.mt.mu.museum.mv.mw.mx.my.mz.na.name.nato.nc
13-
    tonumber
13+
   .ne.net.nf.ng.ni.nl.no.nom.np.nr.nt.nu.nz.om.org.pa.pe.pf.pg.ph.pk.pl.pm
14-
    tostring
14+
   .pn.post.pr.pro.ps.pt.pw.py.qa.re.ro.ru.rw.sa.sb.sc.sd.se.sg.sh.si.sj.sk
15-
    type
15+
   .sl.sm.sn.so.sr.ss.st.store.su.sv.sy.sz.tc.td.tel.tf.tg.th.tj.tk.tl.tm.tn
16-
    unpack
16+
   .to.tp.tr.travel.tt.tv.tw.tz.ua.ug.uk.um.us.uy.va.vc.ve.vg.vi.vn.vu.web.wf
17-
    xpcall
17+
   .ws.xxx.ye.yt.yu.za.zm.zr.zw]]
18-
    coroutine.create
18+
local tlds = {}
19-
    coroutine.resume
19+
for tld in domains:gmatch'%w+' do
20-
    coroutine.running
20+
   tlds[tld] = true
21-
    coroutine.status
21+
22-
    coroutine.wrap
22+
23-
    coroutine.yield
23+
local function IsURLBlackListed(prot, subd, tld, colon, port, slash, path)
24-
    math.abs
24+
25-
    math.acos
25+
	if ( prot and prot ~= "" ) or tlds[tld:lower()] then
26-
    math.asin
26+
27-
    math.atan
27+
		if type(MOD.URLWhiteList)~="table"then
28-
    math.atan2
28+
			MOD.URLWhiteList = {};
29-
    math.ceil
29+
			return true;
30-
    math.cos
30+
31-
    math.cosh
31+
32-
    math.deg
32+
		subd = subd:lower();
33-
    math.exp
33+
		subd = subd:gsub("www.","");
34-
    math.fmod
34+
		subd = subd:sub(0,subd:len()-1);
35-
    math.floor
35+
36-
    math.frexp
36+
		local website = subd.."."..tld;
37-
    math.huge
37+
38-
    math.ldexp
38+
		website = website:lower();
39-
    math.log
39+
40-
    math.log10
40+
		if MOD.URLWhiteList[website] then
41-
    math.max
41+
			return false;
42-
    math.min
42+
43-
    math.modf
43+
44-
    math.pi
44+
		return true;
45-
    math.pow
45+
46-
    math.rad
46+
47-
    math.random
47+
	return false;
48-
    math.sin
48+
49-
    math.sinh
49+
50-
    math.sqrt
50+
local function GetHasBlacklistedURLs(msg)
51-
    math.tan
51+
52-
    math.tanh
52+
	local urls = {};
53-
    os.clock
53+
54-
    os.difftime
54+
	for pos, url, prot, subd, tld, colon, port, slash, path in msg:gmatch
55-
    os.time
55+
	   '()(([%w_.~!*:@&+$/?%%#-]-)(%w[-.%w]*%.)(%w+)(:?)(%d*)(/?)([%w_.~!*:@&+$/?%%#=-]*))'
56-
    string.byte
56+
	do
57-
    string.char
57+
58-
    string.find
58+
		if IsURLBlackListed(prot, subd, tld, colon, port, slash, path)then
59-
    string.format
59+
			return true;
60-
    string.gmatch
60+
61-
    string.gsub
61+
62-
    string.len
62+
63-
    string.lower
63+
	return false;
64-
    string.match
64+
65-
    string.reverse
65+
66-
    string.sub
66+
local function IsUserWhitelisted(user)
67-
    string.upper
67+
68-
    table.insert
68+
	if UserStatus(user) == 2 then
69-
    table.maxn
69+
		return true;
70-
    table.remove
70+
	elseif type(MOD.UserWhiteList)~="table"then
71-
    table.sort
71+
		MOD.UserWhiteList = {};
72
		return false;
73-
Custom functions
73+
	elseif MOD.UserWhiteList[user:lower()] then
74
		return true;
75-
	ME(); -> returns the current user
75+
76-
	Channel(); -> returns the name of the channel we're in
76+
		return false;
77-
	print(string); -> adds string to the response
77+
78-
	GetUsers(); -> returns an array containing all the users in the channel
78+
79-
	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
79+
80-
	GetCommands() -> returns an array containing the available commands
80+
81-
	GetMsg(user) -> return the last message sent by the user, returns nil if none
81+
82-
	JSONEncode(tbl) -> returns the table as json encoded
82+
83-
	JSONDecode(data) -> decodes a json string into a table
83+
84-
	Timestamp() -> timestamp in CET
84+
85-
	Date(formatting,time) -> wrapper around os.date, if time is nil it takes the current time	
85+
86-
	HTML(html) -> decodes html to a lua table (https://github.com/luaforge/html/tree/master/html) as html.parsestr
86+
local function Join(user)
87
88-
	(MOD is only available to moderators in the channel)
88+
89
90-
	The timer functions are defined within this script!
90+
local function Leave(user)
91-
	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.
91+
92
end
93-
	he timer functions are defined within this script!
93+
94-
	MOD.GetTimers() -> returns an array containing the names of all running timers
94+
95
96-
	Get stream is defined inside of this script!
96+
	if UserStatus("kitsunebot") == 2 then
97-
	MOD.GetStream(nameofstream) -> returns a table or nil if the stream is live or not
97+
		if IsUserWhitelisted(user) then
98
			return;
99-
	MOD.GetVar(key,channel) -> returns a value from the database
99+
		elseif( GetHasBlacklistedURLs(msg) )then
100-
	MOD.SetVar(key,value,arrayid) -> Sets or updates a value in the database, arrayid is optional
100+
			MOD.Timer("to_"..user,0,function() MOD.Timeout(user); end);
101-
	MOD.DelVar(key) -> delete a value from the database
101+
			print("@"..user.." purged link");
102-
	MOD.GetArray(arrayid, chan, descending,limit, offset) -> returns a table containing key:values as set by SetVar with arrayid	
102+
103-
	MOD.DelArray(arrayid) -> deletes all records with the arrayid
103+
104
	end
105-
	MOD.GetGlobalVar(key) -> returns a value from the database, shared across all channels
105+
106-
	MOD.SetGlobalVar(key,value) -> Sets or updates a value in the database, shared across all channels
106+
107-
	MOD.DelGlobalVar(key) -> delete a value from the database, shared across all channels
107+
108
109-
	MOD.Commercial(sec) -> runs a commercial for sec (30|60|90|120|150|180) default is 30
109+
110-
	MOD.ResetCD(user) -> resets the cooldown, if a user is supplied it resets it for the user too
110+
111-
	MOD.HTTPGet(url) -> returns content and status, content is nil on failure
111+
MOD = MOD or {};
112-
	MOD.HTTPSGet(url) -> Same as above but HTTPS, returns body, code, headers, status in that order
112+
--These are called from the http://pastebin.com/y68mc6pM script
113
MOD.EventJoin = Join;
114-
	MOD.HTTPPost(url,headers,request_body) -> sends a post request, headers should be a table, request_body should be a string
114+
MOD.EventLeave = Leave;
115-
	MOD.HTTPSPost(url,headers,request_body) -> same as above but https/ssl
115+
MOD.EventMsg = Message;
116-
	-> POST functions returns string resource, number code, table response_headers, table response_body
116+
MOD.EventTick = Tick;
117
118-
	MOD.StartupScript(pastebintag*) -> Sets the channel's startup script
118+
--Commands
119-
	MOD.Save() -> Saves your commands and the saveable content in the MOD table
119+
MOD.AddCom("reg",function(msg,usr,chan)
120-
	MOD.Reload() -> Reloads/Resets the channel environment and reruns the startup script
120+
121
	if not msg or msg == "" or UserStatus(usr)~=2 then
122-
	MOD.AddCom(string,value); -> creates a command where string is the command without the !.
122+
123-
	if value is a function it must be defined beforehand or within the same chunk as AddCom, IE:
123+
124-
	AddCom("Test", function(msg,usr,channel) print("cat"); end); AddCom additionally runs MOD.Save automatically.
124+
125
	if type(MOD.UserWhiteList)~="table"then
126-
	AddCom passes the message, user and channel name in that order to its calling function.
126+
		MOD.UserWhiteList = {};
127
	end
128-
	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.
128+
129
	MOD.UserWhiteList[msg:lower()]=true;
130-
	MOD.Timeout(user,time) -> Timesout a user, if time isnt provided the timeout is 1 second (Kitsunebot must be a mod)
130+
131-
	MOD.Ban(user) -> perma bans user (Kitsunebot must be a mod)
131+
	print("@"..usr.. " user " .. msg .. " has been added to the regulars");
132-
	MOD.Unban(user) -> unbans a previously banned user (Kitsunebot must be a mod)
132+
133
	MOD.Save();
134-
	MOD.TimestampToSec(stamp) -> Convert a "yyyy-mm-ddThh:mm:ssZ" timestamp to unix
134+
135-
	MOD.SecondToSpan(unixtimestamp) -> Converts a unixtimestamp to timespan DD:HH:MM:SS
135+
end);
136
137-
	Additional notes:
137+
MOD.AddCom("unreg",function(msg,usr,chan)
138
139-
	pastebintag* = this is the last letters in a pastebin
139+
	if not msg or msg == "" or UserStatus(usr)~=2 then
140-
	for example the link to this script is http://pastebin.com/y68mc6pM
140+
141-
	the tag is as thus y68mc6pM
141+
142
143-
	The MOD table is only available for moderators and its contents (strings, numbers, tables)
143+
	if type(MOD.UserWhiteList)~="table"then
144-
	are saved when MOD.Save is called.
144+
		MOD.UserWhiteList = {};
145
	end
146-
	MOD.MODONLY (default false) if true kitsunebot will only respond to mods (custom commands included).
146+
147
	MOD.UserWhiteList[msg:lower()]=nil;
148-
	IE: !kitsunebot MOD.MODONLY=true (or false) to toggle it on or off.
148+
149
	print("@"..usr.. " user " .. msg .. " has been removed from the regulars");
150-
	MOD.COOLDOWN (default 15) The cooldown of which kitsunebot will respond to commands, channel mods are exempt from this cooldown
150+
151
	MOD.Save();
152-
	MOD.INDIVIDUAL_CD (default 20) same as above but for the individual user
152+
153
end);
154
155-
--Upvalue function
155+
MOD.AddCom("regurl",function(msg,usr,chan)
156-
local function Meow(msg,usr,chan)
156+
157
	if not msg or msg == "" or UserStatus(usr)~=2 then
158-
	--No param supplied
158+
159-
	if msg == "" then
159+
160-
		
160+
161-
		local stream = MOD.GetStream(chan:sub(2));
161+
	if type(MOD.URLWhiteList)~="table"then
162-
		local streamstatus ="";
162+
		MOD.URLWhiteList = {};
163-
		
163+
164-
		if stream == nil then
164+
165-
			streamstatus = "Stream not online";
165+
	if not GetHasBlacklistedURLs(msg) then
166-
		else 
166+
		print("URL already whitelisted or the format is invalid. Format should be: google.com");
167-
			streamstatus = "Stream is online with " .. tostring(stream.viewers) .. " viewers";
167+
168-
		end	
168+
169
170-
		print("MEOW! " .. usr .. " you are in " .. chan .. " there are " .. #GetUsers() .. " users in the chat! " .. streamstatus );
170+
	local pos, url, prot, subd, tld, colon, port, slash, path = msg:match('()(([%w_.~!*:@&+$/?%%#-]-)(%w[-.%w]*%.)(%w+)(:?)(%d*)(/?)([%w_.~!*:@&+$/?%%#=-]*))');
171
172
	subd = subd:lower();
173-
		--Special dumb cases
173+
	subd = subd:gsub("www.","");
174-
		if msg:lower() == usr:lower() then
174+
	subd = subd:sub(0,subd:len()-1);
175-
			print("MEOW! " .. usr .. " 4Head");
175+
176
	local website = subd.."."..tld;
177-
		elseif msg:lower() == "kitsunebot" then
177+
178-
			print("MEOW! " .. usr .. " Kreygasm" );
178+
	MOD.URLWhiteList[website:lower()]=true;
179
180
	print("@"..usr.. " URL " .. msg .. " has been whitelisted");
181
182-
		--Get the status 1 here, 2 mod, 0 not here
182+
	MOD.Save();
183-
		local status,title = UserStatus(msg);
183+
184
end);
185-
		if status == 1 then
185+
186-
			print("MEOW! " .. usr .. " " .. msg .. " is here!");
186+
MOD.AddCom("unregurl",function(msg,usr,chan)
187-
		elseif status == 2 then
187+
188-
			print("MEOW! " .. usr .. " " .. msg .. " is here as a "..title:lower().."!");
188+
	if not msg or msg == "" or UserStatus(usr)~=2 then
189-
		else
189+
190-
			print("MEOW! " .. usr .. " " .. msg .. " is not here!");
190+
191
192
	if type(MOD.URLWhiteList)~="table"then
193
		MOD.URLWhiteList = {};
194
	end
195-
--Helper function
195+
196
	local pos, url, prot, subd, tld, colon, port, slash, path = msg:match('()(([%w_.~!*:@&+$/?%%#-]-)(%w[-.%w]*%.)(%w+)(:?)(%d*)(/?)([%w_.~!*:@&+$/?%%#=-]*))');
197
198
	subd = subd:lower();
199
	subd = subd:gsub("www.","");
200
	subd = subd:sub(0,subd:len()-1);
201-
--Turn seconds into a span IE "hh:mm:ss"
201+
202-
local function SecondToSpan(sec)
202+
	local website = subd.."."..tld;
203
204-
        --Break out the components from the seconds
204+
	MOD.URLWhiteList[website:lower()]=nil;
205-
        local days = math.floor((sec/3600)/24);
205+
206-
                local hours = math.floor((sec/3600));
206+
	print("@"..usr.. " URL " .. msg .. " has been removed from the whitelist");
207-
        local mins = math.floor((sec-(hours*3600))/60);
207+
208-
        local seconds = math.floor(sec%60);
208+
	MOD.Save();
209
210-
        --Pad out the span with 0 when necessary
210+
end);