Server Side Chat Rooms Bot
 

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

Server Side Chat Rooms Bot

Started by Corayzon, 20 April, 2004, 00:42:39

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Corayzon

Here is an old, but good chatroom bot i wrote a while ago, thought someone ere might find it handy

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

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

--///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
--// 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+)")

	-- Chat Room Functions
	------------------------------------------
	if cmd == "+startchat" then
		user:SendPM(user.sName, "***Starting Chat Room v0.01 ...")
		iChatRoom[user.sName] = "qChatName"
		user:SendPM(user.sName, "***Please enter your ChatRoom Name: ")
		return 1

	elseif cmd == "+joinchat" then
		_,_,cmd,hubname = strfind(data, "%b<>%s+(%S+)%s+(%S+)")
		if iChatRoom[hubname] ~= nil then
			local host = iChatRoom[hubname]
			local hub = iChatRoom[host]
			tChatRoom[host]["userlist"][user.sName] = user.sName
			tChatRoom[host]["count"] = tChatRoom[host]["count"] + 1
			SendPmToNick(user.sName, hub, "***You have connected to "..hubname)
			SendPmToNick(hub, user.sName, "***"..user.sName.." has connected to the chatroom")
		else
			user:SendData(sBot, "***Unable to connected to chatroom "..hubname)
		end

	elseif cmd == "+chatrooms" then
		local sOut = "\r\n\r\n\tChat Room List\r\n\r\n"
		if tRoomList ~= nil then
			for roomname, e in tRoomList do
				sOut=sOut.."\t\t"..roomname.."\t"..tChatRoom[iChatRoom[roomname]]["count"]
			end
			user:SendData(sBot, sOut)
		end

	end

	-- ChatRoom chat
	if tChatRoom ~= nil then
		for haha, room in tChatRoom do
			if strfind(data, "$To: "..room["hubname"]) then
				if room["userlist"][user.sName] == user.sName then

					if cmd == "+userlist" then

						local sOut = "\r\n\r\n\tU s e r   L i s t\r\n\r\n"
						for users, e in room["userlist"] do
							sOut=sOut.."\t\t"..users.."\r\n"
						end
						SendPmToNick(user.sName, room["hubname"], sOut)

					elseif cmd == "+exit" then
						room["userlist"][user.sName] = nil
						room["count"] = room["count"] - 1
						SendPmToNick(user.sName, room["hubname"], "***You have disconnected from "..hubname)
						SendPmToNick(room["hubname"], user.sName, "***"..user.sName.." has disconnected to the chatroom")
						

					elseif cmd == "+kill" then
						if room["host"] == user.sName then
							
							iChatRoom[room["hubname"]] = nil
							iChatRoom[room["hubname"]] = nil
							tRoomList[room["hubname"]] = nil
							frmHub:UnregBot(room["hubname"])
							room = nil
							return 1
						end
					else
						for users, e in room["userlist"] do

							_,_,string = strfind(data, "%b<>%s+(.+)")
							if users ~= user.sName then
								SendPmToNick(users, room["hubname"], "["..user.sName.."] "..string)
								return 1
							end
						end
					end
				end
			end
		end
	end

	-- ChatRoom initailization
	if cmd ~= nil then
		if iChatRoom[user.sName] ~= nil then
			if strfind(data, "$To: "..user.sName) then
				if iChatRoom[user.sName] == "qChatName" then

					_,_,hubname = strfind(data, "%b<>%s+(.+)")
					tChatRoom[user.sName] = {}
					frmHub:RegBot(hubname)
					tChatRoom[user.sName]["host"] = user.sName
					tChatRoom[user.sName]["userlist"] = {}
					tChatRoom[user.sName]["userlist"][user.sName] = user.sName
					tChatRoom[user.sName]["hubname"] = hubname
					tChatRoom[user.sName]["count"] = 1
					iChatRoom[user.sName] = hubname
					iChatRoom[hubname] = user.sName
					tRoomList[hubname] = hubname
					SendPmToNick(user.sName, hubname, "***"..hubname.." has started")
					SendPmToNick(user.sName, hubname, "***You have connected to "..hubname)
					return 1
				
				--elseif tChatRoom[user.sName]["state"] == [	
				end
			end
		end
	end
end

SMF spam blocked by CleanTalk