Tiny Release
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Tiny Release

Started by Cêñoßy†ê, 23 March, 2006, 14:50:59

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Cêñoßy†ê

----------------------------------------------------------
-- Tiny Release v2.04					--
-- Made by Optimus 02/03/05				--
-- Add/Delete releases					--
-- Top 10 new releases on connect			--
-- Usercommand added by Timetraveller			--
-- Lua 5.1 fix by C??o?y??                              --
----------------------------------------------------------
tRelease = {}
tCommands = {}
tFunctions = {}
RankingTable = {}
dofile("ReleaseRank.tbl")

-- Your botname
sBot = "-T?M????-"
-- File where releases are put
ReleaseFile = "releases.tbl"
-- File where releaseranks are put
RankFile = "ReleaseRank.tbl"
-- Amount of releases on connect
TopRelease = 10
-- Max number of stored releases in database, don't set it to high.
MaxReleases = 1000
-- Max number of top release writers
MaxPosters = 20
-- Enable top releases on connect 1=on/0=off
EnableTopRelease = 1
-- Where to send top releases on connect, set to main/pm
TopReleaseConnect = "main"
-- Where to send Show releases, set to main/pm
ShowRelease = "pm"
-- Send usercommands on connect 1=on/0=off
UserCommands = 1
-- Usercommands menu name
zMenu = "----? ReaD/Add NeW ReleaseS"

-- Your command prefixes here
CmdPrefix = { ["!"] = 1, ["?"] = 1, ["+"] = 1}

-- Sets who can use release script
Allowed = {
[0] = 1,	-- Master
[1] = 1,	-- Operator
[2] = 1,	-- VIPs
[3] = 1,	-- Regs
[4] = 1,	-- Moderator
[5] = 1,	-- Netfounder
}

Main = function()
	frmHub:RegBot(sBot)
	dofile(ReleaseFile)
	NewReleases = tFunctions.GetReleases(table.maxn(tRelease), table.maxn(tRelease)-TopRelease)
end

ChatArrival = function(user, data)
	user.SendMessage = user.SendData return tFunctions.GetCommands(user, data)
end

ToArrival = function(user, data)
	local s,e,to = string.find(data, "$To: (%S+%s?%S*)%sFrom:")
	if to == sBot then
		user.SendMessage = user.SendPM return tFunctions.GetCommands(user, data)
	end
end

NewUserConnected = function(user)
	if Allowed[user.iProfile] == 1 then
		if EnableTopRelease == 1 then
			local disp = "\r\n\t\t\t?? ?? ?? ??? ??????? ?? ?? ??? ?? Last "..TopRelease.." Releases Added ?? ?? ?? ??? ??????? ?? ?? ??? ?? \r\n\r\n"..NewReleases
			disp = disp.."\r\n\t\t\t?? ?? ?? ??? ??????? ?? ?? ??? ?? Last "..TopRelease.." Releases Added ?? ?? ?? ??? ??????? ?? ?? ??? ?? "
			disp = disp.."\r\n\t\t\t"
			tFunctions.ShowWhere(user, TopReleaseConnect, disp)
		end tFunctions.SendCommands(user)
	end
end

OpConnected = NewUserConnected

--// Commands ----------------------------------------------------------------------------------------------------------


tCommands["addrel"] = function(user, data)
	if Allowed[user.iProfile] == 1 then
		local s,e,item,descr = string.find(data, "%b<>%s+%S+%s+(.+)%-(.*)")
		if s then
			if table.maxn(tRelease) < MaxReleases then
				table.insert(tRelease,{user.sName,item,descr,os.date("%d-%b-%Y")})
				tFunctions.SaveReleases()
				NewReleases = tFunctions.GetReleases(table.maxn(tRelease), table.maxn(tRelease)-TopRelease)
				UpdateReleaseRank(user)
				saveTableToFile(RankFile, RankingTable, "RankingTable")
				SendToAll(sBot, user.sName.. "  Added A New Release To DataBase ** "..item.." - "..descr.." ** Check It Out!!  ;)")
			else
				user:SendMessage(sBot, "*** Database is full, maxium number of releases are: "..MaxReleases)
			end
		else
			user:SendMessage(sBot, "*** Usage: !addrel item-descr")
		end
	end return 1
end

tCommands["delrel"] = function(user, data)
	if user.bOperator then
		local s,e,nr = string.find(data, "%b<>%s+%S+%s+(%d+)")
		if s then
			if tRelease[tonumber(nr)] then
				table.remove(tRelease,nr)
				tFunctions.SaveReleases()
				NewReleases = tFunctions.GetReleases(table.getn(tRelease), table.maxn(tRelease)-TopRelease)
				user:SendMessage(sBot, "Release nr."..nr.." is deleted from database!")
			else
				user:SendMessage(sBot, "*** Release nr."..nr.." is not in database!")
			end
		else
			user:SendMessage(sBot, "*** Usage: !delrel nr")
		end
	end return 1
end

