Link.Bot.v1.0.LUA5.1
 

Link.Bot.v1.0.LUA5.1

Started by kammikaze, 17 October, 2010, 11:07:01

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kammikaze

hello, i always used to use this script in my "old"  hubsoft and try to convert it for the newest hubsoft, but that doesn`t work. I saw there is already a request for this script but it is for and older version and for russian. I like the script in english for DiXBoT v2.1 Build 2987_PtokaX 0.4.1.2. Can somebody help me out? This is the script:
-- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////\
--||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  |
--||\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\||  |
--|| |                                                                                                            ||  |
--|| |			               ]N&                                                              				  ||  |
--|| |			   0Q           M!              ]D1                 gNO9MM,              R&                       ||  |
--|| | 			   MK        _gg,u     ymw_,,   "Bg  ,p,            M#   06    ,pag    ,q0&_,s                    ||  |
--|| |			   ##        ``"0&    =MQ``TAz  j&$  ]#&            0N   &0  =qA``#pc   ^MA^^`                    ||  |
--|| |			   M&           &f    ]09  i&2  =NA q#t             l30Ng&   jZp  #E5    0Q                       ||  |
--|| |			   #M          4#6    ]MX  lN9  *&D00               &B   &0  ]06  4NH    0@                       ||  |
--|| |			   MB          ]#8    ]0!  4Q8  WNT ~0L             NN   ##  ]0!  420    #8                       ||  |
--|| |			   &M&gppg   pqjW&pg  ]M&  ]0F  ]0[  *NS            ##gyx0~  ^"&pg#!"    ~#ggp                    ||  |
--|| |			   ``    _   _    ``    _   _         `  _           _ ```_    _      __  _  _                    ||  |
--|| |			"N@M@0N#**FF+479*~M#O"9#0M!*7M8N0**N*MMNN#*78MFM8"*#0@@N~*M!7*7!M**#4F***F0@MF*!                  ||  |
--|| |                                                                                            ________________||  |
--|| |                                                                                           |[ By. St0ne db ]||  |
--||//////////////////////////////////////////////////////////////////////////////////////////////////////////////||  |
--||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  |
-- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
--  ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////\
--|? Release Notes ?||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  |
-- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
--
----[v1.0 Features/Notes]-------------------------------------------------------
--
--	? Add Web Links to a database viewable by hub users.
--	? Access Control by user profile.
--  ? Database searching commands.
--  ? Display links via timer.
--	? Bot visual styles (two included)
--
--
----[FAQ]-----------------------------------------------------------------------
--
--  ? How to design custom styles.
--
--      Custom styles consist of up to six variables, named sSep0 - sSep5.
--      If the option to use extended info is turned on then all variables are used.
--      If not then sSep4 is skiped.
--
--      Any text can be used as well as magic characters such as:
--          \t - Tab
--          \n - New Line
--
--      Here is the default style:
--
--			<< Output Style A >>
--			sSep0	= " -=-  ",		    		---/ Header
--			sSep1	= "\t",             		--/  Seperator between ID and description
--			sSep2	= "  -=>  ",				--   Seperator between description and URL
--			sSep3   = "\r\n\t\t   Added by: ",	--   Seperator between URL and Extended Info Start
--			sSep4	= " - Submitted on: ",		--\  Seperator between Username and Date [Extended Info]
--			sSep5	= "\r\n",					---\ Footer
--
--      Which appears like this in Ptokax:
--                                                    sSep2
--                                                      |
--                                                      |
--                                                     \|/
-- 			-=-  ID: 5			UK LUA Language Board  -=>  http://lua.uknnet.com
--			/T\ 		 /T\	 Added by: st0ne_db - Submitted on: 30/05/06
--           |            |        /T\                  /T\                 /T\
--           |            |         |                    |                   |
--           |            |         |                    |                   |
--         sSep0        sSep1     sSep3                sSep4               sSep5
--
--
--  ? How to show categories on a timer.
--
--      If the option is turned on, the script will locate the category and display at the time chosen.
--      Times must use a 24 hour clock. If random categories are used. The times are used while the category
--      is chosen at random from the database. Since the category is ignored anything can be used:
--
--          ie.     ["04:20"] 	= "With random this does not matter",
--
--      Otherwise the category names work like the searching. Partial names maybe used to show multiple cats
--      on one time.
--
--			ie. 	["04:20"] 	= "PtokaX",
--					["16:20"] 	= "toka",       <-- partial name, would also work
--
--
-- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////\
--|? Credit ?|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  |
-- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
--
--  -The Serialize and SaveToFile functions from: 'Entry Bot v1.1e' (by jiten)
--  -Function pairsByKeys from: http://www.lua.org/pil/19.3.html
--  -Beta Testing: Thanks to Stormbringer 
--  -All other code by St0ne db.<the-westside crew> Best Viewed in LUAEdit v3
--  		-[ Updates, Bug Reports.. other LUA scripts for PtokaX.. http://the-westside.no-ip.info ]-
--
--  -Support your LUA Community-
--  	? LUA Language Board:  		http://forum.ptokax.org
--  	? UK LUA Language Board : 	http://lua.uknnet.com
--  	? PtokaX Resources' Site:	http://ptxscriptdb.psycho-chihuahua.net
--      ? PtokaX Wiki:              http://ptxwiki.psycho-chihuahua.net/doku.php
--
--
-- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////\
--|? Script Variables ?|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  |
-- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
tVar = {
	--*************************************************************************************************************
	--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Script Variables :: Main Configuration !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	--*************************************************************************************************************  
	sPrefix	= "!",   					---- Command Prefix
	------------------------------------------------------------------------------------------
	sBot	= "?Link-Bot?",  			---/ Bot Name
	sBotD	= "Link Bot",				--/  Bot Description
	sBotE	= "linkbot@ptokax.net",		--\  Bot Email Address
	sIsOP	= 1,						---\ Bot is OP (1=yes,0=no)
	sResp   = "main",                   ---- Bot Replys <main/pm>
	------------------------------------------------------------------------------------------ 
	sFolder	= "LinkBot",    			---/ Script Folder
	sFile	= "links.tbl",      		---\ Link Database
	sSendRC = "on",                     ---/ Send Right Click Menu <on/off>
	sMenu   = "Link Bot",				---\ Right Click Menu Name
	sUser   = "off",                    ---- Only Admin Profiles May Add New Links
	sNew    = "pm",                   	---- Anounce New Links to Hub <main/pm/off>
	sSpam   = "pm",	                	---- Show Link Database on Entry <main/pm/off>
	
	--*************************************************************************************************************
	--!!!!!!!!!!!!!!!!!!!!!!!!!!!! Script Visuals :: Change to suit your needs !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	--*************************************************************************************************************
	sHdStr	= "-- ",					---/ Header Character
	iHdSize = 55,						---\ [x] Times Repeted
	sExtNfo = "on",						---/ Show extended information (posted by, date) <on/off>
	sETime 	= "dmy",					---\ Date format (d=day, m=month, y=year)
	----<<[ Output Style A ]>>----------------------------------------------------------------                                    
	sSep0	= " -=-  ",		    		---/ Header
	sSep1	= "\t",             		--/  Seperator between ID and description
	sSep2	= "  -=>  ",				--   Seperator between description and URL
	sSep3   = "\r\n\t\t   Added by: ",	--   Seperator between URL and Extended Info Start
	sSep4	= " - Submitted on: ",		--\  Seperator between Username and Date [Extended Info]
	sSep5	= "\r\n",					---\ Footer	  
	----<<[ Output Style B ]>>----------------------------------------------------------------
	--sSep0	= "",		    			---/ Header
	--sSep1	= "  -=+=-  ",             	--/  Seperator between ID and description
	--sSep2	= "  -=+=-  ",				--   Seperator between description and URL
	--sSep3 = "  -=+=-  Added by: ",	--   Seperator between URL and Extended Info Start
	--sSep4	= " on ",					--\  Seperator between Username and Date [Extended Info]
	--sSep5	= "  -=+=-",				---\ Footer  

   	--*************************************************************************************************************
	--!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Script Timing :: Change to suit your needs !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	--*************************************************************************************************************
	sTimedShow		= "on",  			---- Show Categories On Timer <on/off>
	sTimed			= "pm",	     		---- Show in Main or PM <main/pm>
	iTime 			= 50,				---- Timer Interval (sec)
	sRTime 			= "off",			---- Random Categories <on/off>
	tTime = {                           ---- Time and Category to Display (if not using random)
		["04:20"] 	= "PtokaX",
		["16:20"] 	= "PtokaX",
	},
}

-- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////\
--|? Script Commands ?||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  |
-- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
tCmd = {
	sAddCat = "addlcat",        -- Add new category         [Admin]
	sDel    = "dellink",        -- Delete a link            [Admin]
	sDelCat = "dellcat",        -- Delete a category        [Admin]
	sFixID  = "fixids",			-- Renumber ID's            [Admin]
	sAdd	= "addlink",        -- Add a new link       	[User/Admin]
	sShow   = "lshow",      	-- Show Links\Cats          [User]
	sCShow  = "lshowcat",       -- Show Categories          [User]
	sSearch = "searchl",        -- Search Link Database     [User]
}

-- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////\
--|? Script Profiles ?||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  |
-- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
-- User Access [Show & Add Links] (1=allowed/0=deny) -- **Custom Profile 1 & 2 provided for RoboCop Support**
pUser = {    
	[0] = 1,    -- =[Master]=
	[1] = 1,    -- =[OP]=
	[2] = 1,    -- =[ViP]=
	[3] = 1,    -- =[Reg]=
	[4] = 1,    -- =[Custom Profile 1]=
	[5] = 1,    -- =[Custom Profile 2]=
   [-1] = 0,   	-- =[UnReg]=
}
-- Admin Access [Delete Links & Cats, Add Cats] (1=allowed/0=deny)
pAdmin = {
	[0] = 1,    -- =[Master]=
	[1] = 1,    -- =[OP]=
	[2] = 0,    -- =[ViP]=
	[3] = 0,    -- =[Reg]=
	[4] = 0,    -- =[Custom Profile 1]=
	[5] = 0,    -- =[Custom Profile 2]=
   [-1] = 0,   	-- =[UnReg]=
}

-- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////\
--|? Main Code ?||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  |
-- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
function Main()
  	local tempt = "";
	for t in string.gmatch(tVar.sETime,"%S") do 
		tempt = tempt.."\%"..t.."/"; 
	end
	tempt = string.sub(tempt,1,string.len(tempt)-1);
	tVar.sETime = tempt;
	frmHub:RegBot(tVar.sBot,tVar.sIsOP,tVar.sBotD,tVar.sBotE);
	if tVar.sTimedShow == "on" then
  SetTimer(tVar.iTime*1000);
		StartTimer();
	end
	doLoadData();
end

function ChatArrival(user,data)
	local data = string.sub(data,1,-2) 
	local s,e,sTrig,sCmd = string.find(data,"%b<>%s*(%S)(%S+)")
	if sTrig == tVar.sPrefix then		
		local tScriptCmds = {

			[tCmd.sAdd] = function(user,data)
				if tVar.sUser == "on" then
					if not pAdmin[user.iProfile] == 1 then return 1; end
				else
				    if not pUser[user.iProfile] == 1 then return 1; end
				end
				local _,_,sCatName,sURL,sDesc = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(%S+)%s+(.*)");
				if sCatName and sURL and sDesc then
					local found = false;
					for catname in pairs(LinkData) do
						if string.find(string.lower(catname),string.lower(sCatName)) then
							found = catname;
                    	    for cats,v in pairsByKeys(LinkData[catname]) do
								if string.lower(cats) == string.lower(sDesc) then
									toUser(user,"*** Error: Duplicated entry, "..sDesc)
									return 1;
								end 
							end
							local IDNum = doIDNum("set",1); local current = os.date(tVar.sETime)
							LinkData[catname][sDesc] = {};	LinkData[catname][sDesc]["URL"] = sURL; LinkData[catname][sDesc]["ID"] = IDNum;
							LinkData[catname][sDesc]["User"] = user.sName;	LinkData[catname][sDesc]["Date"] = current;												
							doSaveData();				
						end
      				end
					if found == false then
                    	toUser(user,"*** Error: Category "..sCatName.." does not exist.");
					else
						toUser(user,"*** Link Added: "..found..", ID: "..LinkData[found][sDesc]["ID"].." - "..sDesc.." - "..sURL);
					    if tVar.sNew == "main" then
                    		SendToAll(tVar.sBot,"*** Link Added: "..found..", - "..sDesc.." - "..sURL);
						elseif tVar.sNew == "pm" then
                    		SendPmToAll(tVar.sBot,"*** Link Added: "..found..", - "..sDesc.." - "..sURL);
						end						
					end			
				else
					toUser(user,"\r\n"..showCatInfo().."\r\n*** Error: Syntax error, "..tVar.sPrefix..tCmd.sAdd.." <cat> <url> <description>");
				end
				return 1;
			end,
			
			[tCmd.sAddCat] = function(user,data)
                if not pAdmin[user.iProfile] == 1 then return 1; end
				local _,_,sCatName = string.find(data,"%b<>%s+%S+%s+(%S+)");
				if sCatName then
					if not LinkData[sCatName] then
						LinkData[sCatName] = {};
						doSaveData();
						toUser(user,"*** Category: "..sCatName.." added.");
				    else
				    	toUser(user,"*** Error: Category, "..sCatName.." already exists.");	
				    end
				else	
					toUser(user,"\r\n"..showCatInfo().."*** Error: Enter category name: "..tVar.sPrefix..tCmd.sAddCat.." <cat>");
				end
				return 1;
			end,
			
			[tCmd.sDel] = function(user,data)
                if not pAdmin[user.iProfile] == 1 then return 1; end
				local _,_,sIDNum = string.find(data,"%b<>%s+%S+%s+(.*)");
				if sIDNum then					
					local sMsg = "\r\n"; local idChk = 0;
					for ID in string.gmatch(sIDNum, "%S+") do
						idChk = doIDNum("check",ID);
						if idChk == 0 then
							sMsg = sMsg.."*** ID: "..tostring(ID).." deleted.\r\n"   
						else
							sMsg = sMsg.."*** ID: "..tostring(ID).." not found.\r\n"	
						end
					end
					toUser(user,sMsg);									
				else
					toUser(user,"*** Error: Enter ID to delete, Multiple ID's may be entered on one line.");
				end
				return 1;
			end,
			
			[tCmd.sDelCat] = function(user,data)
                if not pAdmin[user.iProfile] == 1 then return 1; end
				local _,_,sCatName = string.find(data,"%b<>%s+%S+%s+(%S+)");
				if LinkData[sCatName] then
					LinkData[sCatName] = nil;
					doSaveData();
					toUser(user,"*** Category: "..sCatName..", and all links within have been delete");
				else
					toUser(user,"\r\n"..showCatInfo().."\r\n*** Error: Enter category name to delete (all links contained within will be deleted)");
				end
				return 1;
			end,
			
			[tCmd.sShow] = function(user,data)
                if not pUser[user.iProfile] == 1 then return 1; end
				local _,_,sCatName = string.find(data,"%b<>%s+%S+%s+(%S+)");
				local sMsg = "";
				if sCatName then -- show by cat
					local found = false;
					for cats in pairs(LinkData) do
						if string.find(string.lower(cats),string.lower(sCatName)) then
							found = true;
							sMsg = sMsg.."\r\n\r\n"
				    		.."\r\n\r\n "..string.rep(tVar.sHdStr,tVar.iHdSize).."\r\n\t\t\t\t? "..cats.." ?\r\n "..string.rep(tVar.sHdStr,tVar.iHdSize).."\r\n";
							for desc,v in pairsByKeys(LinkData[cats]) do
								sMsg = sMsg..tVar.sSep0.."ID: "..LinkData[cats][desc]["ID"]..tVar.sSep1..desc..tVar.sSep2..LinkData[cats][desc]["URL"].." ";
								if string.lower(tVar.sExtNfo) == "on" and LinkData[cats][desc]["User"] then
									sMsg = sMsg..tVar.sSep3..LinkData[cats][desc]["User"]..tVar.sSep4..LinkData[cats][desc]["Date"]..tVar.sSep5.."\r\n";
								elseif string.lower(tVar.sExtNfo) == "on" then
									sMsg = sMsg..tVar.sSep3.."Unknown"..tVar.sSep4.."Not Avaible"..tVar.sSep5.."\r\n";
								else
									sMsg = sMsg..tVar.sSep5.."\r\n";
								end
							end
						end
      				end
					if found == true then
					    toUser(user,"Displaying by category.... "..sMsg);
					else
						toUser(user,"*** Error: Category "..sCatName.." does not exist.");
					end
				else -- show all
				    sMsg = sMsg.."Displaying all links.... \r\n\r\n"
					for cats,v in pairsByKeys(LinkData) do
				    	sMsg = sMsg.."\r\n\r\n "..string.rep(tVar.sHdStr,tVar.iHdSize).."\r\n\t\t\t\t? "..cats.." ?\r\n "..string.rep(tVar.sHdStr,tVar.iHdSize).."\r\n";
						if LinkData[cats] then
							for desc,v in pairsByKeys(LinkData[cats]) do
								sMsg = sMsg..tVar.sSep0.."ID: "..LinkData[cats][desc]["ID"]..tVar.sSep1..desc..tVar.sSep2..LinkData[cats][desc]["URL"].." ";
								if string.lower(tVar.sExtNfo) == "on" and LinkData[cats][desc]["User"] then
									sMsg = sMsg..tVar.sSep3..LinkData[cats][desc]["User"]..tVar.sSep4..LinkData[cats][desc]["Date"]..tVar.sSep5.."\r\n";	
								elseif string.lower(tVar.sExtNfo) == "on" then
									sMsg = sMsg..tVar.sSep3.."Unknown"..tVar.sSep4.."Not Avaible"..tVar.sSep5.."\r\n";
								else 
									sMsg = sMsg..tVar.sSep5.."\r\n";
								end
							end
				    	end
					end
					toUser(user,sMsg);
				end
				return 1;
			end,

			[tCmd.sFixID] = function(user,data)
                if not pAdmin[user.iProfile] == 1 then return 1; end
				doIDNum("fix",1)
				toUser(user,"*** ID's Re-Numbered.");
				return 1;
			end,

			[tCmd.sSearch] = function(user,data)
                if not pUser[user.iProfile] == 1 then return 1; end
                local _,_,sType,sTxt = string.find(data,"%b<>%s+%S+%s+(%S+)%s+(.*)");
				local sMsg = ""
				if sType and sTxt then
				    if string.lower(sType) == "cat" then
						for cats in pairs(LinkData) do
							if string.find(string.lower(cats),string.lower(sTxt)) then
						        sMsg = sMsg.."- "..cats.."\r\n"
							end
						end
						toUser(user,"*** Search Results: by Category\r\n\r\n"..sMsg)
				    elseif sType == "link" then
						for cats in pairs(LinkData) do
							for desc in pairs(LinkData[cats]) do
								local url = LinkData[cats][desc]["URL"];
								if string.find(string.lower(desc),string.lower(sTxt)) or string.find(string.lower(url),string.lower(sTxt)) then
						        	sMsg = sMsg.."- "..cats.." : "..desc.." [ "..url.." ]\r\n"
								end
							end
						end
      					toUser(user,"*** Search Results: by Link\r\n\r\n"..sMsg)
				    else
            			toUser(user,"*** Error: "..tVar.sPrefix..tCmd.sSearch.." <cat/link> <search text>");
				    end
				else
				    toUser(user,"*** Link Database Search: "..tVar.sPrefix..tCmd.sSearch.." <cat/link> <search text>");
				end
				return 1;
			end,

			[tCmd.sCShow] = function(user,data)
                if not pUser[user.iProfile] == 1 then return 1; end
				toUser(user,"*** Displaying Category Listing: \r\n\r\n"..showCatInfo());
				return 1;
			end,
			
		}		
		if tScriptCmds[sCmd] then
			return tScriptCmds[sCmd](user,data);
	 	end
	end
end

function NewUserConnected(user)
	if string.lower(tVar.sSendRC) == "on" then
		if user.bUserCommand then
			if pUser[user.iProfile] == 1 then
				if tVar.sUser ~= "on" then
					user:SendData("$UserCommand 1 3 "..tVar.sMenu.."\\Add New Link$<%[mynick]> "..tVar.sPrefix..tCmd.sAdd.." %[line:Category Name?] %[line:URL?] %[line:Description?]&#124;");
				end
				user:SendData("$UserCommand 1 3 "..tVar.sMenu.."\\Show All Links$<%[mynick]> "..tVar.sPrefix..tCmd.sShow.."&#124;");
                user:SendData("$UserCommand 1 3 "..tVar.sMenu.."\\Show Links By Cat$<%[mynick]> "..tVar.sPrefix..tCmd.sShow.." %[line:Category Name?]&#124;");
				user:SendData("$UserCommand 1 3 "..tVar.sMenu.."\\Show Categories$<%[mynick]> "..tVar.sPrefix..tCmd.sCShow.."&#124;");
				user:SendData("$UserCommand 1 3 "..tVar.sMenu.."\\Search Link Database$<%[mynick]> "..tVar.sPrefix..tCmd.sSearch.." %[line:cat/link?] %[line:Search For?]&#124;");
    		end
    		if pAdmin[user.iProfile] == 1 then
				if tVar.sUser == "on" then
					user:SendData("$UserCommand 1 3 "..tVar.sMenu.."\\Admin\\Add New Link$<%[mynick]> "..tVar.sPrefix..tCmd.sAdd.." %[line:Category Name?] %[line:URL?] %[line:Description?]&#124;");
				end
				user:SendData("$UserCommand 1 3 "..tVar.sMenu.."\\Admin\\Add New Category$<%[mynick]> "..tVar.sPrefix..tCmd.sAddCat.." %[line:Category Name?]&#124;");
      			user:SendData("$UserCommand 1 3 "..tVar.sMenu.."\\Admin\\Delete Link$<%[mynick]> "..tVar.sPrefix..tCmd.sDel.." %[line:Enter ID to delete, Multiple ID's may be entered on one line.]&#124;");
      			user:SendData("$UserCommand 1 3 "..tVar.sMenu.."\\Admin\\Delete Cat$<%[mynick]> "..tVar.sPrefix..tCmd.sDelCat.." %[line:Category Name?]&#124;");
      			user:SendData("$UserCommand 1 3 "..tVar.sMenu.."\\Admin\\Renumber ID's$<%[mynick]> "..tVar.sPrefix..tCmd.sFixID.."&#124;");
			end
  		end
 	end
	if tVar.sSpam ~= "off" then
		local sMsg = "\r\n";
		for cats,v in pairsByKeys(LinkData) do
		   	sMsg = sMsg.."\r\n\r\n "..string.rep(tVar.sHdStr,tVar.iHdSize).."\r\n\t\t\t\t? "..cats.." ?\r\n "..string.rep(tVar.sHdStr,tVar.iHdSize).."\r\n";
			for desc,v in pairsByKeys(LinkData[cats]) do
				sMsg = sMsg..tVar.sSep0.."ID: "..LinkData[cats][desc]["ID"]..tVar.sSep1..desc..tVar.sSep2..LinkData[cats][desc]["URL"].." ";
				if string.lower(tVar.sExtNfo) == "on" and LinkData[cats][desc]["User"] then
					sMsg = sMsg..tVar.sSep3..LinkData[cats][desc]["User"]..tVar.sSep4..LinkData[cats][desc]["Date"]..tVar.sSep5.."\r\n";
				elseif string.lower(tVar.sExtNfo) == "on" then
					sMsg = sMsg..tVar.sSep3.."Unknown"..tVar.sSep4.."Not Avaible"..tVar.sSep5.."\r\n";
				else
					sMsg = sMsg..tVar.sSep5.."\r\n";
				end
		   	end
		end
		if tVar.sSpam == "main" then
 	        user:SendData(tVar.sBot, sMsg);
 		elseif tVar.sSpam == "pm" then
 	        user:SendPM(tVar.sBot, sMsg);
 		end
	end
end

function OnTimer()
 	local current = os.date("%H:%M");
	local sMsg = "";
    local found = false;
	if tVar.tTime[current] then
		if tVar.sRTime == "on" then
            math.randomseed(os.clock());
			found = true;
			local tRandCat = { };
			for cats in pairs(LinkData) do
				table.insert(tRandCat, cats);
      		end
      		local rand = math.random(1,table.maxn(tRandCat));
			local cats = tRandCat[rand];
			sMsg = sMsg.."\r\n\r\n"
			.."\r\n\r\n "..string.rep(tVar.sHdStr,tVar.iHdSize).."\r\n\t\t\t\t? "..cats.." ?\r\n "..string.rep(tVar.sHdStr,tVar.iHdSize).."\r\n";
			for desc,v in pairsByKeys(LinkData[cats]) do
				sMsg = sMsg..tVar.sSep0.."ID: "..LinkData[cats][desc]["ID"]..tVar.sSep1..desc..tVar.sSep2..LinkData[cats][desc]["URL"].." ";
				if string.lower(tVar.sExtNfo) == "on" and LinkData[cats][desc]["User"] then
					sMsg = sMsg..tVar.sSep3..LinkData[cats][desc]["User"]..tVar.sSep4..LinkData[cats][desc]["Date"]..tVar.sSep5.."\r\n";
				elseif string.lower(tVar.sExtNfo) == "on" then
					sMsg = sMsg..tVar.sSep3.."Unknown"..tVar.sSep4.."Not Avaible"..tVar.sSep5.."\r\n";
				else
					sMsg = sMsg..tVar.sSep5.."\r\n";
				end
			end
		else
   			for cats in pairs(LinkData) do
				if string.find(string.lower(cats),string.lower(tVar.tTime[current])) then
					found = true;
					sMsg = sMsg.."\r\n\r\n"
				    .."\r\n\r\n "..string.rep(tVar.sHdStr,tVar.iHdSize).."\r\n\t\t\t\t? "..cats.." ?\r\n "..string.rep(tVar.sHdStr,tVar.iHdSize).."\r\n";
					for desc,v in pairsByKeys(LinkData[cats]) do
						sMsg = sMsg..tVar.sSep0.."ID: "..LinkData[cats][desc]["ID"]..tVar.sSep1..desc..tVar.sSep2..LinkData[cats][desc]["URL"].." ";
						if string.lower(tVar.sExtNfo) == "on" and LinkData[cats][desc]["User"] then
							sMsg = sMsg..tVar.sSep3..LinkData[cats][desc]["User"]..tVar.sSep4..LinkData[cats][desc]["Date"]..tVar.sSep5.."\r\n";
						elseif string.lower(tVar.sExtNfo) == "on" then
							sMsg = sMsg..tVar.sSep3.."Unknown"..tVar.sSep4.."Not Avaible"..tVar.sSep5.."\r\n";
						else
							sMsg = sMsg..tVar.sSep5.."\r\n";
						end
					end
				end
      		end
		end
		if found == true then
			if tVar.sTimed == "main" then
				SendToAll(tVar.sBot,"["..current.."] Category: "..tVar.tTime[current].."\r\n"..sMsg);
            elseif tVar.sTimed =="pm" then
                SendPmToAll(tVar.sBot,"["..current.."] Category: "..tVar.tTime[current].."\r\n"..sMsg);
            end
		else
			SendToOps(tVar.sBot,"*** Error: Category "..tVar.tTime[current].." does not exist.");
		end
	end
end

-- Misc Functions
function toUser(curUser,sMsg)
	if tVar.sResp == "pm" then
        curUser:SendPM(tVar.sBot,sMsg);
	else
		curUser:SendData(tVar.sBot,sMsg);
	end
end

function showCatInfo()
	local sMsg = string.rep("-",20).."\r\n  Categories:\r\n"..string.rep("-",20).."\r\n\r\n";
	for cats,v in pairsByKeys(LinkData) do
		local lNum = function(cat)
						local cnt = 0; 
						for c in pairs(LinkData[cat]) do 
						 	cnt=cnt+1; 
						end	
						return tostring(cnt); 
					 end 
		sMsg = sMsg.." Category Name: "..cats.."\r\n Number of links: "..lNum(cats).."\r\n\r\n"
	end
	return sMsg;
end

function doIDNum(sType,IDNum)
	if sType == "fix" then
		local curNum = 1
		if LinkData ~= nil then
			for cats,v in pairsByKeys(LinkData) do
				if LinkData[cats] ~= nil then
					for desc,v in pairsByKeys(LinkData[cats]) do
						LinkData[cats][desc]["ID"] = curNum;						
						curNum = curNum + 1;
			        end
				end	
			end
	    end
		doSaveData();	
	else
		if LinkData ~= nil then
			for cats,v in pairsByKeys(LinkData) do
				if LinkData[cats] ~= nil then
					for desc,v in pairsByKeys(LinkData[cats]) do
						if sType == "set" then --set
							local curNum = tonumber(LinkData[cats][desc]["ID"])
							if curNum >= IDNum then
								IDNum = curNum + 1;
							end
						else --check & delete
							if tonumber(LinkData[cats][desc]["ID"]) == tonumber(IDNum) then
								LinkData[cats][desc] = nil; -- deleted
								return 0;
							end
						end					
					end
				end	
	
			end
	    end
	end
	return IDNum;
end

-- File Functions
function doLoadData()
	if loadfile(tVar.sFolder.."/"..tVar.sFile) then
    	dofile(tVar.sFolder.."/"..tVar.sFile);
  	else
        local file = io.open(tVar.sFolder.."/"..tVar.sFile , "a" );
        local data = "LinkData = {\r\n}";
		io.output(tVar.sFolder.."/"..tVar.sFile);
    	file:write( data );
    	file:close();
    	dofile(tVar.sFolder.."/"..tVar.sFile);
  	end
end

function doSaveData()
	SaveToFile(tVar.sFolder.."/"..tVar.sFile,LinkData,"LinkData")
	doLoadData()
end

-- Function from: http://www.lua.org/pil/19.3.html --
function pairsByKeys (t, f)
    local a = {}
    for n in pairs(t) do table.insert(a, n) end
    table.sort(a, f)
    local i = 0
    local iter = function ()
        i = i + 1
        if a[i] == nil then return nil
        else return a[i], t[a[i]]
        end
    end
	return iter
end

-- Functions from: Entry Bot 1.1e (by jiten) --
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

SaveToFile = function(file,table,tablename)
	local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close()
end

OpDisconnected=UserDisconnected
OpConnected=NewUserConnected

kammikaze

Sorry, this is new for me and was the first try ???

SMF spam blocked by CleanTalk