Zrightclicker for ChatRoom
 

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

Zrightclicker for ChatRoom

Started by Casanova82, 13 April, 2005, 17:58:47

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Casanova82

bots = {}

function Main()
   loadchat()
   for name, users in bots do
      frmHub:RegBot(name)
   end
end

function OnExit()
   savechat()
end



function ChatArrival(user, data)
   local s, e, cmd, args = string.find(data, "^%b<> %!(%a+)%s*(.*)|$")
   if cmd == "mkchat" and user.bOperator then mkchat(user, args) return 1 end
end

function ToArrival(user,data)
   local s, e, to, str = string.find(data, "^$To: (%S+) From: %S+ $%b<> (.*)|$")
   if bots[to] then
      if not tfind(bots[to], user.sName) then user:SendPM(to, "non sei stato invitato!") return end
      local isowner = user.sName == bots[to][1]
      local s, e, cmd, args = string.find(str, "^%!(%a+)%s*(.*)$")
      if cmd == "leave" then leave(user, to)
      elseif cmd == "members" then members(user, to)
      elseif cmd == "delchat" and isowner then delchat(user, to)
      elseif cmd == "invite" and isowner then invite(user, args, to)
      elseif cmd == "remove" and isowner then remove(user, args, to)
      else dochat(to, user.sName, str) end
   end
end

function loadchat()
   bots = dofile("chatrooms.dat") or {}
end

function savechat()
   local f = io.open("chatrooms.dat", "w+")
   assert(f, "chatrooms.dat")
   f:write("return {\n")
   for name, users in bots do
      f:write("\t"..string.format("[%q]", name).." = { ")
      for i = 1, table.getn(users) do f:write(string.format("%q", users)..", ") end
      f:write("},\n")
   end
   f:write("}")
   f:close()
end

function dochat(to, from, str)
   local users = bots[to]
   for i = 1, table.getn(users) do
      local nick = users
      if nick ~= from then SendToNick(nick, "$To: "..nick.." From: "..to.." $<"..from.."> "..str) end
   end
end

function mkchat(user, args)
   local s, e, name, members = string.find(args, "(%S+)%s*(.*)")
   if not s then user:SendData(">> syntax: !mkchat [userlist]") return end
   if bots[name] then user:SendData(">> "..name.." belongs to "..bots[name][1]) return end
   frmHub:RegBot(name) bots[name] = { user.sName }
   invite(user, members, name) dochat(name, name, "hello")
end



function delchat(user, to)
   dochat(to, to, "bye bye")
   frmHub:UnregBot(to)
   bots[to] = nil
end



function leave(user, to)
   local id = tfind(bots[to], user.sName)
   if id == 1 then user:SendPM(to, "non puoi")
   else dochat(to, to, user.sName.." ? uscito dalla stanza") table.remove(bots[to], id) end
end



function members(user, to)
   local users = bots[to]
   for i = 1, table.getn(users) do user:SendPM(to, i..". "..users) end
end

function invite(user, args, to)
   local n = 0
   string.gsub(args, "(%S+)", function(nick)
      local tmp, bool = GetItemByName(nick), tfind(bots[to], nick)
      if tmp and not bool then
         table.insert(bots[to], nick)
         dochat(to, to, nick.." sei stato invitato!")
      end
   end)
end



function remove(user, args, to)
   string.gsub(args, "(%S+)", function(nick)
      local id = tfind(bots[to], nick)
      if id and id ~= 1 then
         dochat(to, to, nick.." sei stato cacciato dalla stanza!")
         table.remove(bots[to], id)
      end
   end)
end



function tfind(table, item)
   for key, value in table do
      if value == item then return key end
   end
end



How can i add command on zrightclicker of this script???

jiten

Do post with the [ CODE] [ /CODE] thingy.

Try this:
bots = {} 

function Main() 
	loadchat() 
	for name, users in bots do 
		frmHub:RegBot(name) 
	end 
end 

function OnExit() 
	savechat() 
end 

function ChatArrival(user, data) 
	local s, e, cmd, args = string.find(data, "^%b<> %!(%a+)%s*(.*)|$") 
	if cmd == "mkchat" and user.bOperator then
		mkchat(user, args)
		return 1
	end 
end 