tCommands["showrel"] = function(user, data)
	if Allowed[user.iProfile] == 1 then
		local disp = "\r\n\t\t\t?? ?? ?? ??? ??????? ?? ?? ??? ?? Top "..table.getn(tRelease).." Releases ?? ?? ?? ??? ??????? ?? ?? ??? ??\r\n\r\n"
		disp = disp..tFunctions.GetReleases(table.maxn(tRelease), 1)
		tFunctions.ShowWhere(user, ShowRelease, disp.."\r\n\t\t\t?? ?? ?? ??? ??????? ?? ?? ??? ?? Top "..table.getn(tRelease).." Releases ?? ?? ?? ??? ??????? ?? ?? ??? ??")
	end return 1
end

tCommands["cleanup"] = function(user, data)
	if user.bOperator then
		local howmuch = table.maxn(tRelease)
		if howmuch >= MaxReleases then
			for i = 1, howmuch/2 do table.remove(tRelease,i) end 
			tFunctions.SaveReleases()
			user:SendMessage(sBot, "The database is cleaned!")
		else
			user:SendMessage(sBot, "The database doesn't need tobe cleaned!")
		end
	end return 1
end

tCommands["toprelease"] = function(user, data)
	user:SendData(sBot,ShowRanks())
	return 1
end

tCommands["myrelease"] = function(user, data)
	if RankingTable[user.sName] then
		user:SendData(sBot,"Your Posted releases: Total:"..RankingTable[user.sName].." releases")
	end return 1
end

--// Functions ---------------------------------------------------------------------------------------------------------


UpdateReleaseRank = function(user)
	local iUpdate = RankingTable[user.sName] or 0
	iUpdate = iUpdate + 1 RankingTable[user.sName] = iUpdate
end

ShowRanks = function()
	local tTemp = {}
        for i, v in pairs(RankingTable) do table.insert(tTemp, {i,v}) end
	table.sort(tTemp,function(a,b) return (a[2] > b[2]) end)
	local disp = "\r\n\t----------------------------------T-o-p--P-o-s-t-e-r-s----------------------------------\r\n\r\n"
	disp = disp.."\tNr:\tReleases:\t\tNick:\r\n"
	for i = 1,MaxPosters do
		if tTemp[i] then
			disp = disp.."\t"..i..".\t"..tTemp[i][2].."\t\t\t"..tTemp[i][1].."\r\n"
		end
	end 
	return disp
end

tFunctions.GetCommands = function(user, data)
	data=string.sub(data,1,string.len(data)-1)
	local s,e,prefix,cmd=string.find(data, "%b<>%s*(%S)(%S+)")
	if prefix and CmdPrefix[prefix] and tCommands[cmd] then
		return tCommands[cmd](user, data)
	end
end

tFunctions.ShowWhere = function(user, where, msg)
	if where == "main" then user:SendData(sBot, msg) elseif where == "pm" then user:SendPM(sBot, msg) end
end

tFunctions.GetReleases = function(startpos, endpos)
	local text = ""
	for i = startpos, endpos, -1 do
		if tRelease[i] then
			text = text.."     [ "..i.." ]   "..tRelease[i][4].."   "..tRelease[i][1].."  Added:  "..tRelease[i][2].." - "..tRelease[i][3].."\r\n"
		end
	end return text
end

tFunctions.SaveReleases = function()
	local iCount = 0
	local file = io.open(ReleaseFile, "w")
	if file then
		file:write("tRelease =  {\n")
			for i = 1, table.maxn(tRelease) do
				if tRelease[i] then
					iCount = iCount + 1
					file:write(string.format("[%d]",i).." = { "..string.format("%q",tRelease[i][1])..", "..string.format("%q",tRelease[i][2])..", "..string.format("%q",tRelease[i][3])..", "..string.format("%q",tRelease[i][4]).." },\n")
				end
			end
		file:write(string.format("[%q]","n").." = "..iCount..",\n}")
		file:close()
	end
end

tFunctions.SendCommands = function(user)
	if UserCommands == 1 then
		if user.bUserCommand then -- Is new function to check if client has UserCommand support.
			user:SendData("$UserCommand 0 3")
			user:SendData("$UserCommand 1 3 "..zMenu.."\\Show New Releases$<%[mynick]> !showrel|")
			user:SendData("$UserCommand 1 3 "..zMenu.."\\Add New Releases$<%[mynick]> !addrel %[line:Release-Descr]|")
			user:SendData("$UserCommand 1 3 "..zMenu.."\\Delete Releases (Ops Only)$<%[mynick]> !delrel %[line:Number]|")
			user:SendData("$UserCommand 1 3 "..zMenu.."\\Clean DataBase (Ops Only)$<%[mynick]> !cleanup|")
			user:SendData("$UserCommand 1 3 "..zMenu.."\\Show Top "..MaxPosters.."  Posters$<%[mynick]> !toprelease||")
			user:SendData("$UserCommand 1 3 "..zMenu.."\\Show Amount of your posted releases$<%[mynick]> !myrelease||")
		end
	end
end

--------------------------------------------------
Serialize = function(tTable,sTableName,hFile,sTab)
	sTab = sTab or ""
	hFile:write(sTab..sTableName.." = {\n")
	for key,value in pairs(tTable) do
	if (type(value) ~= "function") then
			local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key)
	if(type(value) == "table") then
				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
	end
	hFile:write(sTab.."}")
end

