-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommandEngine.lua
More file actions
53 lines (53 loc) · 2.04 KB
/
commandEngine.lua
File metadata and controls
53 lines (53 loc) · 2.04 KB
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
commands={}
function checkPerms(cmdperms,usrhost)
for k,v in pairs(cmdperms) do
if users[usrhost].perms[k]==true then
return true
end
end
if users[usrhost].perms.owner or cmdperms[1]=="" or not cmdperms[1] then
return true
end
return false
end
function addcommand(commandName,commandFunc,commandPerms)
if not commandPerms then commandPerms={""} end
if not commandName then error "Command name not given!" end
if not commandFunc then error "Command function not given!" end
commands[commandName]={}
commands[commandName].func=commandFunc
commands[commandName].level=commandPerms
end
function commandEngine(usr,chan,msg)
if chan:sub(1,1)=="#" then target=chan else target=usr.nick end
if not users[usr.host] then
users[usr.host]={
identified=false,
perms={}
}
users[usr.host].perms[""]=true
end
print(string.format("[MESSAGE]\t[%s][%s]<%s> %s",os.date(),chan,usr.nick,msg))
called=false
if msg:sub(1,#config.cmdchar)==config.cmdchar and (users[usr.host].ignore==false or users[usr.host].ignore==nil) then
pre,cmd,rest = msg:match("^("..config.cmdchar..")([^%s]+)%s?(.*)$") -- thanks to cracker64
if not cmd then return end
args=split(rest," ")
print(string.format("[COMMAND]\t[%s][%s][%s]",usr.nick,cmd,rest))
if commands[cmd] then
if checkPerms(commands[cmd].level,usr.host) then
status,target,send=pcall(commands[cmd].func,usr,chan,msg,args)
if not status then
print(string.format("[ERROR]\t\t%s",split(target,"\n")[1]))
if chan:sub(1,1)=="#" then irc:sendChat(chan,split(target,"\n")[1]) else irc:sendChat(usr.nick,split(target,"\n")[1]) end
else
if target=="usr" then irc:sendChat(usr.nick,send) elseif target=="chan" then irc:sendChat(chan,send) end
end
else
irc:sendChat(target,string.format("%s, you do not have the required permissions for the command %q. You need one of the following capabilities to use this: %s",usr.nick,cmd,table.concat(commands[cmd].level," ")))
end
--[[else
irc:sendChat(target,string.format("%s, the command %q does not exist.",usr.nick,cmd))]]
end
end
end