Multi-room chatting
 

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

Multi-room chatting

Started by cbill, 24 May, 2004, 20:50:48

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

cbill

Okay, so I got bored and now I waster my BW using a DC++ hub, but I don't know how to script it, and I had a most fabulous idea for a bot too.

A multi-room chatbot, that works through pm.

The chatbot sits in the main room, and you issue commands as a user that can work it:
#roomlist lists the current rooms that have users in them
#join allows you to join a room, if t exists
#make creates a room and autojoins it
 thats in the main console for plain users

the chat room operates off of the private messages, the bot keeps a record of what nick is in a room, and if someone sends a pm o the bot from that room, then the message will be forewarded to the rest of the users in that room.  if a user is inactive for too long, and doesnt have a special status like op or whatnot its dropped form the list and must join that room to chat there again

commands from the main room can also be pmed tpo the chatbot if theya re not in a room.

if a room becomes empty at any time for any reason, then it will be closed by taking it off the names list.

op commands can come later or arent neccessary.

permanent rooms are in a text file specified in the script, will be made if dont exist.

so
#makeroom whatever
...joining whatever
..talk talk talk...
#part
(cheks if empty (no? ok, yes? remove))
#join room
...joining room
#part


you get the point...

if you could make this id be so very thankful!!!

Corayzon

#1
hey cbill =]

this is a scripts i wrote ages ago when i had the same idea...and it functions just as you would like, but it is old and can be optimized for better proformance...

but newayz...

-- Corayzon's Side-Bot Light 1.0 Beta

--// BotName
sBot = "-ChatRoom-Bot-"

tChatRoom = {}
iChatRoom = {}
tRoomList = {}

-- TO DO LIST
-------------
-- 
-- 

--///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
--// Main function
--///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Main()
	frmHub:EnableSearchData(1)
	frmHub:EnableFullData(1)
	frmHub:RegBot(sBot)
end

--///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
--// Data arrival from client on server
--///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function DataArrival(user, data)
	
	data=strsub(data,1,strlen(data)-1) 
	_,_,cmd=strfind(data, "%b<>%s+(%S+)")
	_,_,toChatRoom=strfind(data, "$To: (%S+)")
	_,_,sMessage=strfind(data, "$<(.+)")

	-- Hub ChatRoom Commands
	if cmd == "+startchatroom" then
		doStartChatRoom(user, data)
		return 1

	elseif cmd == "+joinchatroom" then
		doJoinChatRoom(user, data)

	elseif cmd == "+chatrooms" then
		getChatRooms(user)
	end

	-- ChatRoom Initailisation Process
	if toChatRoom ~= nil then
		if toChatRoom == sBot then
			if tChatRoom[toChatRoom]["status"] == "ChatRoomName" then

			end
		end
	end

	-- ChatRoom Commands
	if toChatRoom ~= nil then
		if tChatRoom ~= nil then
			if tChatRoom[toChatRoom]["running"] ~= nil then

				if cmd == "+leave" then
					tChatRoom[toChatRoom]["userlist"][user.sName] = nil
					tChatRoom[toChatRoom]["n"] = tChatRoom[toChatRoom]["n"] - 1
					SendDataToChatRoom(toChatRoom, user.sName, "***"..user.sName.." has left the Chat Room")

				elseif cmd == "+quit" then
					if user.sName == tChatRoom[toChatRoom]["owner"] then
						SendDataToChatRoom(toChatRoom, user.sName, "***"..user.sName.." has closed the Chat Room")
						tChatRoom[toChatRoom] = nil
						frmHub:UnregBot(toChatRoom)
						SendToAll(sBot, "***"..user.sName.." has stopped the chatroom "..sRoomName..". Use +chatrooms to see the current chat rooms")
					end

				elseif cmd == "+userlist" then

					local sOut = "\r\n\r\n\tC h a t   R o o m   U s e r L i s t\r\n\r\n"
					for username, suspects in tChatRoom[toChatRoom]["userlist"] do
						sOut=sOut.."\t\t"..username.."\r\n"
					end
					sOut=sOut.."\t\tCount: "..tChatRoom[toChatRoom]["n"].."\r\n\r\n"
					SendPmToNick(user.sName, toChatRoom, sOut)
				end
			end
		end
	end

	-- Send ChatRoom Message
	if toChatRoom ~= nil then
		if tChatRoom ~= nil then
			if tChatRoom[toChatRoom]["running"] ~= nil then
				if tChatRoom[toChatRoom]["userlist"][user.sName] ~= nil then
					SendDataToChatRoom(toChatRoom, user.sName, "<"..sMessage)
					return 1
				end
			end
		end
	end
end


function SendDataToChatRoom(sChatRoom, sUserName, sMessage)
	for username, suspects in tChatRoom[sChatRoom]["userlist"] do
		if user.sName ~= username then
			SendPmToNick(username, sChatRoom, sMessage)
		end
	end
end

function doStartChatRoom(user, data)

	_,_,cmd,sRoomName=strfind(data, "%b<>%s+(%S+)%s+(.+)")

	if sRoomName ~= nil then

		tChatRoom[sRoomName] = {}
		tChatRoom[sRoomName]["userlist"] = {}
		tRoomList[sRoomName] = sRoomName
		frmHub:RegBot(sRoomName)

		tChatRoom[sRoomName]["owner"] = user.sName
		tChatRoom[sRoomName]["userlist"][user.sName] = user.sName
		tChatRoom[sRoomName]["n"] = 1
		tChatRoom[sRoomName]["running"] = "1"
		SendToAll(sBot, "***"..user.sName.." has started the chatroom "..sRoomName..". User +joinchatroom "..sRoomName.." to join")
		
	end
end

function doJoinChatRoom(user, data)

	_,_,cmd,sRoomName=strfind(data, "%b<>%s+(%S+)%s+(.+)")

	if sRoomName ~= nil then
		if tChatRoom[sRoomName] ~= nil then
			if tChatRoom[sRoomName]["running"] ~= nil then
				if tChatRoom[sRoomName]["userlist"][user.sName] == nil then

					tChatRoom[sRoomName]["userlist"][user.sName] = user.sName
					tChatRoom[sRoomName]["n"] = tChatRoom[sRoomName]["n"] + 1
					SendDataToChatRoom(sRoomName, user.sName, "***"..user.sName.." has just connected to the chat room")

				end
			end
		end
	end
end

function getChatRooms(user)
	local sOut = "\r\n\r\n\tC h a t   R o o m s   L i s t\r\n\r\n"
	for roomname, suspects in tRoomList do
		sOut=sOut.."\t\t"..roomname.."\t"..tChatRoom[roomname]["n"].."\r\n"
	end
	SendPmToNick(user.sName, sBot, sOut) 
end

there are quite a few memory leaks here, but if this is what your after, just tell me, and i guess ill quickly write up and optimized version for ya =]

hope it helps cbill =]

cbill

this is perfect! can you do the optimising thingy plz? thanks!

Corayzon

i can do that...ill post her here as soon as i do =]

SMF spam blocked by CleanTalk