saveTableToFile = function(file, table, tablename)
	local handle = io.open(file,"w")
	Serialize(table,tablename,handle)
   	handle:close()
end


script needs these files allso
ReleaseRank.tbl
RankingTable = {
}


releases.tbl
tRelease = {
}
Powered By Leviathan™ 2nd Generation v. 1.9

zinden

possible to add catagories?
like Movies, games etc......
Xion++ - Where it all begins
http://www.zinden.net

jiten

Quote from: zinden on 25 March, 2006, 15:49:13
possible to add catagories?
like Movies, games etc......

You can try EntryBot and FreshStuff that already support that.
Soon, I'll be releasing an almost completely rewritten code of Release/Request bot with lots of features (including these).

Cheers

zinden

Does those work for newest ptokax?
cant see those script posted in lua 5.1 section....... ???
Xion++ - Where it all begins
http://www.zinden.net

jiten

Quote from: zinden on 25 March, 2006, 18:28:51
Does those work for newest ptokax?
cant see those script posted in lua 5.1 section....... ???

Not yet. But, will port it (EntryBot) to LUA 5.1 soon.
Release and Request Bot will be available in days too.

bastya_elvtars

@Zinden: I haven't yet tested FS under 5.1 but that is a matter of fixing the for loops only, so you should really check that out since it does not need major rewrite.
Everything could have been anything else and it would have just as much meaning.

Syphrone-NL

Got a problem with this now

When i do !toprelease i get this error:
[16:57] Syntax E:\DC\BFP Hub Lua 5.1\scripts\releases.lua:164: attempt to call a table value
Owner of 2 public hubs in Palace Network ---> www.palace-network.nl

jiten

Quote from: Syphrone-NL on 20 August, 2006, 16:03:54
When i do !toprelease i get this error:
[16:57] Syntax E:\DC\BFP Hub Lua 5.1\scripts\releases.lua:164: attempt to call a table value

Change that line to:

for i, v in pairs(RankingTable) do table.insert(tTemp, {i,v}) end

Cêñoßy†ê

Quote from: jiten on 20 August, 2006, 16:53:00
Change that line to:

for i, v in pairs(RankingTable) do table.insert(tTemp, {i,v}) end


Post updated.. thx jiten ::)
Powered By Leviathan™ 2nd Generation v. 1.9

jay-dee

im using this tiny release script.
can someone change it,
that only the item-description is stored, without username and date???
and also in mainchat

not:?H2O?> jay-dee  Added A New Release To DataBase ** lol - base ** Check It Out!!  ;)
but this:?H2O?> There is a new Release added To the DataBase ** Check It Out!!  ;)
---------------------------------------------------------
-- Tiny Release v2.04					--
-- Made by Optimus 02/03/05				--
-- Add/Delete releases					--
-- Top 10 new releases on connect			--
-- Usercommand added by Timetraveller			--
----------------------------------------------------------

tRelease = {}
tCommands = {}
tFunctions = {}

-- Your botname
sBot = "?H2O?"
-- File where releases are put
ReleaseFile = "releases.tbl"
-- Amount of releases on connect
TopRelease = 10
-- Max number of stored releases in database, don't set it to high.
MaxReleases = 500
-- Enable top releases on connect 1=on/0=off
EnableTopRelease = 1
-- Where to send top releases on connect, set to main/pm
TopReleaseConnect = "main"
-- Where to send Show releases, set to main/pm
ShowRelease = "pm"
-- Send usercommands on connect 1=on/0=off
UserCommands = 1
-- Usercommands menu name
zMenu = "----?New Releases"

-- Your command prefixes here
CmdPrefix = { ["!"] = 1, ["?"] = 1, ["+"] = 1}

-- Sets who can use release script
Allowed = {
[0] = 1,	-- Master
[1] = 1,	-- Operator
[2] = 1,	-- VIPs
[3] = 1,	-- Regs
[4] = 1,	-- Moderator
[5] = 1,	-- Netfounder
}

Main = function()
	frmHub:RegBot(sBot)
	dofile(ReleaseFile)
	NewReleases = tFunctions.GetReleases(table.getn(tRelease), table.getn(tRelease)-TopRelease)
end

ChatArrival = function(user, data)
	user.SendMessage = user.SendData return tFunctions.GetCommands(user, data)
end

ToArrival = function(user, data)
	local s,e,to = string.find(data, "$To: (%S+%s?%S*)%sFrom:")
	if to == sBot then
		user.SendMessage = user.SendPM return tFunctions.GetCommands(user, data)
	end
end

NewUserConnected = function(user)
	if Allowed[user.iProfile] == 1 then
		if EnableTopRelease == 1 then
			local disp = "\r\n\t\t\t?? ?? ?? ??? ??????? ?? ?? ??? ?? Last "..TopRelease.." Releases Added ?? ?? ?? ??? ??????? ?? ?? ??? ?? \r\n\r\n"..NewReleases
			disp = disp.."\r\n\t\t\t?? ?? ?? ??? ??????? ?? ?? ??? ?? Last "..TopRelease.." Releases Added ?? ?? ?? ??? ??????? ?? ?? ??? ?? "
			disp = disp.."\r\n\t\t\t"
			tFunctions.ShowWhere(user, TopReleaseConnect, disp)
		end tFunctions.SendCommands(user)
	end