function ToArrival(user,data) 
	local s, e, to, str = string.find(data, "^$To: (%S+) From: %S+ $%b<> (.*)|$") 
	if bots[to] then 
		if not tfind(bots[to], user.sName) then
			user:SendPM(to, "non sei stato invitato!") 
		return end 
		local isowner = user.sName == bots[to][1] 
		local s, e, cmd, args = string.find(str, "^%!(%a+)%s*(.*)$") 
		if cmd == "leave" then 
			leave(user, to) 
		elseif cmd == "members" then 
			members(user, to) 
		elseif cmd == "delchat" and isowner then
			delchat(user, to) 
		elseif cmd == "invite" and isowner then
			invite(user, args, to) 
		elseif cmd == "remove" and isowner then
			remove(user, args, to) 
		else dochat(to, user.sName, str)
		end 
	end 
end 

function loadchat() 
	bots = dofile("chatrooms.dat") or {} 
end 

function savechat() 
	local f = io.open("chatrooms.dat", "w+") 
	assert(f, "chatrooms.dat") 
	f:write("return {\n") 
	for name, users in bots do 
		f:write("\t"..string.format("[%q]", name).." = { ") 
		for i = 1, table.getn(users) do
			f:write(string.format("%q", users[i])..", ")
		end 
		f:write("},\n") 
	end 
	f:write("}") 
	f:close() 
end 

function dochat(to, from, str) 
	local users = bots[to] 
	for i = 1, table.getn(users) do 
		local nick = users[i] 
		if nick ~= from then
			SendToNick(nick, "$To: "..nick.." From: "..to.." $<"..from.."> "..str)
		end 
	end 
end 

function mkchat(user, args) 
	local s, e, name, members = string.find(args, "(%S+)%s*(.*)") 
	if not s then
		user:SendData(">> syntax: !mkchat  [userlist]") 
	return end 
	if bots[name] then
		user:SendData(">> "..name.." belongs to "..bots[name][1])
	return end 
	frmHub:RegBot(name) bots[name] = { user.sName } 
	invite(user, members, name) dochat(name, name, "hello") 
end 

function delchat(user, to) 
	dochat(to, to, "bye bye") 
	frmHub:UnregBot(to) 
	bots[to] = nil 
end 

function leave(user, to) 
	local id = tfind(bots[to], user.sName) 
	if id == 1 then
		user:SendPM(to, "non puoi") 
	else 
		dochat(to, to, user.sName.." ? uscito dalla stanza") table.remove(bots[to], id)
	end 
end 

function members(user, to) 
	local users = bots[to] 
	for i = 1, table.getn(users) do
		user:SendPM(to, i..". "..users[i])
	end 
end 

function invite(user, args, to) 
	local n = 0 
	string.gsub(args, "(%S+)", function(nick) 
	local tmp, bool = GetItemByName(nick), tfind(bots[to], nick) 
	if tmp and not bool then 
		table.insert(bots[to], nick) 
		dochat(to, to, nick.." sei stato invitato!") 
	end 
end) 
end 



function remove(user, args, to) 
	string.gsub(args, "(%S+)", function(nick) 
	local id = tfind(bots[to], nick) 
	if id and id ~= 1 then 
		dochat(to, to, nick.." sei stato cacciato dalla stanza!") 
		table.remove(bots[to], id) 
	end 
end) 
end 

function tfind(table, item) 
	for key, value in table do 
		if value == item then
			return key
		end 
	end 
end 

function NewUserConnected(curUser)
	UserCmds(curUser)
end

OpConnected = NewUserConnected

function UserCmds(curUser)
	curUser:SendData("$UserCommand 1 2 Chatrooms\\Leave$$To: %[line:Chatroom] From: %[mynick] $<%[mynick]> !leave||")
	curUser:SendData("$UserCommand 1 2 Chatrooms\\Members$$To: %[line:Chatroom] From: %[mynick] $<%[mynick]> !members||")
	curUser:SendData("$UserCommand 1 2 Chatrooms\\Delete$$To: %[line:Chatroom] From: %[mynick] $<%[mynick]> !delchat %[line:Chatroom]||")
	curUser:SendData("$UserCommand 1 2 Chatrooms\\Invite$$To: %[line:Chatroom] From: %[mynick] $<%[mynick]> !invite %[line:Nick]||")
	curUser:SendData("$UserCommand 1 2 Chatrooms\\Remove$$To: %[line:Chatroom] From: %[mynick] $<%[mynick]> !remove %[line:Nick]||")
	curUser:SendData("$UserCommand 1 3 Chatrooms\\Make$<%[mynick]> !mkchat %[line:Chatroom]||")
end

Cheers

Casanova82

Great!!! Tkx  :))

jiten


SMF spam blocked by CleanTalk