plop's CodeBoard - Revamped
 

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

plop's CodeBoard - Revamped

Started by Herodes, 15 March, 2005, 12:27:34

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Herodes

This is the scripters beloved bot in some weirdos hub .. I thought you might wanna have a look at its L5 version ...

---------------------------------------------------------------------------------------------------------
-- code board V2 by plop
---------------------------------------------------------------------------------------------------------
-- made for my own hub to seperate chat from code
-- doesn't repeat to the sender anymore
-- added away filter
---------------------------------------------------------------------------------------------------------
--- modded a lil bit by Herodes 
--- logs the posts of every day, each day opens a new file .. :)
--- done to retrieve past posts ... I thought it would be usefull ..
---------------------------------------------------------------------------------------------------------
--- modded a bit more by Herodes 			28/7/2004 9:05 pm
--- Now u can list the files in the log's directory and show any that u may want ...
---------------------------------------------------------------------------------------------------------
-- Yet another cb mod by Herodes ...
--- made in Lua 5
--- added ability to post from main ...
--- added ability for users to decide where to receive the posts (main or pm)
--- completely fixed for the Ptx-L5.. ( 15/3 - 2005 )
---------------------------------------------------------------------------------------------------------

Bot = "CodeBoard"
tUsers = {}
logfile = "codelogs/code"..os.date("%d").."-"..os.date("%m")..".txt"
cbcmd = "+cb"

--- Start the script ...
function Main() 
	frmHub:RegBot(Bot, 1, "Post your code in here .. it'll be kept safe with me", "petsagouris@hotmail.com")
end

--- When Mainchat msg arrives ..
function ChatArrival( user, data )
	if ( tUsers[user.sName] == nil ) then tUsers[user.sName] = 1 end
	CB( user, string.sub( data, 1, -2 ))
end

--- When a pm arrives ...
function ToArrival( user, data )
	if ( tUsers[user.sName] == nil ) then tUsers[user.sName] = 1 end
	CB( user, string.sub( data, 1, -2 ),  true )
end

--- Main Handling done here ...
function CB(user, data, how)
	local ok, len = 1, (string.len(cbcmd) +1)
	s,e,chat = string.find(data, "%b<>%s+(.*)")
	if string.sub(chat, 1,string.len(cbcmd)) == cbcmd then
		s,e,cmd,args = string.find(data, "%b<>%s+(%S+)%s*(.*)")
		if string.sub(cmd, len,len) == "r" then
			if args and args ~= "" then SendBack(ReadIt("codelogs/"..args..".txt"), user, how) end
			ok = nil; return 1
		elseif string.sub(cmd, len,len) == "l" then
			ListLogs(user, how); ok = nil; return 1
		elseif string.sub(cmd, len, len) == "n" then 
			ChangeWay(user, how); ok = nil; return 1
		elseif string.sub(cmd, len, len) == "p" then
			DoPost(user, string.sub(chat, len+2, -1), how); ok = nil; return 1
		elseif string.sub(cmd, len, len) == "h" then
			CBHelp(user, how); ok = nil; return 1
		end
	end
	if ok and how then
		DoPost(user, data, out); return 1
	end
end

--- Semi-Utility Function ... 
function LogIt(what)
	local handle, err = io.open(logfile, "a+")
	if handle then
		handle:write("\r\n\r\n- = = @ = =        Start of new input\t= = @ = = -\r\n"..what.."\r\n- = = @ = =\tEnd Of Input\t = = @ = = -")
		handle:close()
	end
end

--- List the log files of the CB...
function ListLogs(user, how)
	os.execute("dir codelogs > codelogs/dirlist.lst")
	local msg = "\r\n\t - Available Logs:\r\n\t"..string.rep("-", 50).." [ listing start ]\r\n"
	for line in io.lines("codelogs/dirlist.lst") do
		local s,e,name = string.find(line, "%s(%S+)%.txt$")
		if name then msg = msg.."\t\t- "..name.."\r\n" end
	end
	os.remove("codelogs/dirlist.lst")
	SendBack(msg, user, how)
end

--- Choose the way the CB will be annoying a user ...
function ChangeWay(user, how)
	local status = "main"
	if tUsers[user.sName] == 1 then 	tUsers[user.sName] = 2 
	else tUsers[user.sName] = 1; status = "pm"
	end
	SendBack("You are now going to be receiving the cb messages in "..status, user, how)
end

--- Take care of posting in the CB
function DoPost(user, data, out)
	-- local s,e,text = string.find(data, "%$%b<>(.*)")
	if ( text ~= "" ) then
		local curUser
		local signalstr = "\r\n- - - - - - - - - - - - - - - - - - - - - - code board - - - - - - - - - - - - - - - - - - - - - -"
		local line = "\t-- Code by: "..user.sName.." ( on "..(os.date())..")"..signalstr.." [ start ]\r\n"..data..signalstr.."[ end ]"
		LogIt(line)
		for a,b in tUsers do
			curUser = GetItemByName(a)
			if ( (curUser) and (a ~= user.sName) ) then 
				if tUsers[a] == 1 then SendBack(line, curUser, "pm")
				else SendBack(line, curUser)
				end
			elseif (a == user.sName) then 
				SendBack("Your code has been send!", user, out)
			else 
				tUsers[a] = nil
			end
		end
	end
end

--- Help text .. 
function CBHelp(user, how)
	local msg, tC = "\r\n\t These commands are available for the "..Bot.."\r\n"..string.rep("- ", 50).."\r\n",
	   { ["r"] = "read a code board log",
		["l"] = "lists the code boards logs",
		["n"] = "code board messages in pm/main",
		["p"] = "post in code board",
		["h"] = "this text",}
	for cmd, explain in tC do
		msg = msg.."\t\t"..cbcmd..cmd.."\t"..explain.."\r\n"
	end
	SendBack(msg, user, how)
end
--- Utility function ..
function ReadIt(file)
	local msg = "\r\n\t"
	if ( io.input(file) ) then
		text = io.input(file)
		for line in text:lines() do 	msg = msg..line.."\r\n\t" end
		text:close()
		return msg
	else
		return file.." does not exist"
	end
end
--- Another Utility function ..
function SendBack(msg, user, out)
	if out then user:SendPM(Bot, msg)
	else user:SendData(Bot, msg) 
	end
end
--- Take care of the logins/outs .. 
function OpConnected(user)
	if ( tUsers[user.sName] == nil ) then  tUsers[user.sName] = 1 end
end

NewUserConnected = OpConnected

function OpDisconnected(user)
	if ( tUsers[user.sName] ) then tUsers[user.sName] = nil end
end

UserDisconnected = OpDisconnected

plop