end

OpConnected = NewUserConnected

--// Commands ----------------------------------------------------------------------------------------------------------


tCommands["addrel"] = function(user, data)
	if Allowed[user.iProfile] == 1 then
		local s,e,item,descr = string.find(data, "%b<>%s+%S+%s+(.+)%-(.*)")
		if s then
			if table.getn(tRelease) < MaxReleases then
				table.insert(tRelease,{user.sName,item,descr,os.date("%d-%m-%Y")})
				tFunctions.SaveReleases()
				NewReleases = tFunctions.GetReleases(table.getn(tRelease), table.getn(tRelease)-TopRelease)
				SendToAll(sBot, user.sName.. "  Added A New Release To DataBase ** "..item.." - "..descr.." ** Check It Out!!  ;)")
			else
				user:SendMessage(sBot, "*** Database is full, maxium number of releases are: "..MaxReleases)
			end
		else
			user:SendMessage(sBot, "*** Usage: !addrel item-descr")
		end
	end return 1
end

tCommands["delrel"] = function(user, data)
	if user.bOperator then
		local s,e,nr = string.find(data, "%b<>%s+%S+%s+(%d+)")
		if s then
			if tRelease[tonumber(nr)] then
				table.remove(tRelease,nr)
				tFunctions.SaveReleases()
				NewReleases = tFunctions.GetReleases(table.getn(tRelease), table.getn(tRelease)-TopRelease)
				user:SendMessage(sBot, "Release nr."..nr.." is deleted from database!")
			else
				user:SendMessage(sBot, "*** Release nr."..nr.." is not in database!")
			end
		else
			user:SendMessage(sBot, "*** Usage: !delrel nr")
		end
	end return 1
end

tCommands["showrel"] = function(user, data)
	if Allowed[user.iProfile] == 1 then
		local disp = "\r\n\t\t\t?? ?? ?? ??? ??????? ?? ?? ??? ?? Top "..table.getn(tRelease).." Releases ?? ?? ?? ??? ??????? ?? ?? ??? ??\r\n\r\n"
		disp = disp..tFunctions.GetReleases(table.getn(tRelease), 1)
		tFunctions.ShowWhere(user, ShowRelease, disp.."\r\n\t\t\t?? ?? ?? ??? ??????? ?? ?? ??? ?? Top "..table.getn(tRelease).." Releases ?? ?? ?? ??? ??????? ?? ?? ??? ??")
	end return 1
end

tCommands["cleanup"] = function(user, data)
	if user.bOperator then
		local howmuch = table.getn(tRelease)
		if howmuch >= MaxReleases then
			for i = 1, howmuch/2 do table.remove(tRelease,i) end 
			tFunctions.SaveReleases()
			user:SendMessage(sBot, "The database is cleaned!")
		else
			user:SendMessage(sBot, "The database doesn't need tobe cleaned!")
		end
	end return 1
end

--// Functions ---------------------------------------------------------------------------------------------------------

tFunctions.GetCommands = function(user, data)
	data=string.sub(data,1,string.len(data)-1)
	local s,e,prefix,cmd=string.find(data, "%b<>%s*(%S)(%S+)")
	if prefix and CmdPrefix[prefix] and tCommands[cmd] then
		return tCommands[cmd](user, data)
	end
end

tFunctions.ShowWhere = function(user, where, msg)
	if where == "main" then user:SendData(sBot, msg) elseif where == "pm" then user:SendPM(sBot, msg) end
end

tFunctions.GetReleases = function(startpos, endpos)
	local text = ""
	for i = startpos, endpos, -1 do
		if tRelease[i] then
			text = text.."\t ["..i.."]  "..tRelease[i][4].." ? "..tRelease[i][1].." ? Added:  "..tRelease[i][2].." - "..tRelease[i][3].."\r\n"
		end
	end return text
end

tFunctions.SaveReleases = function()
	local iCount = 0
	local file = io.open(ReleaseFile, "w")
	if file then
		file:write("tRelease =  {\n")
			for i = 1, table.getn(tRelease) do
				if tRelease[i] then
					iCount = iCount + 1
					file:write(string.format("[%d]",i).." = { "..string.format("%q",tRelease[i][1])..", "..string.format("%q",tRelease[i][2])..", "..string.format("%q",tRelease[i][3])..", "..string.format("%q",tRelease[i][4]).." },\n")
				end
			end
		file:write(string.format("[%q]","n").." = "..iCount..",\n}")
		file:close()
	end
end

tFunctions.SendCommands = function(user)
	if UserCommands == 1 then
		if user.bUserCommand then -- Is new function to check if client has UserCommand support.
			user:SendData("$UserCommand 0 3")
			user:SendData("$UserCommand 1 3 "..zMenu.."\\Show New Releases$<%[mynick]> !showrel&#124;")
			user:SendData("$UserCommand 1 3 "..zMenu.."\\Add New Releases$<%[mynick]> !addrel %[line:Release-Descr]&#124;")
			user:SendData("$UserCommand 1 3 "..zMenu.."\\Delete Releases (Ops Only)$<%[mynick]> !delrel %[line:Number]&#124;")
			user:SendData("$UserCommand 1 3 "..zMenu.."\\Clean DataBase (Ops Only)$<%[mynick]> !cleanup&#124;")
		end
	end
