READ THE RULES
0 Members and 1 Guest are viewing this topic.
--[[ 09-02-2008 ReleaseBot 1.0 LUA 5.11 [API 2] made by Daywalker Using some code snibbets from Sir Mutor cause i like that style and it's easy going imo :) Tnx to Plop to point me to the right table form :)) And as always CrazyGuy for listen to my mumbling about some code :P ]]RelCfg = {------------------------------- Main Settings ------------------------------------- Botname pulled from the hub or use "Custom-Name"Bot = SetMan.GetString(21),-- Hub NameHub = SetMan.GetString(0),-- Should bot have a key? true / falseBotIsOp = true,-- Bot descriptionBotDesc = "ReleaseBot",-- Bot Email addressBotMail = "release@genre.mp3",-- File to save Release tableRelFile = "Release.tbl",-- File to save Request tableReqFile = "Request.tbl",-- File to save Other stuff to tableBuFile = "BackBone.tbl",-- Context Menu TitleMenu = SetMan.GetString(0),-- Context Submenu TitlesSubMenu1 = "Release",SubMenu2 = "Request",-- activate show today release on connect true or falsesendrelease = true,-- send releases to main or pm "Main/Pm"HowToSend = "Pm",-- Time to clean a table in daysCleanTime = 14,------------------------------ Don't Try This At Home --------------------------}local minute = 60000local hour = 60*minutelocal day = 24*hourOnStartup = function() clean = TmrMan.AddTimer(day) RelCfg.Tz = TimeZone() RelCfg.Pfx = SetMan.GetString(29):sub(1,1) RelCfg.Path = string.gsub(Core.GetPtokaXPath().."scripts/ReleaseBot/","/","\\") RelCfg.RelFile = RelCfg.Path..RelCfg.RelFile RelCfg.ReqFile = RelCfg.Path..RelCfg.ReqFile RelCfg.BuFile = RelCfg.Path..RelCfg.BuFile gc,no = nil,table.getn if _VERSION ~= "Lua 5.1" then return OnError("Error! This script is incompatible with ".._VERSION), true end if loadfile(RelCfg.RelFile) then dofile(RelCfg.RelFile) Core.SendToOps("<"..RelCfg.Bot.."> *** Loading Release File....|") else RelCfg.Rel = {} Save_File(RelCfg.RelFile,RelCfg.Rel,"RelCfg.Rel") end if loadfile(RelCfg.ReqFile) then dofile(RelCfg.ReqFile) Core.SendToOps("<"..RelCfg.Bot.."> *** Loading Request File........|") else RelCfg.Req = {} Save_File(RelCfg.ReqFile,RelCfg.Req,"RelCfg.Req") end if loadfile(RelCfg.BuFile) then dofile(RelCfg.BuFile) Core.SendToOps("<"..RelCfg.Bot.."> *** Loading Genre File...............|") else RelCfg.Bu = {} Save_File(RelCfg.BuFile,RelCfg.Bu,"RelCfg.Bu") end if RelCfg.Bot ~= SetMan.GetString(21) or RelCfg.Bot == SetMan.GetString(21) and SetMan.GetBool(17) == false then Core.RegBot(RelCfg.Bot, RelCfg.BotDesc, RelCfg.BotMail, RelCfg.BotIsOp) end OnError("*** ReleaseBot 1.0RC1 LUA for ".._VERSION.." by Daywalker has been started...")endOnExit = function() OnError("*** ReleaseBot 1.0RC1 LUA for ".._VERSION.." by Daywalker has been stopped...")endOnError = function(msg) Core.SendToOps("<"..RelCfg.Bot.."> "..msg.."|")endfunction UserConnected(user, data) SendRelCmds(user) SendReqCmds(user) SendRel(user)endOpConnected = UserConnectedRegConnected = UserConnectedChatArrival = function(user, data) local s,e,cmd = string.find( data, "%b<> %p(%w+)") local s,e,to = string.find(data,"^$To: (%S+) From:") if cmd and RelCmds[cmd] then local _,_,_,tab = RelCmds[cmd]() if tab[user.iProfile] and tab[user.iProfile] == 1 then if to and to == RelCfg.Bot then Core.SendPmToNick(user.sNick,RelCfg.Bot,RelCmds[cmd](user,data).."|") --Core.SendToNick(user.sNick,"<"..RelCfg.Bot.."> "..message.."|") else local message = RelCmds[cmd](user,data) Core.SendToNick(user.sNick,"<"..RelCfg.Bot.."> "..message.."|") end collectgarbage("collect") return true end end if cmd and ReqCmds[cmd] then local _,_,_,tab = ReqCmds[cmd]() if tab[user.iProfile] and tab[user.iProfile] == 1 then if to and to == RelCfg.Bot then Core.SendPmToNick(user.sNick,RelCfg.Bot,ReqCmds[cmd](user,data).."|") --Core.SendToNick(user.sNick,"<"..RelCfg.Bot.."> "..message.."|") else local message = ReqCmds[cmd](user,data) Core.SendToNick(user.sNick,"<"..RelCfg.Bot.."> "..message.."|") end collectgarbage("collect") return true end endendToArrival = ChatArrivalRelCmds = { addgen = function(user,data) if user then local s,e,genre = string.find( data, "%b<> %p%w+%s(.*)|$") if not genre then return "Error!, Use: "..RelCfg.Pfx.. "addgen <genre>" else for i,v in pairs(RelCfg.Bu) do if v["Genre"] == genre then return "*** The genre: >> "..v["Genre"].." << is allready added to the ReleaseBot" end end if not RelCfg.Bu then RelCfg.Bu = {["Genre"] = genre} else spam = {["Genre"] = genre} table.insert(RelCfg.Bu,spam) end Core.SendToAll("<"..RelCfg.Bot.."> Genre: "..genre.." is added by "..user.sNick.." to the ReleaseBot|") Save_File(RelCfg.BuFile,RelCfg.Bu,"RelCfg.Bu") return "Genre: "..genre.." is added to the ReleaseBot|" end else return "Add A Genre"," %[line:Genre]"," %[line:Genre]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 0,[2] = 0,[3] = 0,[4] = 0,[5] = 0,[6] = 0,} end end, delgen = function(user,data) if user then local s,e,ID = string.find( data, "%b<> %p%w+%s(%d+)|$") if not ID then return "Error!, Use: "..RelCfg.Pfx.. "delgen <ID>" else local x for i,v in pairs(RelCfg.Bu) do if string.lower(i) == string.lower(ID) then x = i break end end if x then RelCfg.Bu[x] = nil Save_File(RelCfg.BuFile,RelCfg.Bu,"RelCfg.Bu") return "ID: "..x.." is deleted from Genre list" else return "ID: "..ID.." is not in the Genre list" end end else return "Delete A Genre"," %[line:ID]"," %[line:ID]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 0,[2] = 0,[3] = 0,[4] = 0,[5] = 0,[6] = 0,} end end, addrel = function(user,data) if user then local s,e,genre,release = string.find( data, "%b<> %p%w+%s(.*)%s(.*)|$") if not release then return "Error!, Use: "..RelCfg.Pfx.. "addrel <genre> <release>" else for i,v in pairs(RelCfg.Rel) do if v["Release"] == release then return "*** The release: >> "..v["Release"].." << is allready added to the ReleaseBot" end end for i,v in pairs(RelCfg.Bu) do if v["Genre"] == genre then ReleaseUpdate = { ["Genre"] = genre, ["Release"] = release, ["Name"] = user.sNick, ["Date"] = os.date(), ["Time"] = os.time(), } table.insert(RelCfg.Rel,ReleaseUpdate) Core.SendToAll("<"..RelCfg.Bot.."> Release: "..release.." is added by "..user.sNick.. " to the ReleaseBot under genre: "..v["Genre"].."|") Save_File(RelCfg.RelFile,RelCfg.Rel,"RelCfg.Rel") return "Release: "..release.." is added to releasebot|" else msg = "*** The genre: >> "..genre.." << is not available yet.." end end return msg end else return "Add A Release"," %[line:Genre] %[line:Release]"," %[line:Genre] %[line:Release]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 0,[4] = 0,[5] = 0,[6] = 0,} end end, delrel = function(user,data) if user then local s,e,ID = string.find( data, "%b<> %p%w+%s(%d+)|$") if not ID then return "Error!, Use: "..RelCfg.Pfx.. "delrel <ID>" else local x for i,v in pairs(RelCfg.Rel) do if string.lower(i) == string.lower(ID) then x = i break end end if x then RelCfg.Rel[x] = nil Save_File(RelCfg.RelFile,RelCfg.Rel,"RelCfg.Rel") return "ID: "..x.." is deleted from the ReleaseBot" else return "ID: "..ID.." is not in the ReleaseBot" end end else return "Delete A Release"," %[line:ID]"," %[line:ID]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 0,[4] = 0,[5] = 0,[6] = 0,} end end, gen = function(user,data) if user then if next(RelCfg.Bu) then local Count = 0 local reply = "Listing Genres ...\r\n\r\n\tID. ".. "\t\tGenre\r\n\t"..string.rep("Ż",25).."\r\n" for i,v in pairsByKeys(RelCfg.Bu) do reply = reply.."\tID: "..i.. "\t\t"..v["Genre"].."\r\n" end return reply.."\n\t"..string.rep("Ż",25).."\r\n\r\n" else return "There are no genres atm." end else return "Show Genres ","","", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end, rls = function(user,data) if user then local s,e,genre = string.find( data, "%b<> %p%w+%s(.*)|$") if not genre or genre == "" then if next(RelCfg.Rel) then local reply = "Listing All Releases ...\r\n\r\n\tID. ".. "\tGenre\tRelease\r\n\t"..string.rep("Ż",100).."\r\n" for i,v in pairsByKeys(RelCfg.Rel) do reply = reply.."\tID: "..i.."\t"..v["Genre"].."\t"..v["Release"].. " // Added by "..v["Name"].." at "..v["Date"].."\r\n" end return reply.."\n\t"..string.rep("Ż",100).."\r\n\r\n" else return "There are no releases atm." end else local reply = "Listing Releases by Genre...\r\n\r\n\tID. ".. "\t\tGenre\t\tRelease\r\n\t"..string.rep("Ż",100).."\r\n" for i,v in pairsByKeys(RelCfg.Rel) do if v["Genre"] == genre then reply = reply.."\tID: "..i.."\t\t"..v["Genre"].."\t\t"..v["Release"].. " // Added by "..v["Name"].." at "..v["Date"].."\r\n" end end return reply.."\n\t"..string.rep("Ż",100).."\r\n\r\n" end else return "Show releases (genre) "," %[line:Genre]"," %[line:Genre]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end, today = function(user,data) if user then local s,e,genre = string.find( data, "%b<> %p%w+%s(.*)|$") local od,pos,datesplit = string.find(os.date(), "%d+%/(%d+)%/%d+%s%d+%:%d+%:%d+") if not genre or genre == "" then if next(RelCfg.Rel) then local reply = "Listing All Releases of today ...\r\n\r\n\tID. ".. "\tGenre\tRelease\r\n\t"..string.rep("Ż",100).."\r\n" for i,v in pairsByKeys(RelCfg.Rel) do if v["Date"] then tb,pos,splittabledate = string.find(v["Date"], "%d+%/(%d+)%/%d+%s%d+%:%d+%:%d+") if splittabledate == datesplit then reply = reply.."\tID: "..i.."\t\t"..v["Genre"].."\t\t"..v["Release"].. " // Added by "..v["Name"].." at "..v["Date"].."\r\n" else x=1 end end end if x then --nice empty space to fool the bot^^ end return reply.."\n\t"..string.rep("Ż",100).."\r\n\r\n" else return "There are no releases for today atm." end else local reply = "Listing Today's Releases by Genre...\r\n\r\n\tID. ".. "\tGenre\tRelease\r\n\t"..string.rep("Ż",100).."\r\n" for i,v in pairsByKeys(RelCfg.Rel) do if v["Genre"] == genre then if v["Date"] then tb,pos,splittabledate = string.find(v["Date"], "%d+%/(%d+)%/%d+%s%d+%:%d+%:%d+") if splittabledate == datesplit then reply = reply.."\tID: "..i.."\t"..v["Genre"].."\t"..v["Release"].. " // Added by "..v["Name"].." at "..v["Date"].."\r\n" else x=1 end end end end if x then --nice empty space to fool the bot^^ end return reply.."\n\t"..string.rep("Ż",100).."\r\n\r\n" end else return "Show releases of today (genre) "," %[line:Genre]"," %[line:Genre]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end, rlshelp = function(user,data) if user then local x local reply = "\r\n\r\n\tRelease Command Help\r\n\r\n\tCommand\t\tDescription\r\n".. "\t"..string.rep("Ż",40).."\r\n" for i,v in pairsByKeys(RelCmds) do local desc,args,_,tab = RelCmds[i]() if tab[user.iProfile] and tab[user.iProfile] == 1 then x = 1 reply = reply.."\t!"..string.format("%-15s",i).."\t"..desc.."\r\n" end end if x then return reply.."\n\t"..string.rep("Ż",40).."\r\n\r\n" else return "Sorry "..user.sNick.." These commands are disabled for your profile." end else return "Show Release Help","","", -- Adjust To Your Profiles {[-1] = 1,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end, about = function(user,data) local reply = "\n\n\tAbout this script..\n".. "\t"..string.rep("Ż",40).."\r\n" if user then x=1 if x then reply = reply.."\t09-02-2008\n".. "\n\tReleaseBot 1.0 RC1 LUA 5.11 [API 2] made by Daywalker\n".. "\n\tUsing some code snibbets from Sir Mutor cause i like that style and it's easy going imo :)\n".. "\tTnx to Plop to point me to the right table form :))\n".. "\tAnd as always CrazyGuy for listen to my mumbling about some code :P\n".. "\n\tThis Script Release Candidate was Finished at 03/22/08 14:14:31 +1 UTC\n".. "\n\tExact Date and Time for now is: "..os.date().." "..RelCfg.Tz.."\n" end return reply.."\n\t"..string.rep("Ż",40).."\r\n\r\n" else return "Show about this script","","", -- profiles aan of uit {[-1] = 1,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end,}ReqCmds = { addreq = function(user,data) if user then local s,e,genre,request = string.find( data, "%b<> %p%w+%s(.*)%s(.*)|$") if not request then return "Error!, Use: "..RelCfg.Pfx.. "addreq <genre> <request>" else for i,v in pairs(RelCfg.Req) do if v["Request"] == request then return "*** The request: >> "..v["Request"].." << is allready added to the RequestBot" end end for i,v in pairs(RelCfg.Bu) do if v["Genre"] == genre then RequestUpdate = { ["Genre"] = genre, ["Request"] = request, ["Name"] = user.sNick, ["Date"] = os.date(), ["Time"] = os.time(), } table.insert(RelCfg.Rel,RequestUpdate) Core.SendToAll("<"..RelCfg.Bot.."> Request: "..request.." is added by "..user.sNick.. " to the RequestBot under genre: "..v["Genre"].."|") Save_File(RelCfg.ReqFile,RelCfg.Req,"RelCfg.Req") return "Done!!" else msg = "*** The genre: >> "..genre.." << is not available yet.." end end return msg end else return "Add A Request"," %[line:Genre] %[line:Request]"," %[line:Genre] %[line:Request]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 0,[4] = 0,[5] = 0,[6] = 0,} end end, delreq = function(user,data) if user then local s,e,ID = string.find( data, "%b<> %p%w+%s(%d+)|$") if not ID then return "Error!, Use: "..RelCfg.Pfx.. "delrel <ID>" else local x for i,v in pairs(RelCfg.Req) do if string.lower(i) == string.lower(ID) then x = i break end end if x then RelCfg.Req[x] = nil Save_File(RelCfg.ReqFile,RelCfg.Req,"RelCfg.Req") return "ID: "..x.." is deleted from the RequestBot" else return "ID: "..ID.." is not in the RequestBot" end end else return "Delete A Request"," %[line:ID]"," %[line:ID]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 0,[4] = 0,[5] = 0,[6] = 0,} end end, req = function(user,data) if user then local s,e,genre = string.find( data, "%b<> %p%w+%s(.*)|$") if not genre or genre == "" then if next(RelCfg.Req) then local reply = "Listing All Requests ...\r\n\r\n\tID. ".. "\t\tGenre\t\tRequest\r\n\t"..string.rep("Ż",100).."\r\n" for i,v in pairsByKeys(RelCfg.Req) do reply = reply.."\tID: "..i.."\t\t"..v["Genre"].."\t\t"..v["Request"].. " // Added by "..v["Name"].." at "..v["Date"].."\r\n" end return reply.."\n\t"..string.rep("Ż",100).."\r\n\r\n" else return "There are no requests atm." end else local reply = "Listing Requests by Genre...\r\n\r\n\tID. ".. "\t\tGenre\t\tRequest\r\n\t"..string.rep("Ż",100).."\r\n" for i,v in pairsByKeys(RelCfg.Req) do if v["Genre"] == genre then reply = reply.."\tID: "..i.."\t\t"..v["Genre"].."\t\t"..v["Request"].. " // Added by "..v["Name"].." at "..v["Date"].."\r\n" end end return reply.."\n\t"..string.rep("Ż",100).."\r\n\r\n" end else return "Show requests (genre) "," %[line:Genre]"," %[line:Genre]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end, reqhelp = function(user,data) if user then local x local reply = "\r\n\r\n\tRequest Command Help\r\n\r\n\tCommand\t\tDescription\r\n".. "\t"..string.rep("Ż",40).."\r\n" for i,v in pairsByKeys(ReqCmds) do local desc,args,_,tab = ReqCmds[i]() if tab[user.iProfile] and tab[user.iProfile] == 1 then x = 1 reply = reply.."\t!"..string.format("%-15s",i).."\t"..desc.."\r\n" end end if x then return reply.."\n\t"..string.rep("Ż",40).."\r\n\r\n" else return "Sorry "..user.sNick.." These commands are disabled for your profile." end else return "Show Request Help","","", -- profiles aan of uit {[-1] = 1,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end, about = function(user,data) local reply = "\n\n\tAbout this script..\n".. "\t"..string.rep("Ż",40).."\r\n" if user then x=1 if x then reply = reply.."\t09-02-2008\n".. "\n\tReleaseBot 1.0 RC1 LUA 5.11 [API 2] made by Daywalker\n".. "\n\tUsing some code snibbets from Sir Mutor cause i like that style and it's easy going imo :)\n".. "\tTnx to Plop to point me to the right table form :))\n".. "\tAnd as always CrazyGuy for listen to my mumbling about some code :P\n".. "\n\tThis Script Release Candidate was Finished at 03/22/08 14:14:31 UTC + 1\n".. "\tExact Date and Time for now is: "..os.date().."\n" end return reply.."\n\t"..string.rep("Ż",40).."\r\n\r\n" else return "Show about this script","","", -- profiles aan of uit {[-1] = 1,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end,}SendRelCmds = function(user) local x for i,v in pairsByKeys(RelCmds) do local desc,arg1,arg2,tab = RelCmds[i]() if tab[user.iProfile] and tab[user.iProfile] == 1 then x = 1 Core.SendToNick(user.sNick,"$UserCommand 1 1 "..RelCfg.Menu.."\\"..RelCfg.SubMenu1.."\\".. desc.."$<%[mynick]> +"..i..arg1.."||") Core.SendToNick(user.sNick,"$UserCommand 1 2 "..RelCfg.Menu.."\\"..RelCfg.SubMenu1.."\\".. desc.."$$To: "..RelCfg.Bot.." From: %[mynick] $<%[mynick]> +"..i..arg2.."||") end end if x then local Prof if user.iProfile ~= -1 then Prof = ProfMan.GetProfile(user.iProfile).sProfileName else Prof = "Unregistered User" end end collectgarbage("collect")endSendReqCmds = function(user) local x for i,v in pairsByKeys(ReqCmds) do local desc,arg1,arg2,tab = ReqCmds[i]() if tab[user.iProfile] and tab[user.iProfile] == 1 then x = 1 Core.SendToNick(user.sNick,"$UserCommand 1 1 "..RelCfg.Menu.."\\"..RelCfg.SubMenu2.."\\".. desc.."$<%[mynick]> +"..i..arg1.."||") Core.SendToNick(user.sNick,"$UserCommand 1 2 "..RelCfg.Menu.."\\"..RelCfg.SubMenu2.."\\".. desc.."$$To: "..RelCfg.Bot.." From: %[mynick] $<%[mynick]> +"..i..arg2.."||") end end if x then local Prof if user.iProfile ~= -1 then Prof = ProfMan.GetProfile(user.iProfile).sProfileName else Prof = "Unregistered User" end end collectgarbage("collect")endSendRel = function(user) if RelCfg.sendrelease == true then if user then local od,pos,datesplit = string.find(os.date(), "%d+%/(%d+)%/%d+%s%d+%:%d+%:%d+") local reply = "Listing All Today Releases ...\r\n\r\n\tID. ".. "\tGenre\tRelease\r\n\t"..string.rep("Ż",100).."\r\n" for i,v in pairsByKeys(RelCfg.Rel) do if v["Date"] then tb,pos,splittabledate = string.find(v["Date"], "%d+%/(%d+)%/%d+%s%d+%:%d+%:%d+") if splittabledate == datesplit then reply = reply.."\tID: "..i.."\t"..v["Genre"].."\t"..v["Release"].. " // Added by "..v["Name"].." at "..v["Date"].."\r\n" else x=1 end end end if x then --nice empty space to fool the bot^^ end if RelCfg.HowToSend == "Main" then Core.SendToNick(user.sNick,"<"..RelCfg.Bot.."> "..reply.."\n\t"..string.rep("Ż",100).."\r\n\r\n") else Core.SendPmToNick(user.sNick,RelCfg.Bot,reply.."\n\t"..string.rep("Ż",100).."\r\n\r\n") end end else endendOnTimer = function(clean) if clean then local cur,chg = os.time() Core.SendToAll("<"..RelCfg.Bot.."> Release cleaner started at "..os.date()) for i,v in pairs(RelCfg.Rel) do local td = os.difftime(os.time(),v["Time"]) local what = (td/86400) local TtoGo = (RelCfg.CleanTime-what) if what > RelCfg.CleanTime then --message Core.SendToAll("<"..RelCfg.Bot.."> Release: "..v["Release"].." is deleted from the releasebot") table.remove(i) RelCfg.Rel[i] = nil chg = true end end Core.SendToAll("<"..RelCfg.Bot.."> Request cleaner started at "..os.date()) local cur2,chg2 = os.time() for i,v in pairs(RelCfg.Req) do local td = os.difftime(os.time(),v["Time"]) local what = (td/86400) local TtoGo = (RelCfg.CleanTime-what) if what > RelCfg.CleanTime then --message Core.SendToAll("<"..RelCfg.Bot.."> Request: "..v["Request"].." is deleted from the requestbot") table.remove(i) RelCfg.Req[i] = nil chg2 = true end end if chg then Save_File(RelCfg.RelFile,RelCfg.Rel,"BlCfg.Rel") else Core.SendToAll("<"..RelCfg.Bot.."> There are no Releases to delete yet, maybe next time..") end if chg2 then Save_File(RelCfg.ReqFile,RelCfg.Req,"RelCfg.Req") else Core.SendToAll("<"..RelCfg.Bot.."> There are no Requests to delete yet, maybe next time..") end endendCountPairs = function(Table) local x = 0 if Table then for i,v in pairs(Table) do x = x + 1 end end return xendTimeZone = function() local h,m = math.modf((os.time()-os.time(os.date"!*t"))/ 3600) return string.format("%+d UTC",(h + (60 * m)))endSave_Serialize = function(tTable, sTableName, hFile, sTab) sTab = sTab or ""; hFile:write(sTab..sTableName.." = {\n" ) for key, value in pairs(tTable) do local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key) if(type(value) == "table") then Save_Serialize(value, sKey, hFile, sTab.."\t") else local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value) hFile:write( sTab.."\t"..sKey.." = "..sValue) end hFile:write( ",\n") end hFile:write( sTab.."}")endSave_File = function(file,table, tablename ) local hFile = io.open (file , "wb") Save_Serialize(table, tablename, hFile) hFile:flush() hFile:close() collectgarbage("collect")endpairsByKeys = function(t, f) local a = {} for n in pairs(t) do table.insert(a, n) end table.sort(a, f) local i = 0 -- iterator variable local iter = function () -- iterator function i = i + 1 if a[i] == nil then return nil else return a[i], t[a[i]] end end return iterend
RelCfg = {------------------------------- Main Settings ------------------------------------- Botname pulled from the hub or use "Custom-Name"Bot = SetMan.GetString(21),-- Hub NameHub = SetMan.GetString(0),-- Should bot have a key? true / false
-- Botname pulled from the hub or use "Custom-Name"
--[[ 09-02-2008 ReleaseBot 1.0 LUA 5.11 [API 2] made by Daywalker Using some code snibbets from Sir Mutor cause i like that style and it's easy going imo :) Tnx to Plop to point me to the right table form :)) And as always CrazyGuy for listen to my mumbling about some code :P - RC2: * Added the !findrel command (finds all the Releases including the word you searched for) * Added the !prunerel and !prunereq commands to maually prune the tabled by day * Fixed the TableCleaner cause it didn't work properly * Fixed the start script error when hub is not running * Fixed or Added (that's how you look against it^^) the hFile error when Folder isn't there yet... script will search for Folder first and will create it first now. * Added version number for script ]]RelCfg = {------------------------------- Main Settings ------------------------------------- Botname if "" then it will be pulled from the hub or use "Custom-Name"Bot = "",-- Hub Name if "" then it will be set to hubnameHub = "",-- Should bot have a key? true / falseBotIsOp = true,-- Bot descriptionBotDesc = "ReleaseBot",-- Bot Email addressBotMail = "release@genre.mp3",-- Script versionVersion = "1.0RC2",-- folder for DBFolder = "ReleaseBot",-- File to save Release tableRelFile = "Release.tbl",-- File to save Request tableReqFile = "Request.tbl",-- File to save Other stuff to tableBuFile = "BackBone.tbl",-- Context Menu Title if "" then it will be set to hubnameMenu = "",-- Context Submenu TitlesSubMenu1 = "Release",SubMenu2 = "Request",-- activate show today release on connect true or falsesendrelease = true,-- send releases to main or pm "Main/Pm"HowToSend = "Pm",-- Time to clean a table in daysCleanTime = 8,-- Time to do the cleaning repeatly [ 24*(60*60000) = 1 day]DoClean = 24*(60*60000),------------------------------ Don't Try This At Home --------------------------}OnStartup = function() if RelCfg.Bot == "" then RelCfg.Bot = SetMan.GetString(21) end if RelCfg.Menu == "" then RelCfg.Menu = SetMan.GetString(0) end if RelCfg.Hub == "" then RelCfg.Hub = SetMan.GetString(0) end clean = TmrMan.AddTimer(RelCfg.DoClean) RelCfg.Tz = TimeZone() RelCfg.Pfx = SetMan.GetString(29):sub(1,1) RelCfg.Path = string.gsub(Core.GetPtokaXPath().."scripts/"..RelCfg.Folder.."/","/","\\") RelCfg.RelFile = RelCfg.Path..RelCfg.RelFile RelCfg.ReqFile = RelCfg.Path..RelCfg.ReqFile RelCfg.BuFile = RelCfg.Path..RelCfg.BuFile gc,no = nil,table.getn if _VERSION ~= "Lua 5.1" then return OnError("Error! This script is incompatible with ".._VERSION), true end if loadfile(RelCfg.RelFile) then dofile(RelCfg.RelFile) Core.SendToOps("<"..RelCfg.Bot.."> *** Loading Release File....|") else os.execute("mkdir "..RelCfg.Folder) Core.SendToOps("<"..RelCfg.Bot.."> *** Scanning script folder.."..RelCfg.Folder.." not found, Creating "..RelCfg.Folder.." now....|") RelCfg.Rel = {} Save_File(RelCfg.RelFile,RelCfg.Rel,"RelCfg.Rel") Core.SendToOps("<"..RelCfg.Bot.."> *** The folder "..RelCfg.Folder.." is created..inserting files now..|") Core.SendToOps("<"..RelCfg.Bot.."> *** "..RelCfg.RelFile.." file inserted..|") end if loadfile(RelCfg.ReqFile) then dofile(RelCfg.ReqFile) Core.SendToOps("<"..RelCfg.Bot.."> *** Loading Request File........|") else RelCfg.Req = {} Save_File(RelCfg.ReqFile,RelCfg.Req,"RelCfg.Req") Core.SendToOps("<"..RelCfg.Bot.."> *** "..RelCfg.ReqFile.." file inserted..|") end if loadfile(RelCfg.BuFile) then dofile(RelCfg.BuFile) Core.SendToOps("<"..RelCfg.Bot.."> *** Loading Genre File...............|") else RelCfg.Bu = {} Save_File(RelCfg.BuFile,RelCfg.Bu,"RelCfg.Bu") Core.SendToOps("<"..RelCfg.Bot.."> *** "..RelCfg.BuFile.." file inserted..|") end if RelCfg.Bot ~= SetMan.GetString(21) or RelCfg.Bot == SetMan.GetString(21) and SetMan.GetBool(17) == false then Core.RegBot(RelCfg.Bot, RelCfg.BotDesc, RelCfg.BotMail, RelCfg.BotIsOp) end OnError("*** ReleaseBot "..RelCfg.Version.." for ".._VERSION.." by Daywalker has been started...")endOnExit = function() OnError("*** ReleaseBot "..RelCfg.Version.." for ".._VERSION.." by Daywalker has been stopped...")endOnError = function(msg) Core.SendToOps("<"..RelCfg.Bot.."> "..msg.."|")endfunction UserConnected(user, data) SendRelCmds(user) SendReqCmds(user) SendRel(user)endOpConnected = UserConnectedRegConnected = UserConnectedChatArrival = function(user, data) local s,e,cmd = string.find( data, "%b<> %p(%w+)") local s,e,to = string.find(data,"^$To: (%S+) From:") if cmd and RelCmds[cmd] then local _,_,_,tab = RelCmds[cmd]() if tab[user.iProfile] and tab[user.iProfile] == 1 then if to and to == RelCfg.Bot then Core.SendPmToNick(user.sNick,RelCfg.Bot,RelCmds[cmd](user,data).."|") else local message = RelCmds[cmd](user,data) Core.SendToNick(user.sNick,"<"..RelCfg.Bot.."> "..message.."|") end collectgarbage("collect") return true end end if cmd and ReqCmds[cmd] then local _,_,_,tab = ReqCmds[cmd]() if tab[user.iProfile] and tab[user.iProfile] == 1 then if to and to == RelCfg.Bot then Core.SendPmToNick(user.sNick,RelCfg.Bot,ReqCmds[cmd](user,data).."|") else local message = ReqCmds[cmd](user,data) Core.SendToNick(user.sNick,"<"..RelCfg.Bot.."> "..message.."|") end collectgarbage("collect") return true end endendToArrival = ChatArrivalRelCmds = { addgen = function(user,data) if user then local s,e,genre = string.find( data, "%b<> %p%w+%s(.*)|$") if not genre then return "Error!, Use: "..RelCfg.Pfx.. "addgen <genre>" else for i,v in pairs(RelCfg.Bu) do if v["Genre"] == genre then return "*** The genre: >> "..v["Genre"].." << is allready added to the ReleaseBot" end end if not RelCfg.Bu then RelCfg.Bu = {["Genre"] = genre} else spam = {["Genre"] = genre} table.insert(RelCfg.Bu,spam) end Core.SendToAll("<"..RelCfg.Bot.."> Genre: "..genre.." is added by "..user.sNick.." to the ReleaseBot|") Save_File(RelCfg.BuFile,RelCfg.Bu,"RelCfg.Bu") return "Genre: "..genre.." is added to the ReleaseBot|" end else return "Add A Genre"," %[line:Genre]"," %[line:Genre]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 0,[2] = 0,[3] = 0,[4] = 0,[5] = 0,[6] = 0,} end end, delgen = function(user,data) if user then local s,e,ID = string.find( data, "%b<> %p%w+%s(%d+)|$") if not ID then return "Error!, Use: "..RelCfg.Pfx.. "delgen <ID>" else local x for i,v in pairs(RelCfg.Bu) do if string.lower(i) == string.lower(ID) then x = i break end end if x then RelCfg.Bu[x] = nil Save_File(RelCfg.BuFile,RelCfg.Bu,"RelCfg.Bu") return "ID: "..x.." is deleted from Genre list" else return "ID: "..ID.." is not in the Genre list" end end else return "Delete A Genre"," %[line:ID]"," %[line:ID]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 0,[2] = 0,[3] = 0,[4] = 0,[5] = 0,[6] = 0,} end end, addrel = function(user,data) if user then local s,e,genre,release = string.find( data, "%b<> %p%w+%s(.*)%s(.*)|$") if not release then return "Error!, Use: "..RelCfg.Pfx.. "addrel <genre> <release>" else for i,v in pairs(RelCfg.Rel) do if v["Release"] == release then return "*** The release: >> "..v["Release"].." << is allready added to the ReleaseBot" end end for i,v in pairs(RelCfg.Bu) do if v["Genre"] == genre then ReleaseUpdate = {["Genre"] = genre,["Release"] = release,["Name"] = user.sNick,["Date"] = os.date(),["Time"] = os.time(),} table.insert(RelCfg.Rel,ReleaseUpdate) Core.SendToAll("<"..RelCfg.Bot.."> Release: "..release.." is added by "..user.sNick.." to the ReleaseBot under genre: "..v["Genre"].."|") Save_File(RelCfg.RelFile,RelCfg.Rel,"RelCfg.Rel") return "Release: "..release.." is added to releasebot|" else msg = "*** The genre: >> "..genre.." << is not available yet.." end end return msg end else return "Add A Release"," %[line:Genre] %[line:Release]"," %[line:Genre] %[line:Release]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 0,[4] = 0,[5] = 0,[6] = 0,} end end, delrel = function(user,data) if user then local s,e,ID = string.find( data, "%b<> %p%w+%s(%d+)|$") if not ID then return "Error!, Use: "..RelCfg.Pfx.. "delrel <ID>" else local x for i,v in pairs(RelCfg.Rel) do if string.lower(i) == string.lower(ID) then x = i break end end if x then RelCfg.Rel[x] = nil Save_File(RelCfg.RelFile,RelCfg.Rel,"RelCfg.Rel") return "ID: "..x.." is deleted from the ReleaseBot" else return "ID: "..ID.." is not in the ReleaseBot" end end else return "Delete A Release"," %[line:ID]"," %[line:ID]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 0,[4] = 0,[5] = 0,[6] = 0,} end end, prunerel = function(user,data) if user then local s,e,prune = string.find( data, "%b<> %p%w+%s(%d+)|$") if not prune then return "Error!, Use: "..RelCfg.Pfx.. "prunerel <days>" else local cur,chg = os.time() local msg = "\n\t"..string.rep("=",130).. "\n\t\t\t\t\t- Listing Deleted Releases Older Then "..prune.." Days-".. "\n\t"..string.rep("-",260).."\n" for i,v in pairs(RelCfg.Rel) do local td = os.difftime(os.time(),v["Time"]) local what = (td/86400) local TtoGo = (tonumber(prune)-what) if what > tonumber(prune) then --message msg = msg.."\tRelease: "..v["Release"].." is deleted from the releasebot\n" table.remove(RelCfg.Rel[i]) RelCfg.Rel[i] = nil chg = true end end if chg then Save_File(RelCfg.RelFile,RelCfg.Rel,"RelCfg.Rel") Core.SendToAll("<"..RelCfg.Bot.."> "..user.sNick.." Deleted All Releases Older then "..prune.." Days") return msg.."\n\t"..string.rep("Ż",130).."\r\n\r\n" end return "There Are No Releases To Delete Yet!!\n" end else return "Clean release table"," %[line:Days to prune]"," %[line:Days to prune]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 0,[3] = 0,[4] = 0,[5] = 0,[6] = 0,} end end, prunereq = function(user,data) if user then local s,e,prune = string.find( data, "%b<> %p%w+%s(%d+)|$") if not prune then return "Error!, Use: "..RelCfg.Pfx.. "prunereq <days>" else local cur,chg = os.time() local msg = "\n\t"..string.rep("=",130).. "\n\t\t\t\t\t- Listing Deleted Requests Older Then "..prune.." Days-".. "\n\t"..string.rep("-",260).."\n" for i,v in pairs(RelCfg.Req) do local td = os.difftime(os.time(),v["Time"]) local what = (td/86400) local TtoGo = (tonumber(prune)-what) if what > tonumber(prune) then --message msg = msg.."\tRequest: "..v["Request"].." is deleted from the releasebot\n" table.remove(RelCfg.Req[i]) RelCfg.Req[i] = nil chg = true end end if chg then Save_File(RelCfg.ReqFile,RelCfg.Req,"RelCfg.Req") Core.SendToAll("<"..RelCfg.Bot.."> "..user.sNick.." Deleted All Requests Older then "..prune.." Days") return msg.."\n\t"..string.rep("Ż",130).."\r\n\r\n" end return "*** There Are No Requests To Delete Yet!!\n" end else return "Clean request table"," %[line:Days to prune]"," %[line:Days to prune]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 0,[3] = 0,[4] = 0,[5] = 0,[6] = 0,} end end, gen = function(user,data) if user then if next(RelCfg.Bu) then local Count = 0 local reply = "\n\t\t"..string.rep("=",30).. "\n\t\t\t- Listing Genres -".. "\n\t\t"..string.rep("-",60).."\n".. "\n\t\tID.\t\tGenre\n\t\t"..string.rep("Ż",30).."\r\n" for i,v in pairsByKeys(RelCfg.Bu) do reply = reply.."\t\tID: "..i.. "\t\t"..v["Genre"].."\r\n" end return reply.."\n\t\t"..string.rep("Ż",30).."\r\n\r\n" else return "There are no genres atm." end else return "Show Genres ","","", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end, rls = function(user,data) if user then local s,e,genre = string.find( data, "%b<> %p%w+%s(.*)|$") if not genre or genre == "" then if next(RelCfg.Rel) then local reply = "\n\t"..string.rep("=",100).. "\n\t\t\t\t\t- Listing All Releases -".. "\n\t"..string.rep("-",200).."\n".. "\n\tID\t\tGenre\t\tRelease\r\n\t"..string.rep("Ż",100).."\r\n" for i,v in pairsByKeys(RelCfg.Rel) do reply = reply.."\tID: "..i.."\t"..v["Genre"].."\t"..v["Release"].." // Added by "..v["Name"].." at "..v["Date"].."\r\n" end return reply.."\n\t"..string.rep("Ż",100).."\r\n\r\n" else return "There are no releases atm." end else local reply = "Listing Releases by Genre...\r\n\r\n\tID. ".. "\t\tGenre\t\tRelease\r\n\t"..string.rep("Ż",100).."\r\n" for i,v in pairsByKeys(RelCfg.Rel) do if v["Genre"] == genre then reply = reply.."\tID: "..i.."\t\t"..v["Genre"].."\t\t"..v["Release"].." // Added by "..v["Name"].." at "..v["Date"].."\r\n" end end return reply.."\n\t"..string.rep("Ż",100).."\r\n\r\n" end else return "Show releases (genre) "," %[line:Genre]"," %[line:Genre]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end, today = function(user,data) if user then local s,e,genre = string.find( data, "%b<> %p%w+%s(.*)|$") local od,pos,datesplit = string.find(os.date(), "%d+%/(%d+)%/%d+%s%d+%:%d+%:%d+") if not genre or genre == "" then if next(RelCfg.Rel) then local reply = "\n\t"..string.rep("=",100).. "\n\t\t\t\t\t- Listing All Releases of today -".. "\n\t"..string.rep("-",200).."\n".. "\n\tID\t\tGenre\t\tRelease\r\n\t"..string.rep("Ż",100).."\r\n" for i,v in pairsByKeys(RelCfg.Rel) do if v["Date"] then tb,pos,splittabledate = string.find(v["Date"], "%d+%/(%d+)%/%d+%s%d+%:%d+%:%d+") if splittabledate == datesplit then reply = reply.."\tID: "..i.."\t\t"..v["Genre"].."\t\t"..v["Release"].." // Added by "..v["Name"].." at "..v["Date"].."\r\n" else x=1 end end end if x then --nice empty space to fool the bot^^ end return reply.."\n\t"..string.rep("Ż",100).."\r\n\r\n" else return "There are no releases for today atm." end else local reply = "Listing Today's Releases by Genre...\r\n\r\n\tID. ".. "\tGenre\tRelease\r\n\t"..string.rep("Ż",100).."\r\n" for i,v in pairsByKeys(RelCfg.Rel) do if v["Genre"] == genre then if v["Date"] then tb,pos,splittabledate = string.find(v["Date"], "%d+%/(%d+)%/%d+%s%d+%:%d+%:%d+") if splittabledate == datesplit then reply = reply.."\tID: "..i.."\t"..v["Genre"].."\t"..v["Release"].." // Added by "..v["Name"].." at "..v["Date"].."\r\n" else x=1 end end end end if x then --nice empty space to fool the bot^^ end return reply.."\n\t"..string.rep("Ż",100).."\r\n\r\n" end else return "Show releases of today (genre) "," %[line:Genre]"," %[line:Genre]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end, findrel = function(user,data) if user then local s,e,rel = string.find( data, "%b<> %p%w+%s(.*)|$") if not rel then return "Error!, Use: "..RelCfg.Pfx.. "findrel <releasename or a word init>" else local msg = "\n\t\t"..string.rep("=",80).. "\n\t\t\t\t\t- Search Results for the word ["..rel.."] -".. "\n\t\t"..string.rep("-",160).."\r\n" for i,v in pairsByKeys(RelCfg.Rel) do --if string.lower(v["Release"]) == string.lower(rel) then if string.find(string.lower(v["Release"]),rel) then msg = msg.."\r\n\r\n\t\tInfo on the Release: "..v["Release"].." :\n".. "\r\n\t\t"..string.rep("Ż",80).. "\r\n\t\t- Known ID\t\t: "..i.. "\r\n\t\t- Full Releasename\t: "..v["Release"].. "\r\n\t\t- Genre\t\t: "..v["Genre"].. "\r\n\t\t- Added by\t: "..v["Name"].. "\r\n\t\t- Time of Add\t: "..v["Date"].. "\r\n\r\n\t\t"..string.rep("Ż",80).."\r\n" else x=1 end end if x then return msg.."\n\t\t"..string.rep("-",160).."\r\n\r\n" else return "The Release: <"..rel.."> is not found." end end else return "Find A Release"," %[line:Release]"," %[line:Release]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end DownloadFile() end, rlshelp = function(user,data) if user then local x local reply = "\n\t\t"..string.rep("=",40).. "\n\t\t\t- Release Command Help-".. "\n\t\t"..string.rep("-",80).. "\n\t\tCommand\t\tDescription\r\n".. "\t\t"..string.rep("Ż",40).."\r\n" for i,v in pairsByKeys(RelCmds) do local desc,args,_,tab = RelCmds[i]() if tab[user.iProfile] and tab[user.iProfile] == 1 then x = 1 reply = reply.."\t\t!"..string.format("%-15s",i).."\t"..desc.."\r\n" end end if x then return reply.."\n\t\t"..string.rep("Ż",40).."\r\n\r\n" else return "Sorry "..user.sNick.." These commands are disabled for your profile." end else return "Show Release Help","","", -- profiles aan of uit {[-1] = 1,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end, relabout = function(user,data) local reply = "\n\t\t"..string.rep("=",60).. "\n\n\t\t\t\t\t-About this script-".. "\n\t\t"..string.rep("-",120).."\n" if user then x=1 local FileSize1 = CheckFile(RelCfg.BuFile) local FileSize2 = CheckFile(RelCfg.RelFile) local FileSize3 = CheckFile(RelCfg.ReqFile) if x then reply = reply.."\t\t09-02-2008\n".. "\n\t\tReleaseBot "..RelCfg.Version.." ".._VERSION.." [API 2] made by Daywalker\n".. "\n\t\tUsing some code snibbets from Sir Mutor cause i like that style and it's easy going imo :)\n".. "\t\tTnx to Plop to point me to the right table form :))\n".. "\t\tAnd as always CrazyGuy for listen to my mumbling about some code :P\n".. "\n\t\tThis Script Release Candidate was Finished at 04/05/08 16:44:24 +1 UTC".. "\n\t\tExact Date and Time for now is: "..os.date().." "..RelCfg.Tz.. "\n\t\tScript uses "..Mem().." atm.".. "\n\n\t\tCurrent File Sizes are for:".. "\n\t\t"..string.rep("~",25).. "\n\t\t- Genre file\t: "..FileSize1.. "\n\t\t- Release file\t: "..FileSize2.. "\n\t\t- Request file\t: "..FileSize3.. "\n\t\t"..string.rep("~",25).."\n" end return reply.."\n\t\t"..string.rep("Ż",60).."\r\n\r\n" else return "Show about this script","","", -- profiles aan of uit {[-1] = 1,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end,}ReqCmds = { addreq = function(user,data) if user then local s,e,genre,request = string.find( data, "%b<> %p%w+%s(.*)%s(.*)|$") if not request then return "Error!, Use: "..RelCfg.Pfx.. "addreq <genre> <request>" else for i,v in pairs(RelCfg.Req) do if v["Request"] == request then return "*** The request: >> "..v["Request"].." << is allready added to the RequestBot" end end for i,v in pairs(RelCfg.Bu) do if v["Genre"] == genre then RequestUpdate = {["Genre"] = genre,["Request"] = request,["Name"] = user.sNick,["Date"] = os.date(),["Time"] = os.time(),} table.insert(RelCfg.Rel,RequestUpdate) Core.SendToAll("<"..RelCfg.Bot.."> Request: "..request.." is added by "..user.sNick.." to the RequestBot under genre: "..v["Genre"].."|") Save_File(RelCfg.ReqFile,RelCfg.Req,"RelCfg.Req") return "Done!!" else msg = "*** The genre: >> "..genre.." << is not available yet.." end end return msg end else return "Add A Request"," %[line:Genre] %[line:Request]"," %[line:Genre] %[line:Request]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 0,[4] = 0,[5] = 0,[6] = 0,} end end, delreq = function(user,data) if user then local s,e,ID = string.find( data, "%b<> %p%w+%s(%d+)|$") if not ID then return "Error!, Use: "..RelCfg.Pfx.. "delrel <ID>" else local x for i,v in pairs(RelCfg.Req) do if string.lower(i) == string.lower(ID) then x = i break end end if x then RelCfg.Req[x] = nil Save_File(RelCfg.ReqFile,RelCfg.Req,"RelCfg.Req") return "ID: "..x.." is deleted from the RequestBot" else return "ID: "..ID.." is not in the RequestBot" end end else return "Delete A Request"," %[line:ID]"," %[line:ID]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 0,[4] = 0,[5] = 0,[6] = 0,} end end, req = function(user,data) if user then local s,e,genre = string.find( data, "%b<> %p%w+%s(.*)|$") if not genre or genre == "" then if next(RelCfg.Req) then local reply = "Listing All Requests ...\r\n\r\n\tID. ".. "\t\tGenre\t\tRequest\r\n\t"..string.rep("Ż",100).."\r\n" for i,v in pairsByKeys(RelCfg.Req) do reply = reply.."\tID: "..i.."\t\t"..v["Genre"].."\t\t"..v["Request"].." // Added by "..v["Name"].." at "..v["Date"].."\r\n" end return reply.."\n\t"..string.rep("Ż",100).."\r\n\r\n" else return "There are no requests atm." end else local reply = "Listing Requests by Genre...\r\n\r\n\tID. ".. "\t\tGenre\t\tRequest\r\n\t"..string.rep("Ż",100).."\r\n" for i,v in pairsByKeys(RelCfg.Req) do if v["Genre"] == genre then reply = reply.."\tID: "..i.."\t\t"..v["Genre"].."\t\t"..v["Request"].." // Added by "..v["Name"].." at "..v["Date"].."\r\n" end end return reply.."\n\t"..string.rep("Ż",100).."\r\n\r\n" end else return "Show requests (genre) "," %[line:Genre]"," %[line:Genre]", -- profiles aan of uit {[-1] = 0,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end, reqhelp = function(user,data) if user then local x local reply = "\r\n\r\n\tRequest Command Help\r\n\r\n\tCommand\t\tDescription\r\n".. "\t"..string.rep("Ż",40).."\r\n" for i,v in pairsByKeys(ReqCmds) do local desc,args,_,tab = ReqCmds[i]() if tab[user.iProfile] and tab[user.iProfile] == 1 then x = 1 reply = reply.."\t!"..string.format("%-15s",i).."\t"..desc.."\r\n" end end if x then return reply.."\n\t"..string.rep("Ż",40).."\r\n\r\n" else return "Sorry "..user.sNick.." These commands are disabled for your profile." end else return "Show Request Help","","", -- profiles aan of uit {[-1] = 1,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end, reqabout = function(user,data) local reply = "\n\n\tAbout this script..\n".. "\t"..string.rep("Ż",40).."\r\n" if user then x=1 local FileSize1 = CheckFile(RelCfg.BuFile) local FileSize2 = CheckFile(RelCfg.RelFile) local FileSize3 = CheckFile(RelCfg.ReqFile) if x then reply = reply.."\t09-02-2008\n".. "\n\tReleaseBot "..RelCfg.Version.." ".._VERSION.." [API 2] made by Daywalker\n".. "\n\tUsing some code snibbets from Sir Mutor cause i like that style and it's easy going imo :)\n".. "\tTnx to Plop to point me to the right table form :))\n".. "\tAnd as always CrazyGuy for listen to my mumbling about some code :P\n".. "\n\tThis Script Release Candidate was Finished at 04/05/08 16:44:24 +1 UTC".. "\n\tExact Date and Time for now is: "..os.date().." "..RelCfg.Tz.. "\n\tScript uses "..Mem().." atm.".. "\n\n\tCurrent File Sizes are for:".. "\n\t"..string.rep("~",20).. "\n\tGenre file\t\t: "..FileSize1.. "\n\tRelease file\t: "..FileSize2.. "\n\tRequest file\t: "..FileSize3.. "\n\t"..string.rep("~",20).."\n" end return reply.."\n\t"..string.rep("Ż",40).."\r\n\r\n" else return "Show about this script","","", -- profiles aan of uit {[-1] = 1,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,} end end,}SendRelCmds = function(user) local x for i,v in pairsByKeys(RelCmds) do local desc,arg1,arg2,tab = RelCmds[i]() if tab[user.iProfile] and tab[user.iProfile] == 1 then x = 1 Core.SendToNick(user.sNick,"$UserCommand 1 1 "..RelCfg.Menu.."\\"..RelCfg.SubMenu1.."\\".. desc.."$<%[mynick]> +"..i..arg1.."||") Core.SendToNick(user.sNick,"$UserCommand 1 2 "..RelCfg.Menu.."\\"..RelCfg.SubMenu1.."\\".. desc.."$$To: "..RelCfg.Bot.." From: %[mynick] $<%[mynick]> +"..i..arg2.."||") end end if x then local Prof if user.iProfile ~= -1 then Prof = ProfMan.GetProfile(user.iProfile).sProfileName else Prof = "Unregistered User" end end collectgarbage("collect")endSendReqCmds = function(user) local x for i,v in pairsByKeys(ReqCmds) do local desc,arg1,arg2,tab = ReqCmds[i]() if tab[user.iProfile] and tab[user.iProfile] == 1 then x = 1 Core.SendToNick(user.sNick,"$UserCommand 1 1 "..RelCfg.Menu.."\\"..RelCfg.SubMenu2.."\\".. desc.."$<%[mynick]> +"..i..arg1.."||") Core.SendToNick(user.sNick,"$UserCommand 1 2 "..RelCfg.Menu.."\\"..RelCfg.SubMenu2.."\\".. desc.."$$To: "..RelCfg.Bot.." From: %[mynick] $<%[mynick]> +"..i..arg2.."||") end end if x then local Prof if user.iProfile ~= -1 then Prof = ProfMan.GetProfile(user.iProfile).sProfileName else Prof = "Unregistered User" end end collectgarbage("collect")endSendRel = function(user) if RelCfg.sendrelease then if user then local od,pos,datesplit = string.find(os.date(), "%d+%/(%d+)%/%d+%s%d+%:%d+%:%d+") local reply = "Listing All Today Releases ...\r\n\r\n\tID. ".. "\tGenre\tRelease\r\n\t"..string.rep("Ż",100).."\r\n" for i,v in pairsByKeys(RelCfg.Rel) do if v["Date"] then tb,pos,splittabledate = string.find(v["Date"], "%d+%/(%d+)%/%d+%s%d+%:%d+%:%d+") if splittabledate == datesplit then reply = reply.."\tID: "..i.."\t"..v["Genre"].."\t"..v["Release"].." // Added by "..v["Name"].." at "..v["Date"].."\r\n" else x=1 end end end if x then --nice empty space to fool the bot^^ end if RelCfg.HowToSend == "Main" then Core.SendToNick(user.sNick,"<"..RelCfg.Bot.."> "..reply.."\n\t"..string.rep("Ż",100).. "\n\n\tWelcome "..user.sNick.." to "..SetMan.GetString(0).."\n\n".. "\tLet me introduce you to at least one of our services in this hub...\n".. "\tthe 0 day releases... a hot item for some users and yes we have it!!\n".. "\tTo download this releases you need to type !regme <password> in main\n".. "\tto ask for a Vip acount, cause minimal profile to download is Vip profile\n".. "\n\tType !rlshelp in main or use the RC Commands on the hub tab to get help with the releasebot\n".. "\tEnjoy your stay in this hub and don't forget to type\n".. "\t!regme <password> when you're not regged as a vip or ask\n".. "\t(.°ı-DJC-.)T.C.M or (.°ı-DJC-.)M.O.T.S for a Vip acount... Enjoy:))\n\n".. "\n\t"..string.rep("Ż",100).."\r\n\r\n") else Core.SendPmToNick(user.sNick,RelCfg.Bot,reply.."\n\t"..string.rep("Ż",100).. "\n\n\tWelcome "..user.sNick.." to "..SetMan.GetString(0).."\n\n".. "\tLet me introduce you to at least one of our services in this hub...\n".. "\tthe 0 day releases... a hot item for some users and yes we have it!!\n".. "\tTo download this releases you need to type !regme <password> in main\n".. "\tto ask for a Vip acount, cause minimal profile to download is Vip profile\n".. "\n\tType !rlshelp in main or use the RC Commands on the hub tab to get help with the releasebot\n".. "\tEnjoy your stay in this hub and don't forget to type\n".. "\t!regme <password> when you're not regged as a vip or ask\n".. "\t(.°ı-DJC-.)T.C.M or (.°ı-DJC-.)M.O.T.S for a Vip acount... Enjoy:))\n\n".. "\n\t"..string.rep("Ż",100).."\r\n\r\n") end end else endendOnTimer = function(clean) if clean then Core.SendToAll("<"..RelCfg.Bot.."> Release cleaner started at "..os.date()) local cur,chg = os.time() local msg = "\n\t"..string.rep("=",130).. "\n\t\t\t\t\t- Listing Deleted Releases Older Then "..RelCfg.CleanTime.." Days-".. "\n\t"..string.rep("-",260).."\n" for i,v in pairs(RelCfg.Rel) do local td = os.difftime(os.time(),v["Time"]) local what = (td/86400) local TtoGo = (RelCfg.CleanTime-what) if what > RelCfg.CleanTime then --message msg = msg.."\tRelease: "..v["Release"].." is deleted from the releasebot\n" table.remove(RelCfg.Rel[i]) RelCfg.Rel[i] = nil chg = true end end local reqmsg = "\n\t"..string.rep("=",130).. "\n\t\t\t\t\t- Listing Deleted Requests Older Then "..RelCfg.CleanTime.." Days-".. "\n\t"..string.rep("-",260).."\n" local cur2,chg2 = os.time() for i,v in pairs(RelCfg.Req) do local td = os.difftime(os.time(),v["Time"]) local what = (td/86400) local TtoGo = (RelCfg.CleanTime-what) if what > RelCfg.CleanTime then --message reqmsg = reqmsg.."\tRequest: "..v["Request"].." is deleted from the releasebot\n" table.remove(RelCfg.Req[i]) RelCfg.Req[i] = nil chg2 = true end end if chg then Save_File(RelCfg.RelFile,RelCfg.Rel,"RelCfg.Rel") Core.SendToAll("<"..RelCfg.Bot.."> "..msg.."\n\t"..string.rep("Ż",130).."\r\n\r\n") else Core.SendToAll("<"..RelCfg.Bot.."> There are no Releases to delete yet, maybe next time..") end if chg2 then Save_File(RelCfg.ReqFile,RelCfg.Req,"RelCfg.Req") Core.SendToAll("<"..RelCfg.Bot.."> "..reqmsg.."\n\t"..string.rep("Ż",130).."\r\n\r\n") else Core.SendToAll("<"..RelCfg.Bot.."> There are no Requests to delete yet, maybe next time..") end endendCountPairs = function(Table) local x = 0 if Table then for i,v in pairs(Table) do x = x + 1 end end return xendTimeZone = function() local h,m = math.modf((os.time()-os.time(os.date"!*t"))/ 3600) return string.format("%+d UTC",(h + (60 * m)))endMem = function() collectgarbage("collect") return string.format("%-.2f Kb.",collectgarbage("count"))endCheckFile = function(File) local f,e = io.open(File,"r") if f then local current = f:seek() local size = f:seek("end") f:seek("set", current) f:close() if size then return FmtSz(size) end else if e then OnError(e:sub(1,2)) return e:sub(1,2) end endendFmtSz = function(int) local i,u,x= int or 0,{"","K","M","G","T","P"},1 while i > 1024 do i,x = i/1024,x+1 end return string.format("%.2f %sB.",i,u[x])endSave_Serialize = function(tTable, sTableName, hFile, sTab) sTab = sTab or ""; hFile:write(sTab..sTableName.." = {\n" ) for key, value in pairs(tTable) do local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key) if(type(value) == "table") then Save_Serialize(value, sKey, hFile, sTab.."\t") else local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value) hFile:write( sTab.."\t"..sKey.." = "..sValue) end hFile:write( ",\n") end hFile:write( sTab.."}")endSave_File = function(file,table, tablename ) local hFile = io.open (file , "wb") Save_Serialize(table, tablename, hFile) hFile:flush() hFile:close() collectgarbage("collect")endpairsByKeys = function(t, f) local a = {} for n in pairs(t) do table.insert(a, n) end table.sort(a, f) local i = 0 -- iterator variable local iter = function () -- iterator function i = i + 1 if a[i] == nil then return nil else return a[i], t[a[i]] end end return iterend
[20080406 - 12:31:25] <PxTest> *** Scanning script folder..ReleaseBot not found, Creating ReleaseBot now....[20080406 - 12:31:25] <PxTest> *** The folder ReleaseBot is created..inserting files now..[20080406 - 12:31:25] <PxTest> *** C:\DJCTHAHUB\devhub\scripts\ReleaseBot\Release.tbl file inserted..[20080406 - 12:31:25] <PxTest> *** C:\DJCTHAHUB\devhub\scripts\ReleaseBot\Request.tbl file inserted..[20080406 - 12:31:25] <PxTest> *** C:\DJCTHAHUB\devhub\scripts\ReleaseBot\BackBone.tbl file inserted..[20080406 - 12:31:25] <PxTest> *** ReleaseBot 1.0RC2 for Lua 5.1 by Daywalker has been started...[20080406 - 12:31:34] *** Disconnected[20080406 - 12:31:34] *** Connecting to 10.0.0.10:2008...[20080406 - 12:31:34] *** Connected[20080406 - 12:31:35] *** Stored password sent...[20080406 - 12:31:35] <PxTest> Daywalker Creates Errors On PtokaX DC Hub 0.4.1.0RC2 (UpTime: 1 days, 17 hours, 20 minutes / Users: 0)[20080406 - 12:31:36] <PxTest> booo[20080406 - 12:31:51] <PxTest> ======================================== - Release Command Help- -------------------------------------------------------------------------------- Command Description ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ !addgen Add A Genre !addrel Add A Release !delgen Delete A Genre !delrel Delete A Release !findrel Find A Release !gen Show Genres !prunerel Clean release table !prunereq Clean request table !relabout Show about this script !rls Show releases (genre) !rlshelp Show Release Help !today Show releases of today (genre) ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ[20080406 - 12:32:09] <PxTest> Genre: Techno is added to the ReleaseBot[20080406 - 12:32:09] <PxTest> Genre: Techno is added by Daywalker to the ReleaseBot[20080406 - 12:33:49] <PxTest> Release: ThisNameCanBeAReleaseNameAndSceneReleaseNamesAreAlwaysWithoutSpaces is added to releasebot[20080406 - 12:33:49] <PxTest> Release: ThisNameCanBeAReleaseNameAndSceneReleaseNamesAreAlwaysWithoutSpaces is added by Daywalker to the ReleaseBot under genre: Techno
||
||
[20080406 - 13:50:08] <PxTest> Genre: RcCommand is added by ThaTest to the ReleaseBot[20080406 - 13:58:46] <PxTest> Genre: RcCommandsRsx is added by ThaTest to the ReleaseBot[20080406 - 13:59:27] <PxTest> Genre: RSX is added by ThaTest to the ReleaseBot[20080406 - 14:13:48] <PxTest> Genre: RcCommandsApex is added by ThaTest to the ReleaseBot[20080406 - 14:14:10] <PxTest> Genre: Apex is added by ThaTest to the ReleaseBot
table.insert(RelCfg.Rel,RequestUpdate)
table.insert(RelCfg.Req,RequestUpdate)