QuoteOriginally posted by Herodes
This is the scripters beloved bot in some weirdos hub .. I thought you might wanna have a look at its L5 version ...
thx for the complement and this new version.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

plop

hint: also use myinfoarrival 2 add new users 2 the table.
mistake: when posting code in pm the msg "code send" shows up in main.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Herodes

#3
ty for the observations Mr plop ;)
there is the newest from the East :
--- code board V2 by plop
--- reached ver v2.8 - Herodes
--[[ ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
 - made for my own hub to seperate chat from code (plop)
 - doesn't repeat to the sender anymore (plop)
 - added away filter (plop)
=---
 - modded a lil bit by Herodes
 - logs the posts of every day, each day opens a new file .. :)
 - done to retrieve past posts ... I thought it would be usefull ..
=---
 - modded a bit more by Herodes 			28/7/2004 9:05 pm
 - Now u can list the files in the log's directory and show any that u may want ...
=---
 = Yet another cb mod by Herodes ...
 - made in Lua 5
 - added ability to post from main ...
 - added ability for users to decide where to receive the posts (main or pm)
 - completely fixed for the Ptx-L5.. ( 15/3 - 2005 )
 - ammended according to plop's observations ( same date more or less )
 - made poss to have the cb msgs turned off for every individual user...
 - NOTE: You DO need to create a directory named 'codelogs' inside your 'scripts' dir.
--]] ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

Bot = "CodeBoard"
tUsers = {}
logfile = "codelogs/code"..os.date("%d").."-"..os.date("%m")..".txt"
cbcmd = "+cb"

--- Start the script ...
function Main()
	frmHub:RegBot(Bot, 1, "Post your code in here .. it'll be kept safe with me", "petsagouris@hotmail.com")
end

--- When Mainchat msg arrives ..
function ChatArrival( user, data )
	if not tUsers[user.sName] then tUsers[user.sName] = 1 end
	return CB( user, string.sub( data, 1, -2 ))
end

--- When a pm arrives ...
function ToArrival( user, data )
	if not tUsers[user.sName] then tUsers[user.sName] = 1 end
	if (string.sub( data, 1, string.len(Bot)+5) == "$To: "..Bot) then
		return CB( user, string.sub( data, 1, -2 ),  true )
	end
end

--- Main Handling done here ...
function CB(user, data, how)
	local ok, len = 1, (string.len(cbcmd) +1)
	s,e,chat = string.find(data, "%b<>%s+(.*)")
	if (string.sub(chat, 1,string.len(cbcmd)) == cbcmd) then
		s,e,cmd,args = string.find(data, "%b<>%s+(%S+)%s*(.*)")
		if (string.sub(cmd, len,len) == "r") then
			if args and args ~= "" then
				SendBack(ReadIt("codelogs/"..args..".txt"), user, how)
			end
			ok = nil; return 1
		elseif (string.sub(cmd, len,len) == "l") then
			ListLogs(user, how); ok = nil; return 1
		elseif (string.sub(cmd, len, len) == "n") then
			ChangeWay(user, how); ok = nil; return 1
		elseif (string.sub(cmd, len, len) == "p") then
			DoPost(user, string.sub(chat, len+2, -1), how); ok = nil; return 1
		elseif (string.sub(cmd, len, len) == "h") then
			CBHelp(user, how); ok = nil; return 1
		end
	end
	if ok and how then
		DoPost(user, data, how); return 1
	end
end

--- Semi-Utility Function ...
function LogIt(what)
	local handle, err = io.open(logfile, "a+")
	if handle then
		handle:write("\r\n\r\n- = = @ = =        Start of new input\t= = @ = = -\r\n"..what.."\r\n- = = @ = =\tEnd Of Input\t = = @ = = -")
		handle:close()
	end
end

--- List the log files of the CB...
function ListLogs(user, how)
	os.execute("dir codelogs > codelogs/dirlist.lst")
	local msg = "\r\n\t - Available Logs:\r\n\t"..string.rep("-", 50).." [ listing start ]\r\n"
	for line in io.lines("codelogs/dirlist.lst") do
		local s,e,name = string.find(line, "%s(%S+)%.txt$")
		if name then msg = msg.."\t\t- "..name.."\r\n" end
	end
	os.remove("codelogs/dirlist.lst")
	SendBack(msg, user, how)
end

--- Choose the way the CB will be annoying a user ...
function ChangeWay(user, how)
	local status = "You are now going to be receiving the cb messages in pm"
	if tUsers[user.sName] == 1 then 	tUsers[user.sName] = 2
	elseif tUsers[user.sName] == 2 then tUsers[user.sName] = 3; status = "You are not going to be receiving the cb messages"
	elseif tUsers[user.sName] == 3 then tUsers[user.sName] = 1; status = "You are now going to be receiving the cb messages in main"
	end
	SendBack(status, user, how)
end

--- Take care of posting in the CB
function DoPost(user, data, out)
	-- local s,e,text = string.find(data, "%$%b<>(.*)")
	if ( text ~= "" ) then
		local curUser
		local signalstr = "\r\n- - - - - - - - - - - - - - - - - - - - - - code board - - - - - - - - - - - - - - - - - - - - - -"
		local line = "\t-- Code by: "..user.sName.." ( on "..(os.date())..")"..signalstr.." [ start ]\r\n"..data..signalstr.."[ end ]"
		LogIt(line)
		for a,b in tUsers do
			local curUser = GetItemByName(a)
			if ( (curUser) and (a ~= user.sName) ) then
				if tUsers[a] == 1 then SendBack(line, curUser )
				elseif tUsers[a] == 2 then SendBack( line, curUser, true )
				else SendBack("*** "..user.sName.." has posted on the CodeBoard", curUser)
				end
			elseif (a == user.sName) then
				SendBack("Your code has been send!", user, out)
			else
				tUsers[a] = nil
			end
		end
	end
end

--- Help text ..
function CBHelp(user, how)
	local msg, tC = "\r\n\t These commands are available for the "..Bot.."\r\n"..string.rep("- ", 50).."\r\n",
	   { ["r"] = "read a code board log",
		["l"] = "lists the code boards logs",
		["n"] = "code board messages in pm/main/off",
		["p"] = "post in code board",
		["h"] = "this text",}
	for cmd, explain in tC do
		msg = msg.."\t\t"..cbcmd..cmd.."\t"..explain.."\r\n"
	end
	SendBack(msg, user, how)
end
--- Utility function ..
function ReadIt(file)
	local msg = "\r\n"
	if ( io.input(file) ) then
		text = io.input(file)
		for line in text:lines() do 	msg = msg..line.."\r\n" end
		text:close()
		return msg
	else
		return file.." does not exist"
	end