end


thnx in advance  regards

jay
"i was born house- i will die house"

TiMeTrAVelleR

change
SendToAll(sBot, user.sName.. "  Added A New Release To DataBase ** "..item.." - "..descr.." ** Check It Out!!  ;)")
to
SendToAll(sBot,"There is A New Release Added To DataBase ** Check It Out!!  ;)")

jay-dee

i mean also at on connect release delete the date and name..

?? ?? ?? ??? ??????? ?? ?? ??? ?? Last 10 Releases Added ?? ?? ?? ??? ??????? ?? ?? ??? ?? 

    [1]  19-09-2006 ? Back2Basics ? Added:  lol - base

         ?? ?? ?? ??? ??????? ?? ?? ??? ?? Last 10 Releases Added ?? ?? ?? ??? ??????? ?? ?? ??? ?? 
         

to...........

?? ?? ?? ??? ??????? ?? ?? ??? ?? Last 10 Releases Added ?? ?? ?? ??? ??????? ?? ?? ??? ?? 

    [1]   lol - base

         ?? ?? ?? ??? ??????? ?? ?? ??? ?? Last 10 Releases Added ?? ?? ?? ??? ??????? ?? ?? ??? ?? 
         
"i was born house- i will die house"

TiMeTrAVelleR

change

tFunctions.GetReleases = function(startpos, endpos)
	local text = ""
	for i = startpos, endpos, -1 do
		if tRelease[i] then
			text = text.."\t ["..i.."]  "..tRelease[i][4].." ? "..tRelease[i][1].." ? Added:  "..tRelease[i][2].." - "..tRelease[i][3].."\r\n"
		end
	end return text
end
[\code]

to

[code]
tFunctions.GetReleases = function(startpos, endpos)
	local text = ""
	for i = startpos, endpos, -1 do
		if tRelease[i] then
			text = text.."\t ["..i.."]  "..tRelease[i][2].." - "..tRelease[i][3].."\r\n"
		end
	end return text
end
[\code]
[/code]

Psycho_Chihuahua

i think you meant to post it this way ;)

change

tFunctions.GetReleases = function(startpos, endpos)
	local text = ""
	for i = startpos, endpos, -1 do
		if tRelease[i] then
			text = text.."\t ["..i.."]  "..tRelease[i][4].." ? "..tRelease[i][1].." ? Added:  "..tRelease[i][2].." - "..tRelease[i][3].."\r\n"
		end
	end return text
end


to

tFunctions.GetReleases = function(startpos, endpos)
	local text = ""
	for i = startpos, endpos, -1 do
		if tRelease[i] then
			text = text.."\t ["..i.."]  "..tRelease[i][2].." - "..tRelease[i][3].."\r\n"
		end
	end return text
end
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

TiMeTrAVelleR

yea  wasent quite awake ;)

jay-dee

 ??? ??? ???

scripts\releasetiny.lua:83: wrong number of arguments to 'insert'
"i was born house- i will die house"

TiMeTrAVelleR

---------------------------------------------------------
-- Tiny Release v2.04					--
-- Made by Optimus 02/03/05				--
-- Add/Delete releases					--
-- Top 10 new releases on connect			--
-- Usercommand added by Timetraveller			--
----------------------------------------------------------

tRelease = {}
tCommands = {}
tFunctions = {}

-- Your botname
sBot = "?H2O?"
-- File where releases are put
ReleaseFile = "releases.tbl"
-- Amount of releases on connect
TopRelease = 10
-- Max number of stored releases in database, don't set it to high.
MaxReleases = 500
-- Enable top releases on connect 1=on/0=off
EnableTopRelease = 1
-- Where to send top releases on connect, set to main/pm
TopReleaseConnect = "main"
-- Where to send Show releases, set to main/pm
ShowRelease = "pm"
-- Send usercommands on connect 1=on/0=off
UserCommands = 1
-- Usercommands menu name
zMenu = "----?New Releases"

-- Your command prefixes here
CmdPrefix = { ["!"] = 1, ["?"] = 1, ["+"] = 1}

-- Sets who can use release script
Allowed = {
[0] = 1,	-- Master
[1] = 1,	-- Operator
[2] = 1,	-- VIPs
[3] = 1,	-- Regs
[4] = 1,	-- Moderator
[5] = 1,	-- Netfounder
[6] = 1,	-- Owner
}

Main = function()
	frmHub:RegBot(sBot)
	dofile(ReleaseFile)
	NewReleases = tFunctions.GetReleases(table.getn(tRelease), table.getn(tRelease)-TopRelease)
end

ChatArrival = function(user, data)
	user.SendMessage = user.SendData return tFunctions.GetCommands(user, data)
end

ToArrival = function(user, data)
	local s,e,to = string.find(data, "$To: (%S+%s?%S*)%sFrom:")
	if to == sBot then
		user.SendMessage = user.SendPM return tFunctions.GetCommands(user, data)
	end
end

