Chatroom Help
 

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

Chatroom Help

Started by Yahoo, 05 February, 2007, 15:58:56

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yahoo

I have edited chatroom commands for my requirements but i am getting syntax error can anyone try to solve it
Syntax ...\chatroom noerrors1.lua:157: attempt to index local 'f' (a nil value)

Code: lua
-- chatrooms v3 by tezlo
-- Lua 5 version by jiten
-- fixed chatroom loading/saving onexit by jiten (5/28/2005)
-- Changed: Commands structure (5/29/2005)
-- Changed: Chatrooms don't have key now
-- Added: Rightclick support

tCmds = {
	MakeChat = "createroom",
	Away = "away",
	Leave = "exit",
	list = "list",
	Invite = "invite",
	Remove = "remove",
	DelChat = "delchat",
}

Main = function()
	chatrooms:load()
end

OnExit = function()
	chatrooms:save()
end

ChatArrival = function(user, data)
	local s, e, cmd, args = string.find(data, "^%b<> %!(%a+)%s*(.*)|$")
	if cmd == tCmds.createroom and user.bRegistered then
		local s, e, name, profiles = string.find(args, "(%S+)%s*(.*)")
		if not s then
			user:SendData(">> Syntax: !createroom <name> [groups]")
		elseif chatrooms.items[name] then	
			user:SendData(">> "..name.." is already a Chatroom.")
		elseif GetItemByName(name) then
			user:SendData(">> There is a user with that name")
		else
			frmHub:RegBot(name,0,"","")
			local tmp = chatrooms:new(name, user.sName)
			string.gsub(profiles, "(%S+)", function(profile)
				profile = tonumber(profile) or GetProfileIdx(profile)
				if GetProfileName(profile) then tmp.groups[profile] = 1 end
			end); tmp:chat("Hello", name)
			chatrooms:save()
			return 1
		end
	end
end

ToArrival = function(user,data)
	local s, e, to, str = string.find(data, "^$To: (%S+) From: %S+ $%b<> (.*)|$")
	if chatrooms.items[to] then
		local tmp = chatrooms.items[to]
		if not tmp.list[user.sName] then
			if user.bOperator or tmp.groups[user.iProfile] == 1 then
				tmp.list[user.sName] = 1
				tmp:chat(user.sName.." joined", to)
				tmp:chat(str, user.sName)
				chatrooms:save()
			else
				user:SendPM(to, "You're not a member here.")
			end
		else
			local isowner = (tmp.owner == user.sName)
			local s, e, cmd, args = string.find(str, "^%!(%a+)%s*(.*)$")
			if not s then
				tmp.list[user.sName] = 1
				tmp:chat(str, user.sName)
			elseif cmd == tCmds.Away then
				tmp:chat(user.sName.." is away.. "..args, to)
				tmp.list[user.sName] = 0
			elseif cmd == tCmds.exit then
				tmp:chat(user.sName.." left. "..args, to)
				tmp.list[user.sName] = nil
				chatrooms:save()
			elseif cmd == tCmds.list then
				local n, na, msg = 0, 0
				for nick, stat in tmp.list do
					if not GetItemByName(nick) then msg = " (offline)"
					elseif stat == 0 then msg = " (away)"
					else msg, na = "", na+1
					end; n = n+1
					user:SendPM(to, "\t"..nick..msg)
				end; user:SendPM(to, na.."/"..n.." active list.")
			elseif cmd == tCmds.Invite then
				string.gsub(args, "(%S+)", function(nick)
					if not tmp.list[nick] then
						tmp.list[nick] = 1
						tmp:chat(nick.." has been invited to the room. Type !leave to leave, and !list to see who's invited.", to)
					end
				end); chatrooms:save()
			elseif cmd == tCmds.Remove and isowner then
				string.gsub(args, "(%S+)", function(nick)
					if tmp.list[nick] and nick ~= tmp.owner then
						tmp:chat(nick.." has been removed from the room", to)
						tmp.list[nick] = nil
					end
				end); chatrooms:save()
			elseif cmd == tCmds.DelChat and isowner then
				tmp:chat("End of session.", to)
				chatrooms.items[to] = nil
				chatrooms:save()
				frmHub:UnregBot(to)
			else
				tmp:chat(str, user.sName)
			end
		end; return 1
	end