end
--- Another Utility function ..
function SendBack(msg, user, out)
	if out then user:SendPM(Bot, msg)
	else user:SendData(Bot, msg)
	end
end

--- Live users in the table pls ..
function MyInfoArrival( user, data)
	if not tUsers[user.sName] then  tUsers[user.sName] = 1 end
end

--- Take care of the logins/outs ..
function OpConnected(user)
	if not tUsers[user.sName] then  tUsers[user.sName] = 1 end
end

NewUserConnected = OpConnected

function OpDisconnected(user)
	if ( tUsers[user.sName] ) then tUsers[user.sName] = nil end
end

UserDisconnected = OpDisconnected

plop

eeeehm, simple buggy found with very nasty results.
every pm in the hub is seen as code.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Herodes

#5
QuoteOriginally posted by plop
eeeehm, simple buggy found with very nasty results.
every pm in the hub is seen as code.
Offline testing has to be extended on my part ... bug killed, post edited .... thx for reporting :D

Skrollster

i know this is a very new feature, but i don't understand why you don't use it..

local tOnlineUsers = frmHub:GetOnlineUsers()
	for i,v in pairs(tOnlineUsers) do
		if v.sName ~= From then
			v:SendPM(Bot,message)
		end
	end

Skrollster

#7
ok.. couldn't resist..

--- code board V2 by plop
--- reached ver v2.8 - Herodes
--[[ ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
 - made for my own hub to seperate chat from code (plop)
 - doesn't repeat to the sender anymore (plop)
 - added away filter (plop)
=---
 - modded a lil bit by Herodes
 - logs the posts of every day, each day opens a new file .. :)
 - done to retrieve past posts ... I thought it would be usefull ..
=---
 - modded a bit more by Herodes 			28/7/2004 9:05 pm
 - Now u can list the files in the log's directory and show any that u may want ...
=---
 = Yet another cb mod by Herodes ...
 - made in Lua 5
 - added ability to post from main ...
 - added ability for users to decide where to receive the posts (main or pm)
 - completely fixed for the Ptx-L5.. ( 15/3 - 2005 )
 - ammended according to plop's observations ( same date more or less )
 - made poss to have the cb msgs turned off for every individual user...
 - NOTE: You DO need to create a directory named 'codelogs' inside your 'scripts' dir.
=---
 - modded by Skrollster, don't know what it does now.. :P
--]] ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

--- Start the script ...
function Main()
	Bot = "CodeBoard"
	tUsers = {}
	logfile = "codelogs/code"..os.date("%d").."-"..os.date("%m")..".txt"
	cbcmd = "cb"
	frmHub:RegBot(Bot, 1, "Post your code in here .. it'll be kept safe with me", "petsagouris@hotmail.com")
end

--- When Mainchat msg arrives ..
function ChatArrival( user, data )
	return CB( user, string.sub( data, 1, -2 ))
end

--- When a pm arrives ...
function ToArrival( user, data )
	if (string.sub( data, 1, string.len(Bot)+5) == "$To: "..Bot) then
		return CB( user, string.sub( data, 1, -2 ),  true )
	end
end

--- Main Handling done here ...
function CB(user, data, how)
	local ok, len = 1, (string.len(cbcmd) +1)
	s,e,chat = string.find(data, "%b<>%s+(.*)")
	s,e,cmd,args = string.find(data, "%b<>%s+%p(%S+)%s*(.*)")
	if (string.sub(cmd, 1,string.len(cbcmd)) == cbcmd) then
		s,e,cmd,args = string.find(data, "%b<>%s+%p(%S+)%s*(.*)")
		if (cmd == cbcmd.."r") then
			if args and args ~= "" then
				SendBack(ReadIt("codelogs/"..args..".txt"), user, how)
			end
			ok = nil; return 1
		elseif (cmd == cbcmd.."l") then
			ListLogs(user, how); ok = nil; return 1
		elseif (cmd == cbcmd.."n") then
			ChangeWay(user, how); ok = nil; return 1
		elseif (cmd == cbcmd.."p") then
			DoPost(user, string.sub(chat, len+2, -1), how); ok = nil; return 1
		elseif (cmd == cbcmd.."h") then
			CBHelp(user, how); ok = nil; return 1
		end
	end
	if ok and how then
		DoPost(user, data, how); return 1
	end
end

--- Semi-Utility Function ...
function LogIt(what)
	local handle, err = io.open(logfile, "a+")
	if handle then
		handle:write("\r\n\r\n- = = @ = =        Start of new input\t= = @ = = -\r\n"..what.."\r\n- = = @ = =\tEnd Of Input\t = = @ = = -")
		handle:close()
	end
end

--- List the log files of the CB...
function ListLogs(user, how)
	os.execute("dir codelogs > codelogs/dirlist.lst")
	local msg = "\r\n\t - Available Logs:\r\n\t"..string.rep("-", 50).." [ listing start ]\r\n"
	for line in io.lines("codelogs/dirlist.lst") do
		local s,e,name = string.find(line, "%s(%S+)%.txt$")
		if name then msg = msg.."\t\t- "..name.."\r\n" end
	end
	os.remove("codelogs/dirlist.lst")
	SendBack(msg, user, how)
end

--- Choose the way the CB will be annoying a user ...
function ChangeWay(user, how)

	if not tUsers[user.sName] then
		tUsers[user.sName] = 1;
		status = "You are now going to be receiving the cb messages in main";
	elseif tUsers[user.sName] == 1 then
		tUsers[user.sName] = 2;
		status = "You are not going to be receiving the cb messages";
	else
		tUsers[user.sName] = nil;
		local status = "You are now going to be receiving the cb messages in pm"
	end
	SendBack(status, user, how)
end

--- Take care of posting in the CB
function DoPost(user, data, out)
	-- local s,e,text = string.find(data, "%$%b<>(.*)")
	if ( text ~= "" ) then
		local curUser
		local signalstr = "\r\n- - - - - - - - - - - - - - - - - - - - - - code board - - - - - - - - - - - - - - - - - - - - - -"
		local line = "\t-- Code by: "..user.sName.." ( on "..(os.date())..")"..signalstr.." [ start ]\r\n"..data..signalstr.."[ end ]"
		LogIt(line)
		
		local tOnlineUsers = frmHub:GetOnlineUsers()
		for i,curUser in pairs(tOnlineUsers) do
			
			local a = curUser.sName
			if ( a ~= user.sName ) then
				if not tUsers[a] then SendBack(line, curUser, true )
				elseif tUsers[a] == 1 then SendBack( line, curUser )
				else SendBack("*** "..user.sName.." has posted on the CodeBoard", curUser)
				end
			elseif (a == user.sName) then
				SendBack("Your code has been send!", user, out)
			end
		end
	end
