Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) > Help with scripts

ReleaseBot 1.0 RC1 LUA 5.11 [API 2]

(1/6) > >>

Daywalker?:

--- Code: -----[[

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 Name
Hub = SetMan.GetString(0),
-- Should bot have a key? true / false
BotIsOp = true,
-- Bot description
BotDesc = "ReleaseBot",
-- Bot Email address
BotMail = "release@genre.mp3",
-- File to save Release table
RelFile = "Release.tbl",
-- File to save Request table
ReqFile = "Request.tbl",
-- File to save Other stuff to table
BuFile = "BackBone.tbl",
-- Context Menu Title
Menu = SetMan.GetString(0),
-- Context Submenu Titles
SubMenu1 = "Release",
SubMenu2 = "Request",
-- activate show today release on connect true or false
sendrelease = true,
-- send releases to main or pm  "Main/Pm"
HowToSend = "Pm",
-- Time to clean a table in days
CleanTime = 14,
------------------------------ Don't Try This At Home --------------------------
}

local minute = 60000
local hour = 60*minute
local day = 24*hour

OnStartup = 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...")
end

OnExit = function()
OnError("*** ReleaseBot 1.0RC1 LUA for ".._VERSION.." by Daywalker? has been stopped...")
end

OnError = function(msg)
Core.SendToOps("<"..RelCfg.Bot.."> "..msg.."|")
end

function UserConnected(user, data)
SendRelCmds(user)
SendReqCmds(user)
SendRel(user)
end

OpConnected = UserConnected
RegConnected = UserConnected

ChatArrival = 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
end
end
ToArrival = ChatArrival

RelCmds = {
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.."&#124;|")
Core.SendToNick(user.sNick,"$UserCommand 1 2 "..RelCfg.Menu.."\\"..RelCfg.SubMenu1.."\\"..
desc.."$$To: "..RelCfg.Bot.." From: %[mynick] $<%[mynick]> +"..i..arg2.."&#124;|")
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")
end

SendReqCmds = 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.."&#124;|")
Core.SendToNick(user.sNick,"$UserCommand 1 2 "..RelCfg.Menu.."\\"..RelCfg.SubMenu2.."\\"..
desc.."$$To: "..RelCfg.Bot.." From: %[mynick] $<%[mynick]> +"..i..arg2.."&#124;|")
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")
end

SendRel = 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

end
end

OnTimer = 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
end
end

CountPairs = function(Table)
local x = 0
if Table then
for i,v in pairs(Table) do
x = x + 1
end
end
return x
end

TimeZone = function()
local h,m = math.modf((os.time()-os.time(os.date"!*t"))/ 3600)
return string.format("%+d UTC",(h + (60 * m)))
end

Save_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.."}")
end

Save_File = function(file,table, tablename )
local hFile = io.open (file , "wb")
Save_Serialize(table, tablename, hFile)
hFile:flush()
hFile:close()
collectgarbage("collect")
end

pairsByKeys = 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 iter
end

--- End code ---

i hope you enjoy :)

// edit * changed a minor thingy in cleaner text "Nicks" into "Requests" ^^

baba.runner:
Hi Daywalker

You certainly made a good job.
But i want to point to a problem users will have with your script. I'm not a scripter, but I made already my experience with one setting as it is also made in your script. Again you certainly made a good job.

In your first lines:

--- Code: ---RelCfg = {
------------------------------- Main Settings -----------------------------------
-- Botname pulled from the hub or use "Custom-Name"
Bot = SetMan.GetString(21),
-- Hub Name
Hub = SetMan.GetString(0),
-- Should bot have a key? true / false
--- End code ---

you use SetMan. and users will get an error.  something like "attempt to index global 'SetMan' (a nil value)"
And it is something PPK point me to too.
follow this link for his remark to my question -> http://board.ptokax.ath.cx/index.php?topic=7662.msg72616#msg72616

I do not want to offend you. It is just that I see that more and more scripts come out with that error. And I personally find it nasty to have to restart the script once I launched the hub.

Kind Regards.
baba.runner

Daywalker?:
if i'm correct this error shows up on one occasion..

1] when the hub is not started yet and you want to start the script allready..

ex. [23:33] Syntax relreq2.lua:17: attempt to index global 'SetMan' (a nil value)

so start it after you started the hub then the problem will be solved :)

// edit while i was typing Mutor explained it and i could not done it better if you look above :P

BrotherBear:
Hi!

Got to try this script :)

I get this error when I am starting the Script:

[17:42] Syntax Rel-Req-Bot.lua:697: attempt to index local 'hFile' (a nil value)

I am Running Ptokax 0.4.0.0b

Regards,

BrotherBear

BrotherBear:
Hi Dear BrotherBear :)

You have to Create a Folder named ReleaseBot under Scripts folder.

Then Restart the Script.

Regards,

BrotherBear

P.S Thanks Snooze ;)  D.S

Navigation

[0] Message Index

[#] Next page

Go to full version