-- TUOCB (The Ultimate OpChat Bot by bastya_elvtars -- sorry did not optimize the PM command parsing part yet... l8r -- !invite - invite ppl temporarily -- !remove - remove from opchat -- !perminvite - invite till removed -- commands work in main and typed in opchat (wont show up) -- disable opchat in PtokaX if you wanna use this. -- enjoy opchatbot="-Op][Chat-" opchat={} userlevels={[-1]=1,[0]=5,[1]=4,[2]=3,[3]=2} -- usage permissions for inviting and removing ppl -- 5:only superops -- 4 ops & above -- 3 vips & above -- 2 registered users & above -- 1 anyone -- 0 disabled levinvite=5 levperminvite=5 levremove=5 -----------------------==============----------------------- function Main() GetOpChat() frmHub:RegBot(opchatbot) end function DataArrival(user,data) if strsub(data, 1, 4) == "$To:" then data=strsub(data,1,strlen(data)-1) -- is this meant for our bot? local _,_,whoTo = strfind(data,"$To:%s+(%S+)") if (whoTo == opchatbot) then opchatbasic(user,data) end elseif strsub(data, 1, 1) == "<" then data=strsub(data,1,strlen(data)-1) local _,_,cmd = strfind(data,"%b<>%s+[%!%+%#](%S+)") if cmd then returndata=parsecmds(user,data,strlower(cmd),"MAIN") end end end function opchatbasic(user,data) if user.bOperator then if not opchat[user.sName] then opchat[user.sName]=1 savefile(opchat,"opchat.ini") end end if not opchat[user.sName] and not user.bOperator then user:SendPM(opchatbot, "You can't post here!") return 1 else local _,_,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)") if cmd == "!invite" then invite(user, data, "PM","temp") return 1 elseif cmd=="!perminvite" then invite(user, data, "PM","perm") return 1 elseif cmd == "!remove" then removeopchat(user, data, "PM") return 1 elseif cmd=="!me" or cmd=="+me" or cmd=="/me" then local _,_,str = strfind(data, "^$To: %S+ From: %S+ $%b<>%s+%S+%s+(.*)$") if str then meopchat(user.sName,str) return 1 end else local _,_,str = strfind(data, "^$To: %S+ From: %S+ $%b<>%s+(.*)$") dochat(user.sName, str) end end end function dochat(from, str) for a,b in opchat do if from~= a then SendToNick(a, "$To: "..a.." From: "..opchatbot.." $<"..from.."> "..str.."|") end end Clear() end function meopchat(from, str) for a,b in opchat do SendToNick(a, "$To: "..a.." From: "..opchatbot.." $ * "..from.." "..str.."|") end Clear() end function invite(user, data, env,sess) if levinvite~=0 then if userlevels[user.iProfile] >= levinvite then local _,_,args=strfind(data,"%b<>%s+%S+%s+(.*)") if args then gsub(args, "(%S+)", function(nick) local tmp, bool = GetItemByName(nick), %opchat[nick] if tmp and not (tmp.bOperator and bool) then if %sess=="perm" and tmp.iProfile==2 then %opchat[nick]=1;SendPmToOps(opchatbot,nick.." has been perm. invited !") SendPmToNick(nick,opchatbot,"You are invited , you can take part in here until you get removed.") savefile(%opchat,"lawmaker/inifiles/opchat.ini") elseif %sess=="temp" then %opchat[nick]=1;SendPmToOps(opchatbot,nick.." has been temp. invited !") SendPmToNick(nick,opchatbot,"You are invited , you can take part in here for one session..") elseif tmp.iProfile~=2 then %user:SendData(parseenv(%user,%env,opchatbot)..nick.." is not a VIP, only VIPs can be invited for perm.") elseif tmp.bOperator then %user:SendData(parseenv(%user,%env,opchatbot)..nick.." is an OP, OPs get auto invitation ^^.") end elseif not tmp then %user:SendData(parseenv(%user,%env,opchatbot)..nick.." not online...") elseif bool or tmp.bOperator then %user:SendData(parseenv(%user,%env,opchatbot).."Already a member of opchat") end end) else user:SendData(parseenv(user,env,opchatbot).."Ok, but who to invite?") end else user:SendData(parseenv(user,env,opchatbot).."You do not have sufficient rights to run that command! |") end else user:SendData(parseenv(user,env,opchatbot).."That command is disabled.") end end function removeopchat(user, data, env,sess) if levinvite~=0 then if userlevels[user.iProfile] >= levremove then local _,_,args = strfind(data,"%b<>%s+%S+%s+(.*)") if args then gsub(args, "(%S+)", function(nick) local id,tmp = %opchat[nick],GetItemByName(nick) if id and not tmp.bOperator then %opchat[nick]=nil SendPmToOps(opchatbot,nick.." has been removed!") SendPmToNick(nick,opchatbot,"You are removed, so you cannot post here any longer.") savefile(%opchat,"lawmaker/inifiles/opchat.ini") elseif not tmp then %user:SendData(parseenv(%user,%env,opchatbot)..nick.." not online...") elseif not id then %user:SendData(parseenv(%user,%env,opchatbot)..nick.. "is not a member of opchat") elseif tmp.bOperator then %user:SendData(parseenv(%user,%env,opchatbot)..nick.."is an operator, operators cannot be removed.") end end) else user:SendData(parseenv(user,env,opchatbot).."Ok, but who to remove?") end else user:SendData(parseenv(user,env,opchatbot).."You do not have sufficient rights to run that command! |") end else user:SendData(parseenv(user,env,opchatbot).."That command is disabled.") end end function GetOpChat() loadfile(opchat,"lawmaker/inifiles/opchat.ini") local temptbl=loadusers() for a,b in temptbl do if not opchat[a] and(b==1 or b==0) then opchat[a]=1 end end savefile(opchat,"lawmaker/inifiles/opchat.ini") end function loadusers() local regusers={} readfrom("../RegisteredUsers.dat") while 1 do local line = read() if line == nil then readfrom() break end local _,_,name,levl = strfind(line,"(.+)|.+|(%d+)") regusers[name]=tonumber(levl) end readfrom() return regusers end function loadfile(table,file) table={} readfrom(file) while 1 do local line = read() if line == nil then readfrom() break end table[line] = 1 end readfrom() end function savefile(table,file) writeto(file) for a,b in table do write(a.."\n") end writeto() end function parsecmds(user,data,cmd,env) local commandtable={ ["invite"]= {invite,{user,data,env,"temp"}}, ["remove"]={removeopchat,{user,data,env}}, ["perminvite"]={invite,{user,data,env,"perm"}}} if commandtable[cmd] then call (commandtable[cmd][1],commandtable[cmd][2]) return 1 end end function parseenv(user,env,bot) if env=="PM" then return "$To: "..user.sName.." From: "..bot.." $<"..bot.."> " elseif env=="MAIN" then return "<"..bot.."> " end end