NewUserConnected = function(user)
	if Allowed[user.iProfile] == 1 then
		if EnableTopRelease == 1 then
			local disp = "\r\n\t\t\t?? ?? ?? ??? ??????? ?? ?? ??? ?? Last "..TopRelease.." Releases Added ?? ?? ?? ??? ??????? ?? ?? ??? ?? \r\n\r\n"..NewReleases
			disp = disp.."\r\n\t\t\t?? ?? ?? ??? ??????? ?? ?? ??? ?? Last "..TopRelease.." Releases Added ?? ?? ?? ??? ??????? ?? ?? ??? ?? "
			disp = disp.."\r\n\t\t\t"
			tFunctions.ShowWhere(user, TopReleaseConnect, disp)
		end tFunctions.SendCommands(user)
	end
end

OpConnected = NewUserConnected

--// Commands ----------------------------------------------------------------------------------------------------------


tCommands["addrel"] = function(user, data)
	if Allowed[user.iProfile] == 1 then
		local s,e,item,descr = string.find(data, "%b<>%s+%S+%s+(.+)%-(.*)")
		if s then
			if table.getn(tRelease) < MaxReleases then
				table.insert(tRelease,{user.sName,item,descr,os.date("%d-%m-%Y")})
				tFunctions.SaveReleases()
				NewReleases = tFunctions.GetReleases(table.getn(tRelease), table.getn(tRelease)-TopRelease)
				SendToAll(sBot,"New Release Added To DataBase ** "..item.." - "..descr.." ** Check It Out!!  ;)")
			else
				user:SendMessage(sBot, "*** Database is full, maxium number of releases are: "..MaxReleases)
			end
		else
			user:SendMessage(sBot, "*** Usage: !addrel item-descr")
		end
	end return 1
end

tCommands["delrel"] = function(user, data)
	if user.bOperator then
		local s,e,nr = string.find(data, "%b<>%s+%S+%s+(%d+)")
		if s then
			if tRelease[tonumber(nr)] then
				table.remove(tRelease,nr)
				tFunctions.SaveReleases()
				NewReleases = tFunctions.GetReleases(table.getn(tRelease), table.getn(tRelease)-TopRelease)
				user:SendMessage(sBot, "Release nr."..nr.." is deleted from database!")
			else
				user:SendMessage(sBot, "*** Release nr."..nr.." is not in database!")
			end
		else
			user:SendMessage(sBot, "*** Usage: !delrel nr")
		end
	end return 1
end

tCommands["showrel"] = function(user, data)
	if Allowed[user.iProfile] == 1 then
		local disp = "\r\n\t\t\t?? ?? ?? ??? ??????? ?? ?? ??? ?? Top "..table.getn(tRelease).." Releases ?? ?? ?? ??? ??????? ?? ?? ??? ??\r\n\r\n"
		disp = disp..tFunctions.GetReleases(table.getn(tRelease), 1)
		tFunctions.ShowWhere(user, ShowRelease, disp.."\r\n\t\t\t?? ?? ?? ??? ??????? ?? ?? ??? ?? Top "..table.getn(tRelease).." Releases ?? ?? ?? ??? ??????? ?? ?? ??? ??")
	end return 1
end

tCommands["cleanup"] = function(user, data)
	if user.bOperator then
		local howmuch = table.getn(tRelease)
		if howmuch >= MaxReleases then
			for i = 1, howmuch/2 do table.remove(tRelease,i) end 
			tFunctions.SaveReleases()
			user:SendMessage(sBot, "The database is cleaned!")
		else
			user:SendMessage(sBot, "The database doesn't need tobe cleaned!")
		end
	end return 1
end

--// Functions ---------------------------------------------------------------------------------------------------------

tFunctions.GetCommands = function(user, data)
	data=string.sub(data,1,string.len(data)-1)
	local s,e,prefix,cmd=string.find(data, "%b<>%s*(%S)(%S+)")
	if prefix and CmdPrefix[prefix] and tCommands[cmd] then
		return tCommands[cmd](user, data)
	end
end

tFunctions.ShowWhere = function(user, where, msg)
	if where == "main" then user:SendData(sBot, msg) elseif where == "pm" then user:SendPM(sBot, msg) end
end

tFunctions.GetReleases = function(startpos, endpos)
	local text = ""
	for i = startpos, endpos, -1 do
		if tRelease[i] then
			text = text.."\t\t\t ["..i.."]  "..tRelease[i][2].." - "..tRelease[i][3].."\r\n"
		end
	end return text
end

tFunctions.SaveReleases = function()
	local iCount = 0
	local file = io.open(ReleaseFile, "w")
	if file then
		file:write("tRelease =  {\n")
			for i = 1, table.getn(tRelease) do
				if tRelease[i] then
					iCount = iCount + 1
					file:write(string.format("[%d]",i).." = { "..string.format("%q",tRelease[i][1])..", "..string.format("%q",tRelease[i][2])..", "..string.format("%q",tRelease[i][3])..", "..string.format("%q",tRelease[i][4]).." },\n")
				end
			end
		file:write(string.format("[%q]","n").." = "..iCount..",\n}")
		file:close()
	end
end