end

botchat = function(self, msg, from)
	for nick, id in self.list do
		if nick ~= from and id == 1 then
			SendToNick(nick, "$To: "..nick.." From: "..self.name.." $<"..from.."> "..msg)
		end
	end
end

chatrooms = {
	new = function(self, name, owner)
		local tmp = {
			name = name,
			owner = owner,
			groups = {},
			list = { [owner] = 1 },
			chat = botchat
		}; self.items[name] = tmp
		return tmp
	end,

	load = function(self)
		self.items = dofile("logs/chatrooms.tbl") or {}
		for name, room in self.items do
			frmHub:RegBot(name,0,"","")
			room.chat = botchat
			room:chat("Hello", name)
		end
	end,

	save = function(self)
		if loadfile("logs/chatrooms.tbl") then 
			local f = io.open("logs/chatrooms.tbl", "w+")
			f:write("return {\n");
			for name, tmp in self.items do
				f:write(string.format("\t[%q] = {\n\t\tname = %q,\n\t\towner = %q,\n\t\tgroups = {\n", name, tmp.name, tmp.owner))
				for id, stat in tmp.groups do
					f:write(string.format("\t\t\t[%d] = %d,\n", id, stat))
				end; f:write("\t\t},\n\t\tlist = {\n")
				for nick, stat in tmp.list do
					f:write(string.format("\t\t\t[%q] = %d,\n", nick, stat))
				end; 
				f:write("\t\t}\n\t},\n");
			end; 
			f:write("}"); f:close()
		else
			local f = io.open("logs/chatrooms.tbl", "w+")
			f:write("return {\n"); f:write("}"); f:close()
		end
	end
}

NewUserConnected = function(user)
	user:SendData("$UserCommand 1 2 Chatrooms\\exit$&#36;To: %[line:Chatroom] From: %[mynick] $<%[mynick]> !"..tCmds.exit.."&#124;|")
	user:SendData("$UserCommand 1 2 Chatrooms\\list$&#36;To: %[line:Chatroom] From: %[mynick] $<%[mynick]> !"..tCmds.list.."&#124;|")
	user:SendData("$UserCommand 1 2 Chatrooms\\Away$&#36;To: %[line:Chatroom] From: %[mynick] $<%[mynick]> !"..tCmds.Away.."&#124;|")
	user:SendData("$UserCommand 1 3 Chatrooms\\createroom$<%[mynick]> !"..tCmds.MakeChat.." %[line:Chatroom]&#124;|")
	user:SendData("$UserCommand 1 2 Chatrooms\\Remove$&#36;To: %[line:Chatroom] From: %[mynick] $<%[mynick]> !"..tCmds.Remove.." %[line:Nick]&#124;|")
end

OpConnected = function(user)
	NewUserConnected(user)
	user:SendData("$UserCommand 1 2 Chatrooms\\Delete$&#36;To: %[line:Chatroom] From: %[mynick] $<%[mynick]> !"..tCmds.DelChat.." %[line:Chatroom]&#124;|")
	user:SendData("$UserCommand 1 2 Chatrooms\\Invite$&#36;To: %[line:Chatroom] From: %[mynick] $<%[mynick]> !"..tCmds.Invite.." %[line:Nick]&#124;|")
end


And one more request can someone add the options of making publicrooms and privaterooms in the script plzzzzzzzz
Thanks In Advance

*EDIT* added CodeTag's //Typhoon
"BoRN FIGhTEr"

SMF spam blocked by CleanTalk