end
--- Help text ..
function CBHelp(user, how)
	local msg, tC = "\r\n\t These commands are available for the "..Bot.."\r\n"..string.rep("- ", 50).."\r\n",
	   { ["r"] = "read a code board log",
		["l"] = "lists the code boards logs",
		["n"] = "code board messages in pm/main/off",
		["p"] = "post in code board",
		["h"] = "this text",}
	for cmd, explain in tC do
		msg = msg.."\t\t"..cbcmd..cmd.."\t"..explain.."\r\n"
	end
	SendBack(msg, user, how)
end
--- Utility function ..
function ReadIt(file)
	local msg = "\r\n"
	if ( io.input(file) ) then
		text = io.input(file)
		for line in text:lines() do 	msg = msg..line.."\r\n" end
		text:close()
		return msg
	else
		return file.." does not exist"
	end
end

*edit reason: typo*

Skrollster

now some one just need to add a save state of tUsers thingy and it will be perfect..

Skrollster

#9
ok, we found a couple of bugs...

--- code board V2 by plop
--- reached ver v2.8 - Herodes
--[[ ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
 - made for my own hub to seperate chat from code (plop)
 - doesn't repeat to the sender anymore (plop)
 - added away filter (plop)
=---
 - modded a lil bit by Herodes
 - logs the posts of every day, each day opens a new file .. :)
 - done to retrieve past posts ... I thought it would be usefull ..
=---
 - modded a bit more by Herodes 			28/7/2004 9:05 pm
 - Now u can list the files in the log's directory and show any that u may want ...
=---
 = Yet another cb mod by Herodes ...
 - made in Lua 5
 - added ability to post from main ...
 - added ability for users to decide where to receive the posts (main or pm)
 - completely fixed for the Ptx-L5.. ( 15/3 - 2005 )
 - ammended according to plop's observations ( same date more or less )
 - made poss to have the cb msgs turned off for every individual user...
 - NOTE: You DO need to create a directory named 'codelogs' inside your 'scripts' dir.
=---
 - modded by Skrollster, don't know what it does now.. :P
 - fixed a bunch of bugs
 - This version is for ptokax 0.3.3.0 beta 16.06
--]] ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

--- Start the script ...
function Main()
	Bot = "CodeBoard"
	tUsers = {}
	logfile = "codelogs/code"..os.date("%d").."-"..os.date("%m")..".txt"
	cbcmd = "cb"
	frmHub:RegBot(Bot, 1, "Post your code in here .. it'll be kept safe with me", "petsagouris@hotmail.com")
end

--- When Mainchat msg arrives ..
function ChatArrival( user, data )
	return CB( user, string.sub( data, 1, -2 ))
end

--- When a pm arrives ...
function ToArrival( user, data )
	if (string.sub( data, 1, string.len(Bot)+5) == "$To: "..Bot) then
		local s,e,data = string.find(data, "%$(%b<>.*)$")
		return CB( user, string.sub( data, 1, -2 ), true )
	end
end

--- Main Handling done here ...
function CB(user, data, how)
	local ok, len = 1, (string.len(cbcmd) +1)
	s,e,chat = string.find(data, "%b<>%s+(.*)$")
	s,e,cmd,args = string.find(data, "%b<>%s+%p(%S+)%s*(.*)$")
	if cmd and (string.sub(cmd, 1,string.len(cbcmd)) == cbcmd) then
		s,e,cmd,args = string.find(data, "%b<>%s+%p(%S+)%s*(.*)$")
		if (cmd == cbcmd.."r") then
			if args and args ~= "" then
				SendBack(ReadIt("codelogs/"..args..".txt"), user, how)
			end
			ok = nil; return 1
		elseif (cmd == cbcmd.."l") then
			ListLogs(user, how); ok = nil; return 1
		elseif (cmd == cbcmd.."n") then
			ChangeWay(user, how); ok = nil; return 1
		elseif (cmd == cbcmd.."p") then
			DoPost(user, string.sub(chat, len+2, -1), how); ok = nil; return 1
		elseif (cmd == cbcmd.."h") then
			CBHelp(user, how); ok = nil; return 1
		end
	end
	if ok and how then
		DoPost(user, chat, how); return 1
	end
end

--- Semi-Utility Function ...
function LogIt(what)
	local handle, err = io.open(logfile, "a+")
	if handle then
		handle:write("\r\n\r\n- = = @ = =        Start of new input\t= = @ = = -\r\n"..what.."\r\n- = = @ = =\tEnd Of Input\t = = @ = = -")
		handle:close()
	end
end

--- List the log files of the CB...
function ListLogs(user, how)
	os.execute("dir codelogs > codelogs/dirlist.lst")
	local msg = "\r\n\t - Available Logs:\r\n\t"..string.rep("-", 50).." [ listing start ]\r\n"
	for line in io.lines("codelogs/dirlist.lst") do
		local s,e,name = string.find(line, "%s(%S+)%.txt$")
		if name then msg = msg.."\t\t- "..name.."\r\n" end
	end
	os.remove("codelogs/dirlist.lst")
	SendBack(msg, user, how)
end

--- Choose the way the CB will be annoying a user ...
function ChangeWay(user, how)

	local status = "You are now going to be receiving the cb messages in pm"
	if not tUsers[user.sName] then
		tUsers[user.sName] = 1;
		status = "You are now going to be receiving the cb messages in main";
	elseif tUsers[user.sName] == 1 then
		tUsers[user.sName] = 2;
		status = "You are not going to be receiving the cb messages";
	else
		tUsers[user.sName] = nil;
	end
	SendBack(status, user, how)
end

--- Take care of posting in the CB
function DoPost(user, data, out)
	-- local s,e,text = string.find(data, "%$%b<>(.*)")
	if ( text ~= "" ) then
		local curUser
		local signalstr = "\r\n- - - - - - - - - - - - - - - - - - - - - - code board - - - - - - - - - - - - - - - - - - - - - -"
		local line = "\t-- Code by: "..user.sName.." ( on "..(os.date())..")"..signalstr.." [ start ]\r\n"..data..signalstr.."[ end ]"
		LogIt(line)
		
		local tOnlineUsers = frmHub:GetOnlineUsers()
		for i,curUser in pairs(tOnlineUsers) do
			
			local a = curUser.sName
			if ( a ~= user.sName ) then
				if not tUsers[a] then SendBack(line, curUser, true )
				elseif tUsers[a] == 1 then SendBack( line, curUser )
				else SendBack("*** "..user.sName.." has posted on the CodeBoard", curUser)
				end
			elseif (a == user.sName) then
				SendBack("Your code has been send!", user, out)
			end
		end
	end