tFunctions.SendCommands = function(user)
	if UserCommands == 1 then
		if user.bUserCommand then -- Is new function to check if client has UserCommand support.
			user:SendData("$UserCommand 0 3")
			user:SendData("$UserCommand 1 3 "..zMenu.."\\Show New Releases$<%[mynick]> !showrel|")
			user:SendData("$UserCommand 1 3 "..zMenu.."\\Add New Releases$<%[mynick]> !addrel %[line:Release-Descr]|")
			user:SendData("$UserCommand 1 3 "..zMenu.."\\Delete Releases (Ops Only)$<%[mynick]> !delrel %[line:Number]|")
			user:SendData("$UserCommand 1 3 "..zMenu.."\\Clean DataBase (Ops Only)$<%[mynick]> !cleanup|")
		end
	end
end

TiMeTrAVelleR

3:09:17] <?H2O?> 
			?? ?? ?? ??? ??????? ?? ?? ??? ?? Last 10 Releases Added ?? ?? ?? ??? ??????? ?? ?? ??? ?? 

			 [1]  blabla  -  test

			?? ?? ?? ??? ??????? ?? ?? ??? ?? Last 10 Releases Added ?? ?? ?? ??? ??????? ?? ?? ??? ??

Herodes

#18
Gave it an optimisation spin,...

the parsing flows and there are less global vars,.. i hope,..
this one isn't tested ,... just syntax checked...
---------------------------------------------------------
-- Tiny Release v2.05					--
-- Made by Optimus 02/03/05				--
-- Add/Delete releases					--
-- Top 10 new releases on connect			--
-- Usercommand added by Timetraveller			--
-- touched by Herodes [19/09/2006]		--
----------------------------------------------------------

tRelease = {}
tCommands = {}
tFunctions = {}

-- Your botname
sBot = "TinyRelease"
-- File where releases are put
sReleaseFile = "releases.tbl"
-- Amount of releases on connect
iTopRelease = 10
-- Max number of stored releases in database, don't set it to high.
iMaxReleases = 500
-- Enable top releases on connect// true:on / nil:off
bEnableTopRelease = true
-- Send Top Releases on connect// true:pm / nil:main
bTopReleaseConnectInPm = nil
-- Send Show releases in PM// true:pm / nil:main
bShowReleaseInPm = true
-- Send usercommands on connect // true:on / nil:off
bSentUserCommands = true
-- Usercommands menu name
sMenu = "-Tiny Releases"

-- Sets who can use release script
tAllowed = {
[0] = 1,	-- Master
[1] = 1,	-- Operator
[2] = 1,	-- VIPs
[3] = 1,	-- Regs
[4] = 1,	-- Moderator
[5] = 1,	-- Netfounder
}