end
--- Help text ..
function CBHelp(user, how)
	local msg, tC = "\r\n\t These commands are available for the "..Bot.."\r\n"..string.rep("- ", 50).."\r\n",
	   { ["r"] = "read a code board log",
		["l"] = "lists the code boards logs",
		["n"] = "code board messages in pm/main/off",
		["p"] = "post in code board",
		["h"] = "this text",}
	for cmd, explain in tC do
		msg = msg.."\t\t+"..cbcmd..cmd.."\t"..explain.."\r\n"
	end
	SendBack(msg, user, how)
end
--- Utility function ..
function ReadIt(file)
	local msg = "\r\n"
	if ( io.input(file) ) then
		text = io.input(file)
		for line in text:lines() do 	msg = msg..line.."\r\n" end
		text:close()
		return msg
	else
		return file.." does not exist"
	end
end
--- Another Utility function ..
function SendBack(msg, user, out)
	if out then user:SendPM(Bot, msg)
	else user:SendData(Bot, msg)
	end
end

*another one*

Herodes

#10
hmm.. this one saves the user's status... think killed some bugs too .. changed the way some things work too ..
--- code board V2 by plop
--- reached ver v3 - Herodes
--[[ ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
 - made for my own hub to seperate chat from code (plop)
 - doesn't repeat to the sender anymore (plop)
 - added away filter (plop) - Removed it :) /Herodes
=---
 - modded a lil bit by Herodes
 - logs the posts of every day, each day opens a new file .. :)
 - done to retrieve past posts ... I thought it would be usefull ..
=---
 - modded a bit more by Herodes 			28/7/2004 9:05 pm
 - Now u can list the files in the log's directory and show any that u may want ...
=---
 = Yet another cb mod by Herodes ...
 - made in Lua 5
 - added ability to post from main ...
 - added ability for users to decide where to receive the posts (main or pm)
 - completely fixed for the Ptx-L5.. ( 15/3 - 2005 )
 - ammended according to plop's observations ( same date more or less )
 - made poss to have the cb msgs turned off for every individual user...
 - NOTE: You DO need to create a directory named 'codelogs' inside your 'scripts' dir.
=---
 - modded by Skrollster, don't know what it does now.. :P - Its ok I fixed it ;) /Herodes
 - added : saves the user's state now..
 - Note : didn't remove the Connected/Disconnected functions because I didn't want it to fault anywhere.
 - copied : Skrollster's and plop's fixes .. 
 - added : cmd to reset the table/file of users if-when it gets too large.
--]] ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----


--- Start the script ...
function Main()
	Bot = "CodeBoard"
	tUsers = {}
	logfile = os.date("codelogs/code%d-%m.txt")
	cbcmd = "cb"
	LoadFromFile("codelogs/cb.dat")
	frmHub:RegBot(Bot, 1, "Post your code in here .. it'll be kept safe with me", "petsagouris@hotmail.com")
end

--- When Mainchat msg arrives ..
function ChatArrival( user, data )
	if not tUsers[user.sName] then tUsers[user.sName] = 1 end
	return CB( user, string.sub( data, 1, -2 ))
end

--- When a pm arrives ...
function ToArrival( user, data )
	if not tUsers[user.sName] then tUsers[user.sName] = 1 end
	if (string.sub( data, 1, string.len(Bot)+5) == "$To: "..Bot) then
		local s,e,data = string.find(data, "%$(%b<>.*)$")
		return CB( user, string.sub( data, 1, -2 ), true )
	end
end

--- Main Handling done here ...
function CB(user, data, how)
	local ok, len = 1, (string.len(cbcmd) +1)
	s,e,chat = string.find(data, "%b<>%s+(.*)$")
	s,e,cmd,args = string.find(data, "%b<>%s+%p(%S+)%s*(.*)$")
	if cmd and (string.sub(cmd, 1,string.len(cbcmd)) == cbcmd) then
		s,e,cmd,args = string.find(data, "%b<>%s+%p(%S+)%s*(.*)$")
		if (cmd == cbcmd.."r") then
			if args and args ~= "" then
				SendBack(ReadIt("codelogs/"..args..".txt"), user, how)
			end
			ok = nil; return 1
		elseif (cmd == cbcmd.."l") then
			ListLogs(user, how); ok = nil; return 1
		elseif (cmd == cbcmd.."n") then
			ChangeWay(user, how); ok = nil; return 1
		elseif (cmd == cbcmd.."p") then
			DoPost(user, string.sub(chat, len+2, -1), how); ok = nil; return 1
		elseif (cmd == cbcmd.."h") then
			CBHelp(user, how); ok = nil; return 1
		elseif (cmd == cbcmd.."d") then
			ResetUsers(user, how); ok = nil; return 1
		end
	end
	if ok and how then
		DoPost(user, chat, how); return 1
	end
end
--- Reseting the tUsers
function ResetUsers( user, how )
	local tot = 0
	for i,v in tUsers do tot = tot + 1 end
	tUsers = {}; OnExit();
	SendBack("There were "..tot.." users deleted from my table...", user, how)
end
--- Semi-Utility Function ...
function LogIt(what)
	local handle, err = io.open(logfile, "a+")
	if handle then
		handle:write("\r\n\r\n- = = @ = =        Start of new input\t= = @ = = -\r\n"..what.."\r\n- = = @ = =\tEnd Of Input\t = = @ = = -")
		handle:close()
	end
end

--- List the log files of the CB...
function ListLogs(user, how)
	os.execute("dir codelogs > codelogs/dirlist.lst")
	local msg = "\r\n\t - Available Logs:\r\n\t"..string.rep("-", 50).." [ listing start ]\r\n"
	for line in io.lines("codelogs/dirlist.lst") do
		local s,e,name = string.find(line, "%s(%S+)%.txt$")
		if name then msg = msg.."\t\t- "..name.."\r\n" end
	end
	os.remove("codelogs/dirlist.lst")
	SendBack(msg, user, how)
end

--- Choose the way the CB will be annoying a user ...
function ChangeWay(user, how)
	local tMsgs = 
		{ "You are now going to be receiving the cb messages in main",
		"You are now going to be receiving the cb messages in pm",
		"You are not going to be receiving the cb messages",}
	tUsers[user.sName] = tUsers[user.sName] + 1
	if tUsers[user.sName] > 3 then tUsers[user.sName] = 1 end
	SendBack(tMsgs[tUsers[user.sName]], user, how)
end

--- Take care of posting in the CB
function DoPost(user, data, out)
	local signalstr = "\r\n- - - - - - - - - - - - - - - - - - - - - - code board - - - - - - - - - - - - - - - - - - - - - -"
	local line = "\t-- Code by: "..user.sName.." ( on "..(os.date())..")"..signalstr.." [ start ]\r\n"..data..signalstr.."[ end ]"
	LogIt(line)
	for a,b in pairs(frmHub:GetOnlineUsers()) do
		if b.sName ~= user.sName then
			if tUsers[b.sName] then
				if tUsers[b.sName] == 1 then SendBack( line, b )
				elseif tUsers[b.sName] == 2 then SendBack( line, b , true )
				else SendBack( "*** "..user.sName.." has posted on the CodeBoard", b )
				end
			else
				tUsers[b.sName] = 1
				SendBack ( line , b, true )
			end
		else
			SendBack ( "Your Code has been sent!", user, out )
		end
	end
end

--- Help text ..
function CBHelp(user, how)
	local msg, tC = "\r\n\t These commands are available for the "..Bot.."\r\n"..string.rep("- ", 50).."\r\n",
	   { ["r"] = "read a code board log",
		["l"] = "lists the code boards logs",
		["n"] = "code board messages in pm/main/off",
		["p"] = "post in code board",
		["d"] = "reset the table of users",
		["h"] = "this text",}
	for cmd, explain in tC do
		msg = msg.."\t\t+"..cbcmd..cmd.."\t"..explain.."\r\n"
	end
	SendBack(msg, user, how)
end
--- Utility function ..
function ReadIt(file)
	local msg = "\r\n"
	if ( io.input(file) ) then
		text = io.input(file)
		for line in text:lines() do 	msg = msg..line.."\r\n" end
		text:close()
		return msg
	else
		return file.." does not exist"
	end
end
--- Another Utility function ..
function SendBack(msg, user, out)
	if out then user:SendPM(Bot, msg)
	else user:SendData(Bot, msg)
	end
end

--- Live users in the table pls ..
function MyInfoArrival( user, data)
	if not tUsers[user.sName] then  tUsers[user.sName] = 1 end
end

--- Take care of the logins/outs ..
function OpConnected(user)
	if not tUsers[user.sName] then  tUsers[user.sName] = 1 end
end

NewUserConnected = OpConnected

function OpDisconnected(user)
	if ( tUsers[user.sName] ) then tUsers[user.sName] = nil end
end

UserDisconnected = OpDisconnected

function OnExit()
	SaveToFile("codelogs/cb.dat" , tUsers , "-- Created by [codeboard.lua] on "..os.date().."\ntUsers") -- abandon ship!
end

function Serialize(tTable, sTableName, sTab)
	sTab = sTab or "";
	sTmp = ""
	sTmp = sTmp..sTab..sTableName.." = {\n"
	for key, value in tTable do
		local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
		if(type(value) == "table") then
			sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
		else
			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
			sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
		end

		sTmp = sTmp..",\n"
	end
	sTmp = sTmp..sTab.."}"
	return sTmp
end

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

function LoadFromFile(file)
	local handle = io.open(file,"r")
	if (handle ~= nil) then
		loadstring(handle:read("*all"))
		handle:flush()
		handle:close()
	end
end

Herodes

I suppose it needed some work at the edges...
thxto the ppl who nagged ;)
--- code board V2 by plop
--- reached ver v3 - Herodes
--[[ ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
 - made for my own hub to seperate chat from code (plop)
 - doesn't repeat to the sender anymore (plop)
 - added away filter (plop) - Removed it :) /Herodes
=---
 - modded a lil bit by Herodes
 - logs the posts of every day, each day opens a new file .. :)
 - done to retrieve past posts ... I thought it would be usefull ..
=---
 - modded a bit more by Herodes 			28/7/2004 9:05 pm
 - Now u can list the files in the log's directory and show any that u may want ...
=---
 = Yet another cb mod by Herodes ... ( Lua 5 )
 - added : ability to post from main ...
 - added : ability for users to decide where to receive the posts (main or pm)
 - completely fixed for the Ptx-L5.. ( 15/3 - 2005 )
 - fixed : according to plop's observations ( same date more or less )
 - added : the cb messages can be turned off for every individual user...
 - note : You need to create a directory named 'codelogs' inside your 'scripts' directory.
=---
 - added : using the frmHub:GetOnlineUsers() function ( Skrollster )
 - added : saves the user's state now..
 - note : Didn't remove the Connected/Disconnected functions because I didn't want it to fault anywhere.
=--- 21/3/2005
 - fixed : The loading of the user status table now works.
 - fixed : Users are now receiving in pm by default..
--]] ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
tUsers = {}

--- Start the script ...
function Main()
	Bot = "CodeBoard"
	logfile = os.date("codelogs/code%d-%m.txt")
	cbcmd = "+cb"
	LoadFromFile("codelogs/cb.dat")
	frmHub:RegBot(Bot, 1, "Post your code in here .. it'll be kept safe with me", "petsagouris@hotmail.com")
end

--- When Mainchat msg arrives ..
function ChatArrival( user, data )
	if not tUsers[user.sName] then tUsers[user.sName] = 1 end
	return CB( user, string.sub( data, 1, -2 ))
end

--- When a pm arrives ...
function ToArrival( user, data )
	if not tUsers[user.sName] then tUsers[user.sName] = 1 end
	if (string.sub( data, 1, string.len(Bot)+5 ) == "$To: "..Bot) then
		return CB( user, string.sub( data, 1, -2 ),  true )
	end
end

--- Main Handling done here ...
function CB(user, data, how)
	local ok, len = 1, (string.len(cbcmd) +1)
	s,e,chat = string.find(data, "%b<>%s+(.*)")
	if (string.sub(chat, 1,string.len(cbcmd)) == cbcmd) then
		s,e,cmd,args = string.find(data, "%b<>%s+(%S+)%s*(.*)")
		if (string.sub(cmd, len,len) == "r") then
			if args and args ~= "" then
				SendBack(ReadIt("codelogs/"..args..".txt"), user, how)
			end
			ok = nil; return 1
		elseif (string.sub(cmd, len,len) == "l") then
			ListLogs(user, how); ok = nil; return 1
		elseif (string.sub(cmd, len, len) == "n") then
			ChangeWay(user, how); ok = nil; return 1
		elseif (string.sub(cmd, len, len) == "p") then
			DoPost(user, string.sub(chat, len+2, -1), how); ok = nil; return 1
		elseif (string.sub(cmd, len, len) == "h") then
			CBHelp(user, how); ok = nil; return 1
		elseif (string.sub(cmd, len, len) == "i") then
			local msg = ""; for i,v in tUsers do msg = msg.."\n\t"..i.."\t-\t"..v; end
			user:SendData(Bot, msg );
		end
	end
	if ok and how then
		DoPost(user, data, how); return 1
	end