function Main()
	frmHub:RegBot( sBot )
	dofile( sReleaseFile )
	for i,v in pairs(tAllowed) do if (v == 0) then tAllowed[i] = nil;end;end
	NewReleases = tFunctions.GetReleases( #tRelease, #tRelease-iTopRelease)
end

ChatArrival = function(user, data)
	data = string.sub( data, 1, -2 )
	local cmd, args = string.match( data, '%b<>%s+[%!%?%+%-%.%#](%S+)%s*(%S*)')
	if cmd then return Parse( user, cmd, args ) end
end

ToArrival = function(user, data)
	data = string.sub( data, 1, -2 )
	local to = string.match( data, '$To:%s(%S+)%sFrom:' )
	if to and to == sBot then
		local cmd, args = string.match( data, '%b<>%s+[%!%?%+%-%.%#](%S+)%s*(%S*)')
		if cmd then return Parse( user, cmd, args, true ) end
	end
end

NewUserConnected = function(user)
	if Allowed[user.iProfile] then
		if bEnableTopRelease == 1 then
			local disp = "\r\n\t\t\t·· ·· ·· ··· ··?¦?·· ·· ·· ··· ·· Last "..TopRelease.." Releases Added ·· ·· ·· ··· ··?¦?·· ·· ·· ··· ·· \r\n\r\n"..NewReleases
			disp = disp.."\r\n\t\t\t·· ·· ·· ··· ··?¦?·· ·· ·· ··· ·· Last "..TopRelease.." Releases Added ·· ·· ·· ··· ··?¦?·· ·· ·· ··· ·· "
			disp = disp.."\r\n\t\t\t"
			SendBack( user, disp, bTopReleaseConnectInPm )
		end
		if bSentUserCommands then
			if user.bUserCommand then -- Is new function to check if client has UserCommand support.
				user:SendData("$UserCommand 0 3")
				user:SendData("$UserCommand 1 3 "..sMenu.."\\Show New Releases$<%[mynick]> !showrel&#124;")
				user:SendData("$UserCommand 1 3 "..sMenu.."\\Add New Releases$<%[mynick]> !addrel %[line:Release-Descr]&#124;")
				user:SendData("$UserCommand 1 3 "..sMenu.."\\Delete Releases (Ops Only)$<%[mynick]> !delrel %[line:Number]&#124;")
				user:SendData("$UserCommand 1 3 "..sMenu.."\\Clean DataBase (Ops Only)$<%[mynick]> !cleanup&#124;")
			end
		end
	end
end

OpConnected = NewUserConnected

--// Commands ----------------------------------------------------------------------------------------------------------

function Parse( user, cmd, args, how )
	local tCmds = {
		['addrel'] = function( user, args, how )
			if not tAllowed[user.iProfile] then return SendBack( user, 'Nope!, Sorry you can not use this command!', how ) end
			local item, desc = string.match( args, '([^%-]+)%-(.*)' )
			if not item then return SendBack( user, '*** Syntax Error! Please use: !addrel <item>-<description>', how ); end
			if #tRelease > iMaxReleases then return SendBack( user, '*** Database is full, maximum number of releases is: '..iMaxReleases, how ); end
			table.insert( tRelease, { user.sName, item, desc, os.date('%d-%m-%Y') } )
			SaveReleases()
			NewReleases = GetReleases( #tRelease, #tRelease - iTopRelease )
			SendToAll( sBot, user.sName..' Added A New Release To DataBase **'..item..' - '..desc..' ** Check It Out!! ;)' )
			return SendBack( user, 'Release added', how ) ;
		end,

		['delrel'] = function( user, args, how )
			if not user.bOperator then return SendBack( user, 'Nope!, Sorry you can not use this command!', how ) end
			local nr = string.match( args, '^(%d+)')
			if not nr then return SendBack( user, '*** Syntax Error! Please use: !delrel <number>', how ); end
			nr = tonumber(nr)
			if not tRelease[nr] then return SendBack( user, '*** Release No.'..nr..' is not in database!', how ); end
			table.remove( tReleases, nr )
			SaveReleases()
			NewReleases = GetReleases( #tRelease, #tRelease - iTopRelease )
			return SendBack( user, 'Release No.'..nr..' is deleted from the database!', how )
		end,

		['showrel'] = function( user, args, how )
			if not tAllowed[user.iProfile] then return SendBack( user, 'Nope!, Sorry you can not use this command!', how ) end
			local s = "\r\n\t\t\t·· ·· ·· ··· ··?¦?·· ·· ·· ··· ·· Top "..(#tRelease).." Releases ·· ·· ·· ··· ··?¦?·· ·· ·· ··· ··\r\n\r\n"
			s = s..GetReleases(#tRelease, 1 )
			return SendBack( user, s.."\r\n\t\t\t·· ·· ·· ··· ··?¦?·· ·· ·· ··· ·· Top "..(#tRelease).." Releases ·· ·· ·· ··· ··?¦?·· ·· ·· ··· ··\r\n\r\n", how )
		end,

		['cleanup'] = function( user, args, how )
			if not user.bOperator then return SendBack( user, 'Nope!, Sorry you can not use this command!', how ) end
			local m = 'The database does not need to be cleaned!'
			if #tRelease >= iMaxReleases then
				for i = 1, (#tRelease)/2 do
					table.remove( tRelease, i )
				end
				m = 'The database is cleaned!'
			end
			return SendBack( user, m, how )
		end,
	}
	if tCmds[cmd] then
		return tCmds[cmd]( user, args, how )
	end
end

--// Functions ---------------------------------------------------------------------------------------------------------
function SendBack( user, what, how )
	if how then user:SendPM( sBot, what );return 1; end
	user:SendData( sBot, what ); return 1;
end

function GetReleases( s, e )
	local text = ""
	for i = s, e, -1 do
		if tRelease[i] then
			text = text.."\t ["..i.."]  "..tRelease[i][4].." » "..tRelease[i][1].." » Added:  "..tRelease[i][2].." - "..tRelease[i][3].."\r\n"
		end
	end;
	return text
end

function SaveReleases()
	local iCount = 0
	local file = io.open(ReleaseFile, "w")
	if file then
		file:write("tRelease =  {\n")
			for i = 1, (#tRelease) do
				if tRelease[i] then
					iCount = iCount + 1
					file:write(string.format("[%d]",i).." = { "..string.format("%q",tRelease[i][1])..", "..string.format("%q",tRelease[i][2])..", "..string.format("%q",tRelease[i][3])..", "..string.format("%q",tRelease[i][4]).." },\n")
				end
			end
		file:write(string.format("[%q]","n").." = "..iCount..",\n}")
		file:close()
	end
end

jay-dee

 ???

releasetiny.lua:49: bad argument #1 to 'pairs' (table expected, got nil)
"i was born house- i will die house"

Herodes

Quote from: jay-dee on 19 September, 2006, 14:49:11
???

releasetiny.lua:49: bad argument #1 to 'pairs' (table expected, got nil)
hmm .. many apologies... tAllowed is the new name for the Allowed table that contains profile permisions for the cmds,...
My post is now edited,... grab again (or just put a 't' before the first 'Allowed' you encounter in the script :)

jay-dee


???

hmm now i have this one.........

releasetiny.lua:47: attempt to call field 'GetReleases' (a nil value)
"i was born house- i will die house"

jay-dee

 ??? i did use the release from time above, but now the rightclick wont work??

only when i use: !addrel item-desc

whats wrong with this??
user:SendData("$UserCommand 1 3 "..zMenu.."\\Add New Releases$<%[mynick]> !addrel %[line:Release-Descr]|")


it gives no error or syntax........
"i was born house- i will die house"

TiMeTrAVelleR

been tested and works  showed you result 

TiMeTrAVelleR

#24
hmmm sec
  bourd messed it up youre right   will add file here

SMF spam blocked by CleanTalk