end

--- Semi-Utility Function ...
function LogIt(what)
	local handle, err = io.open(logfile, "a+")
	if handle then
		handle:write("\r\n\r\n- = = @ = =        Start of new input\t= = @ = = -\r\n"..what.."\r\n- = = @ = =\tEnd Of Input\t = = @ = = -")
		handle:close()
	end
end

--- List the log files of the CB...
function ListLogs(user, how)
	os.execute("dir codelogs > codelogs/dirlist.lst")
	local msg = "\r\n\t - Available Logs:\r\n\t"..string.rep("-", 50).." [ listing start ]\r\n"
	for line in io.lines("codelogs/dirlist.lst") do
		local s,e,name = string.find(line, "%s(%S+)%.txt$")
		if name then msg = msg.."\t\t- "..name.."\r\n" end
	end
	os.remove("codelogs/dirlist.lst")
	SendBack(msg, user, how)
end

--- Choose the way the CB will be annoying a user ...
function ChangeWay(user, how)
	local tMsgs = { "You are now going to be receiving the cb messages in pm",
		"You are now going to be receiving the cb messages in main",
		"You are not going to be receiving the cb messages",}
	tUsers[user.sName] = tUsers[user.sName] + 1
	if tUsers[user.sName] > 3 then tUsers[user.sName] = 1 end
	SendBack(tMsgs[tUsers[user.sName]], user, how)
end

--- Take care of posting in the CB
function DoPost(user, data, out)
	-- local s,e,text = string.find(data, "%$%b<>(.*)")
	if ( text ~= "" ) then
		local curUser
		local signalstr = "\r\n- - - - - - - - - - - - - - - - - - - - - - code board - - - - - - - - - - - - - - - - - - - - - -"
		local line = "\t-- Code by: "..user.sName.." ( on "..(os.date())..")"..signalstr.." [ start ]\r\n"..data..signalstr.."[ end ]"
		LogIt(line)
		for a,b in pairs(frmHub:GetOnlineUsers()) do
			if b.sName ~= user.sName then
				if tUsers[b.sName] then
					if tUsers[b.sName] == 1 then SendBack( line, b, true )
					elseif tUsers[b.sName] == 2 then SendBack( line, b )
					else SendBack( "*** "..user.sName.." has posted on the CodeBoard", b )
					end
				else
					tUsers[b.sName] = 1
					SendBack ( line , b, true )
				end
			else
				SendBack ( "Your Code has been sent!", user, out )
			end
		end
	end
end

--- Help text ..
function CBHelp(user, how)
	local msg, tC = "\r\n\t These commands are available for the "..Bot.."\n"..string.rep("- ", 50).."\r\n",
	   { ["r"] = "read a code board log",
		["l"] = "lists the code boards logs",
		["n"] = "code board messages in pm/main/off",
		["p"] = "post in code board",
		["h"] = "this text",}
	for cmd, explain in tC do
		msg = msg.."\t\t"..cbcmd..cmd.."\t"..explain.."\n"
	end
	SendBack(msg, user, how)
end
--- Utility function ..
function ReadIt(file)
	local msg = "\n"
	if ( io.input(file) ) then
		text = io.input(file)
		for line in text:lines() do 	msg = msg..line.."\n" end
		text:close()
		return msg
	else
		return file.." does not exist"
	end
end
--- Another Utility function ..
function SendBack(msg, user, out)
	if out then user:SendPM(Bot, msg)
	else user:SendData(Bot, msg)
	end
end

--- Live users in the table pls ..
function MyInfoArrival( user, data)
	if not tUsers[user.sName] then  tUsers[user.sName] = 1 end
end

--- Take care of the logins/outs ..
function OpConnected(user)
	if not tUsers[user.sName] then  tUsers[user.sName] = 1 end
end

NewUserConnected = OpConnected

function OpDisconnected(user)
	if ( tUsers[user.sName] ) then tUsers[user.sName] = nil end
end

UserDisconnected = OpDisconnected

function OnExit()
	SaveToFile("codelogs/cb.dat" , tUsers , "-- Created by [codeboard.lua] on "..os.date().."\ntUsers") -- abandon ship!
end

function Serialize(tTable, sTableName, sTab)
	sTab = sTab or "";
	sTmp = ""
	sTmp = sTmp..sTab..sTableName.." = {\n"
	for key, value in tTable do
		local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
		if(type(value) == "table") then
			sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
		else
			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
			sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
		end

		sTmp = sTmp..",\n"
	end
	sTmp = sTmp..sTab.."}"
	return sTmp
end

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

function LoadFromFile(file)
	local handle = io.open(file,"r")
	if handle then dofile(file) end
end

plop

fixed the pm bug.
--- code board V2 by plop
--- reached ver v3 - Herodes
--[[ ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
 - made for my own hub to seperate chat from code (plop)
 - doesn't repeat to the sender anymore (plop)
 - added away filter (plop) - Removed it :) /Herodes
=---
 - modded a lil bit by Herodes
 - logs the posts of every day, each day opens a new file .. :)
 - done to retrieve past posts ... I thought it would be usefull ..
=---
 - modded a bit more by Herodes 			28/7/2004 9:05 pm
 - Now u can list the files in the log's directory and show any that u may want ...
=---
 = Yet another cb mod by Herodes ... ( Lua 5 )
 - added : ability to post from main ...
 - added : ability for users to decide where to receive the posts (main or pm)
 - completely fixed for the Ptx-L5.. ( 15/3 - 2005 )
 - fixed : according to plop's observations ( same date more or less )
 - added : the cb messages can be turned off for every individual user...
 - note : You need to create a directory named 'codelogs' inside your 'scripts' directory.
=---
 - added : using the frmHub:GetOnlineUsers() functino ( Skrollster )
 - added : saves the user's state now..
 - note : Didn't remove the Connected/Disconnected functions because I didn't want it to fault anywhere.
=--- 21/3/2005
 - fixed : The loading of the user status table now works.
 - fixed : Users are now receiving in pm by default..
--]] ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
tUsers = {}

--- Start the script ...
function Main()
	Bot = "CodeBoard"
	logfile = os.date("codelogs/code%d-%m.txt")
	cbcmd = "+cb"
	LoadFromFile("codelogs/cb.dat")
	frmHub:RegBot(Bot, 1, "Post your code in here .. it'll be kept safe with me", "petsagouris@hotmail.com")
end

--- When Mainchat msg arrives ..
function ChatArrival( user, data )
	if not tUsers[user.sName] then tUsers[user.sName] = 1 end
	return CB( user, string.sub( data, 1, -2 ))
end

--- When a pm arrives ...
function ToArrival( user, data )
	if not tUsers[user.sName] then tUsers[user.sName] = 1 end
	if (string.sub( data, 1, string.len(Bot)+5 ) == "$To: "..Bot) then
		local s,e,text = string.find(data, "$(%b<>.*)")
		return CB( user, string.sub( text, 1, -2 ),  true )
	end
end

--- Main Handling done here ...
function CB(user, data, how)
	local ok, len = 1, (string.len(cbcmd) +1)
	s,e,chat = string.find(data, "%b<>%s+(.+)")
	if (string.sub(chat, 1,string.len(cbcmd)) == cbcmd) then
		s,e,cmd,args = string.find(data, "%b<>%s+(%S+)%s*(.*)")
		if (string.sub(cmd, len,len) == "r") then
			if args and args ~= "" then
				SendBack(ReadIt("codelogs/"..args..".txt"), user, how)
			end
			ok = nil; return 1
		elseif (string.sub(cmd, len,len) == "l") then
			ListLogs(user, how); ok = nil; return 1
		elseif (string.sub(cmd, len, len) == "n") then
			ChangeWay(user, how); ok = nil; return 1
		elseif (string.sub(cmd, len, len) == "p") then
			DoPost(user, string.sub(chat, len+2, -1), how); ok = nil; return 1
		elseif (string.sub(cmd, len, len) == "h") then
			CBHelp(user, how); ok = nil; return 1
		elseif (string.sub(cmd, len, len) == "i") then
			local msg = ""; for i,v in tUsers do msg = msg.."\n\t"..i.."\t-\t"..v; end
			user:SendData(Bot, msg );
		end
	end
	if ok and how then
		DoPost(user, (chat or data), how); return 1
	end
end

--- Semi-Utility Function ...
function LogIt(what)
	local handle, err = io.open(logfile, "a+")
	if handle then
		handle:write("\r\n\r\n- = = @ = =        Start of new input\t= = @ = = -\r\n"..what.."\r\n- = = @ = =\tEnd Of Input\t = = @ = = -")
		handle:close()
	end
end

--- List the log files of the CB...
function ListLogs(user, how)
	os.execute("dir codelogs > codelogs/dirlist.lst")
	local msg = "\r\n\t - Available Logs:\r\n\t"..string.rep("-", 50).." [ listing start ]\r\n"
	for line in io.lines("codelogs/dirlist.lst") do
		local s,e,name = string.find(line, "%s(%S+)%.txt$")
		if name then msg = msg.."\t\t- "..name.."\r\n" end
	end
	os.remove("codelogs/dirlist.lst")
	SendBack(msg, user, how)
end

--- Choose the way the CB will be annoying a user ...
function ChangeWay(user, how)
	local tMsgs = { "You are now going to be receiving the cb messages in pm",
		"You are now going to be receiving the cb messages in main",
		"You are not going to be receiving the cb messages",}
	tUsers[user.sName] = tUsers[user.sName] + 1
	if tUsers[user.sName] > 3 then tUsers[user.sName] = 1 end
	SendBack(tMsgs[tUsers[user.sName]], user, how)
end

--- Take care of posting in the CB
function DoPost(user, data, out)
	-- local s,e,text = string.find(data, "%$%b<>(.*)")
	if ( text ~= "" ) then
		local curUser
		local signalstr = "\r\n- - - - - - - - - - - - - - - - - - - - - - code board - - - - - - - - - - - - - - - - - - - - - -"
		local line = "\t-- Code by: "..user.sName.." ( on "..(os.date())..")"..signalstr.." [ start ]\r\n"..data..signalstr.."[ end ]"
		LogIt(line)
		for a,b in pairs(frmHub:GetOnlineUsers()) do
			if b.sName ~= user.sName then
				if tUsers[b.sName] then
					if tUsers[b.sName] == 1 then SendBack( line, b, true )
					elseif tUsers[b.sName] == 2 then SendBack( line, b )
					else SendBack( "*** "..user.sName.." has posted on the CodeBoard", b )
					end
				else
					tUsers[b.sName] = 1
					SendBack ( line , b, true )
				end
			else
				SendBack ( "Your Code has been sent!", user, out )
			end
		end
	end
end

--- Help text ..
function CBHelp(user, how)
	local msg, tC = "\r\n\t These commands are available for the "..Bot.."\n"..string.rep("- ", 50).."\r\n",
	   { ["r"] = "read a code board log",
		["l"] = "lists the code boards logs",
		["n"] = "code board messages in pm/main/off",
		["p"] = "post in code board",
		["h"] = "this text",}
	for cmd, explain in tC do
		msg = msg.."\t\t"..cbcmd..cmd.."\t"..explain.."\n"
	end
	SendBack(msg, user, how)
end
--- Utility function ..
function ReadIt(file)
	local msg = "\n"
	if ( io.input(file) ) then
		text = io.input(file)
		for line in text:lines() do 	msg = msg..line.."\n" end
		text:close()
		return msg
	else
		return file.." does not exist"
	end
end
--- Another Utility function ..
function SendBack(msg, user, out)
	if out then user:SendPM(Bot, msg)
	else user:SendData(Bot, msg)
	end
end

--- Live users in the table pls ..
function MyInfoArrival( user, data)
	if not tUsers[user.sName] then  tUsers[user.sName] = 1 end
end

--- Take care of the logins/outs ..
function OpConnected(user)
	if not tUsers[user.sName] then  tUsers[user.sName] = 1 end
end

NewUserConnected = OpConnected

function OpDisconnected(user)
	if ( tUsers[user.sName] ) then tUsers[user.sName] = nil end
end

UserDisconnected = OpDisconnected

function OnExit()
	SaveToFile("codelogs/cb.dat" , tUsers , "-- Created by [codeboard.lua] on "..os.date().."\ntUsers") -- abandon ship!
end

function Serialize(tTable, sTableName, sTab)
	sTab = sTab or "";
	sTmp = ""
	sTmp = sTmp..sTab..sTableName.." = {\n"
	for key, value in tTable do
		local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
		if(type(value) == "table") then
			sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
		else
			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
			sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
		end

		sTmp = sTmp..",\n"
	end
	sTmp = sTmp..sTab.."}"
	return sTmp
end

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

function LoadFromFile(file)
	local handle = io.open(file,"r")
	if handle then dofile(file) end
end


function OnError(ErrorMsg)
   SendToAll(Bot, ErrorMsg.."|")
   local fFile = io.open("error/codeboard.lst", "a+")
   fFile:write(ErrorMsg.."\n")
   fFile:close()
end

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

SMF spam blocked by CleanTalk