chatrooms
 

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

chatrooms

Started by tezlo, 17 November, 2003, 03:38:16

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

tezlo

saw a few requests for a vipchat regchat thing..
easy to do but i dont like the idea of windows popping up where you dont want them to
so i took a bit of another approach..
bots = {}

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

function OnExit()
	savechat()
end

function DataArrival(user, data)
	if strsub(data, 1, 1) == "<" then
		local s, e, cmd, args = strfind(data, "^%b<> %!(%a+)%s*(.*)|$")
		if cmd == "mkchat" and user.bOperator then mkchat(user, args) return 1 end
	elseif strsub(data, 1, 4) == "$To:" then
		local s, e, to, str = strfind(data, "^$To: (%S+) From: %S+ $%b<> (.*)|$")
		if bots[to] then
			if not tfind(bots[to], user.sName) then
				user:SendPM(to, "youre not a member here") return
			end
			local isowner = user.sName == bots[to][1]
			local s, e, cmd, args = strfind(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
end

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

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

function dochat(to, from, str)
	local users = bots[to]
	for i = 1, 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 = strfind(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, "you cant")
	else dochat(to, to, user.sName.." has left the room") tremove(bots[to], id) end
end

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

function invite(user, args, to)
	local n = 0
	gsub(args, "(%S+)", function(nick)
		local tmp, bool = GetItemByName(nick), tfind(bots[%to], nick)
		if tmp and not bool then
			tinsert(bots[%to], nick)
			dochat(%to, %to, nick.." has been invited to the room")
		end
	end)
end

function remove(user, args, to)
	gsub(args, "(%S+)", function(nick)
		local id = tfind(bots[%to], nick)
		if id and id ~= 1 then
			dochat(%to, %to, nick.." has been removed from the room")
			tremove(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

OPs can setup chatrooms
!mkchat [userlist]

once you set one up you can (in PM to the bot)
!delchat
!invite [userlist]
!remove [userlist]

any member can
!leave
!members

lazyj189

Any way to take code from this script so it can add a person to the specified chat room even if they are not online at that time?  alsoformat it like this script so when you see who all is able to sue the chat room that it will also show if they are online or not?


-----------------------------------------------------
-- 
Chat Bot v3.5 Coded by   [aXsWellx   01/09-03
-- Formerly known as the Developer-Chat for TIC50
-- Based on the idea VIPChat from Piglja 
-- Thx goes to Piglja aMutex for Ideas and Help
-----------------------------------------------------

ChatBot "#SideChat" -- Chat Bot Name
CanUseCommands 
= { -} -- Can Use Chat Bot Commands Lvl Master ~~ Operators ~~ VIPs ~~ Reg ~~ etc.)

ChatArray={}
ChatFile "Chatters.tbl"

function Main()
frmHub:RegBot(ChatBot)
ChatArray LoadFromFile(ChatFile)
end

--========================================================    DataArrival:    =========================================================--

function 
DataArrival(userdata)
if (strsub(data11) == "<" then 
data=strsub(data,1,strlen(data)-1)
_,_,cmd=strfind(data"%b<>%s+(%S+)")
local Commands = (DeveloperCommands(userdatacmd))
return Commands
elseif 
strsub(data15) == "$To: " then 
local seto strfind(data"$To: (%S+)")
if to ~= ChatBot then
return 0
else
if to == ChatBot then
local data=strsub(data,1,strlen(data)-1)  
local s,e,from,msg strfind(data,"From:%s+(%S+)%s+$%b<>%s+(.+)")  
if ChatArray[user.sName] ~= nil then
ChatArray[user.sName] = nil
for i,v in ChatArray do
Developer=GetItemByName(i)
if (Developer~=nilthen
Developer:SendData("$To: "..i.." From: "..ChatBot.." $<"..user.sName.."> "..msg.."|")
end
end
ChatArray[user.sName] = user.sName 
else
user:SendPM(ChatBot,"You do not have permission to write in here (Join or Talk to a Operator if you need permission)")
end 
local _,_,cmd strfind(data,"$%b<>%s+(%S+)")
local Commands = (DeveloperCommands(userdatacmd))
end
end
end
end

--=====================================================      Chat Commands:      ======================================================--

function 
DeveloperCommands(userdatacmd)
if tfind(CanUseCommandsuser.iProfilethen
if (cmd == "!chathelp"then
DevHelp(user)
return 1
elseif (cmd == "!chat"then
local s,e,cmd,ChatName strfinddata"%b<>%s+(%S+)%s+(.*)" )
if (ChatName == nilthen
ChatName user.sName
end
if ChatArray[ChatName] == nil then
ChatArray[ChatName] = ChatName
for indexvalue in ChatArray do 
SendPmToNick(indexChatBot"  "..ChatName.." Has joined the "..ChatBot
end 
else
for indexvalue in ChatArray do 
SendPmToNick(indexChatBot"  "..ChatName.." Has left the "..ChatBot
end 
ChatArray[ChatName] = nil
end
SaveToFile(ChatName,ChatFile,ChatArray)
return 1
elseif (cmd == "!showchatters"then
function DevList()
local DevList ""
for indexvalue in ChatArray do
local line index
if GetItemByName(indexthen
if (strlen(index) <= 10then
DevList DevList.." ? "..line.."\t\t\t~ On-line ~\r\n"
else
DevList DevList.." ? "..line.."\t\t~ On-line ~\r\n"
end
else
if (strlen(index) <= 10then
DevList DevList.." ? "..line.."\t\t\t? Off-Line ?\r\n"
else
DevList DevList.." ? "..line.."\t\t? Off-Line ?\r\n"
end
end
end
return DevList
end
user:SendPM(ChatBot"\r\n\r\n(? ?.??.->      "..ChatBot.." Chatters      <-.??.???) \r\n\r\n"..DevList())
return 1
end
else 
user:SendData("You don't have permission to use the commands to the "..ChatBot.." ask a Operator for permission !!") return 0 end
end

function DevHelp (user)
local disp "\r\n\r\n"
disp disp.."~~ Scripted DeveloperChat Commands: ~~\r\n\r\n"
disp disp.."   !chat <nick> - Add or part a user to the list of people that can chat in the "..ChatBot.."\r\n"
disp disp.."   !showchatters - See witch users that can chat in the "..ChatBot.."\r\n"
disp disp.."\r\n"
user:SendPM(ChatBotdisp)
end

--========================================================    Functions:    ===========================================================--

function 
SaveToFile(arg,file,table)
local aString pickle(table)
writeto(file)
write(aString)
writeto()
end

function LoadFromFile(file)
readfrom(file)
local aString read("*all")
return  unpickle(aString
end

function tfind(tablekey
return 
foreachi(table, function(idtmp) return (tmp == %key) and id end
end 

----------------------------------------------
-- 
Pickle.lua
-- An table serialization utility for lua
-- Steve Dekorte, [URL]http://www.dekorte.com,[/URL] Apr 2000
-- Freeware
----------------------------------------------
function 
pickle(t)
return 
Pickle:clone():pickle_(t)
end

Pickle 
= {
clone = function (
tlocal nt={}; for iv in t do nt[i]=v end return nt end 
}

function 
Pickle:pickle_(root)
if type(root) ~= "table" then 
error("can only pickle tables, not ".. type(root).."s")
end
self._tableToRef = {}
self._refToTable = {}
local savecount 0
self:ref_(root)
local s ""
while getn(self._refToTable) > savecount do
savecount savecount 1
local t self._refToTable[savecount]
s.."{\n"
for iv in t do
format("%s[%s]=%s,\n"sself:value_(i), self:value_(v))
end
s.."},\n"
end
return format("{%s}"s)
end

function Pickle:value_(v)
local vtype type(v)
if vtype == "string" then return format("%q"v)
elseif vtype == "number" then return v
elseif 
vtype == "table" then return "{"..self:ref_(v).."}"
else --error("pickle a "..type(v).." is not supported")
end  
end

function Pickle:ref_(t)
local ref self._tableToRef[t]
if not ref then 
if == self then error("can't pickle the pickle class"end
tinsert(self._refToTablet)
ref getn(self._refToTable)
self._tableToRef[t] = ref
end
return ref
end

----------------------------------------------
-- 
unpickle
----------------------------------------------

function 
unpickle(s)
if type(s) ~= "string" then
error("can't unpickle a "..type(s)..", only strings")
end
local tables dostring("return "..s)
for tnum 1getn(tables) do
local t tables[tnum]
local tcopy = {}; for iv in t do tcopy[i] = v end
for iv in tcopy do
local ninv
if type(i) == "table" then ni tables[i[1]] else ni i end
if type(v) == "table" then nv tables[v[1]] else nv v end
t[ni] = nv
end
end
return tables[1]
end
DivX Dominion Hub Owner
3 years running
DivX Dominion Hub

tezlo

uh.. take code?
just replace these
function members(user, to)
	local users = bots[to]
	for i = 1, getn(users) do user:SendPM(to, i..". "..users[i].." "..((GetItemByName(users[i]) and "online") or "offline")) end
end

function invite(user, args, to)
	gsub(args, "(%S+)", function(nick)
		local tmp = tfind(bots[%to], nick)
		if not tmp then
			tinsert(bots[%to], nick)
			dochat(%to, %to, nick.." has been invited to the room")
		end
	end)
end

jansan

Why this don't work....

ots = {}

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

function OnExit()
   savechat()
end

function DataArrival(user, data)
   if strsub(data, 1, 1) == "<" then
      local s, e, cmd, args = strfind(data, "^%b<> %!(%a+)%s*(.*)|$")
      if cmd == "mkchat" and user.bOperator then mkchat(user, args) return 1 end
   elseif strsub(data, 1, 4) == "$To:" then
      local s, e, to, str = strfind(data, "^$To: (%S+) From: %S+ $%b<> (.*)|$")
      if bots[to] then
         if not tfind(bots[to], user.sName) then
            user:SendPM(to, "youre not a member here") return
         end
         local isowner = user.sName == bots[to][1]
         local s, e, cmd, args = strfind(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)
         elseif cmd=="1d3" then t1d3(user, cmd, to)
         elseif cmd=="1d4" then t1d4(user,cmd, to)
         elseif cmd=="1d6" then t1d6(user,cmd, to)
         elseif cmd=="2d4" then t2d4(user, cmd,to)
         elseif cmd=="1d8" then t1d8(user,cmd, to)
         elseif cmd=="2d6" then t2d6(user,cmd, to)
         elseif cmd=="1d10" then t1d10(user,cmd, to)
         elseif cmd=="1d12" then   t1d12(user,cmd, to)
         elseif cmd=="2d8" then t2d8(user,cmd, to)
         elseif cmd=="2d10" then t2d10(user,cmd, to)
         elseif cmd=="2d12" then t2d12(user,cmd, to)
         elseif cmd=="1d20" then t1d20(user,cmd, to)
         elseif cmd=="2d20" then t2d20(user,cmd, to)
         elseif cmd=="1d100" then t1d100(user,cmd, to)
         else dochat(to, user.sName, str) end
      end
   end
end

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

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

function dochat(to, from, str)
   local users = bots[to]
   for i = 1, 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 = strfind(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, "you cant")
   else dochat(to, to, user.sName.." has left the room") tremove(bots[to], id) end
end

function members(user, to)
   local users = bots[to]
   for i = 1, getn(users) do user:SendPM(to, i..". "..users.." "..((GetItemByName(users) and "online") or "offline")) end
end

function invite(user, args, to)
   gsub(args, "(%S+)", function(nick)
      local tmp = tfind(bots[%to], nick)
      if not tmp then
         tinsert(bots[%to], nick)
         dochat(%to, %to, nick.." has been invited to the room")
      end
   end)
end

function remove(user, args, to)
   gsub(args, "(%S+)", function(nick)
      local id = tfind(bots[%to], nick)
      if id and id ~= 1 then
         dochat(%to, %to, nick.." has been removed from the room")
         tremove(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 t1d3 (user, cmd, to)
   
   local dice = random (1,3)
   
   if dice == 1 then
   dochat(to, to, user.sName.." Lancia 1D3 ed ottiene 1")

   elseif dice == 2 then
   dochat(to, to, user.sName.." Lancia 1D3 ed ottiene 2")
   
   elseif dice == 3 then
   dochat(to, to, user.sName.." Lancia 1D3 ed ottiene 3")

end
end

It's unfinished... but when i try to test the 1d3 funtion don't work... i need this function to play role play on my italian hub... Someone can help me?

IceCoder


SaintSinner

   


Stravides

Using the code below, I would like to change this or is there a better script to enable a request board for all users of the hub to post, but not view.

I could let users just pm me, but i want other ops to be able to look into the requests bot and action the reqs.

many thanks....

QuoteOriginally posted by tezlo


bots = {}

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

function OnExit()
	savechat()
end

function DataArrival(user, data)
	if strsub(data, 1, 1) == "<" then
		local s, e, cmd, args = strfind(data, "^%b<> %!(%a+)%s*(.*)|$")
		if cmd == "mkchat" and user.bOperator then mkchat(user, args) return 1 end
	elseif strsub(data, 1, 4) == "$To:" then
		local s, e, to, str = strfind(data, "^$To: (%S+) From: %S+ $%b<> (.*)|$")
		if bots[to] then
			if not tfind(bots[to], user.sName) then
				user:SendPM(to, "youre not a member here") return
			end
			local isowner = user.sName == bots[to][1]
			local s, e, cmd, args = strfind(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
end

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

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

function dochat(to, from, str)
	local users = bots[to]
	for i = 1, 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 = strfind(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, "you cant")
	else dochat(to, to, user.sName.." has left the room") tremove(bots[to], id) end
end

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

function invite(user, args, to)
	local n = 0
	gsub(args, "(%S+)", function(nick)
		local tmp, bool = GetItemByName(nick), tfind(bots[%to], nick)
		if tmp and not bool then
			tinsert(bots[%to], nick)
			dochat(%to, %to, nick.." has been invited to the room")
		end
	end)
end

function remove(user, args, to)
	gsub(args, "(%S+)", function(nick)
		local id = tfind(bots[%to], nick)
		if id and id ~= 1 then
			dochat(%to, %to, nick.." has been removed from the room")
			tremove(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

OPs can setup chatrooms
!mkchat [userlist]

once you set one up you can (in PM to the bot)
!delchat
!invite [userlist]
!remove [userlist]

any member can
!leave
!members
Stravides
For RPG Books, Mp3 & Videos
We host trivia  and the ever failing Smeagolbot

Snooze

#7
It would would be superb if the script could create a chatroom + invite a list of "special users" on startup.

Should any of these "special users" leave this default chat, he/she should also be able to !join this chat again.

Could any of you kewl scripters help me out with that ?

**Snooze

jsjen

when you accidently invite the same user multiple times they get like the same amount of responses in chat

can you set it so the user can only be invited once?

Mandor

QuoteOriginally posted by tezlo
saw a few requests for a vipchat regchat thing..
easy to do but i dont like the idea of windows popping up where you dont want them to
so i took a bit of another approach...

We have different regged users groups on the hub, e.g. group1, group2, group3 (all in PtokaX hub's settings). I want to set different group1-chat, group2-chat etc. for them. And now my idea:

An active chat is going in Group1-Chat. A Group1-User-A connects to the hub. He doesn't receive any Group1-User-B messages sent to Group1-Chat untill he sends a private message to the Group1-Chat. It's good. But I want him to join Group1-Chat without inviting him - just by sending PM to Group1-Chat. The chat bot would check his group and allow to write there or not.

Also I would like a Group1-User-A to be able to invite a Group2-User-G to Group1-Chat. Without asking Operator to let him join as it is now.

I would like Operators to be able to join all of the chats in the same way. By sending a PM to the Group-Chats.

These are my ideas. I would like to ask if it is possible to code it? Maybe I I missed some solution for it. And above all, I would like to ask Tezlo for a fair answer. Please? I would really enjoy such a version of this script and probably I wouldn't be the only one.

Thanks for your time.


--
Mandor

tezlo

#10
i wanted to make the script more flexible but didnt think it was being used much
rewrote the whole thing, same commands but..

!mkchat [groups]
where [groups] is a list of profiles (names or id's) that will be able to join the chat without having to be invited first (OPs always can)
!away [msg]
when you're away you dont receive any messages, gets reset when you say something
!leave [msg]
takes an argument now.. quit message the irc way

-- chatrooms v3
-- tezlo

function Main()
	chatrooms:load()
end

function OnExit()
	chatrooms:save()
end

function DataArrival(user, data)
	if strsub(data, 1, 1) == "<" then
		local s, e, cmd, args = strfind(data, "^%b<> %!(%a+)%s*(.*)|$")
		if cmd == "mkchat" and user.bOperator then
			local s, e, name, profiles = strfind(args, "(%S+)%s*(.*)")
			if not s then
				user:SendData(">> syntax: !mkchat  [groups]")
			elseif chatrooms.items[name] then	
				user:SendData(">> "..name.." already is a chatroom")
			elseif GetItemByName(name) then
				user:SendData(">> there is a user with that name")
			else
				frmHub:RegBot(name)
				local tmp = chatrooms:new(name, user.sName)
				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
	elseif strsub(data, 1, 4) == "$To:" then
		local s, e, to, str = strfind(data, "^$To: (%S+) From: %S+ $%b<> (.*)|$")
		if chatrooms.items[to] then
			local tmp = chatrooms.items[to]
			if not tmp.members[user.sName] then
				if user.bOperator or tmp.groups[user.iProfile] == 1 then
					tmp.members[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 = strfind(str, "^%!(%a+)%s*(.*)$")
				if not s then
					tmp.members[user.sName] = 1
					tmp:chat(str, user.sName)
				elseif cmd == "away" then
					tmp:chat(user.sName.." is away.. "..args, to)
					tmp.members[user.sName] = 0
				elseif cmd == "leave" then
					tmp:chat(user.sName.." left.. "..args, to)
					tmp.members[user.sName] = nil
					chatrooms:save()
				elseif cmd == "members" then
					local n, na, msg = 0, 0
					for nick, stat in tmp.members 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 members")
				elseif cmd == "invite" then
					gsub(args, "(%S+)", function(nick)
						if not %tmp.members[nick] then
							%tmp.members[nick] = 1
							%tmp:chat(nick.." has been invited to the room", %to)
						end
					end); chatrooms:save()
				elseif cmd == "remove" and isowner then
					gsub(args, "(%S+)", function(nick)
						if %tmp.members[nick] and nick ~= %tmp.owner then
							%tmp:chat(nick.." has been removed from the room", %to)
							%tmp.members[nick] = nil
						end
					end); chatrooms:save()
				elseif cmd == "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
end

botchat = function(self, msg, from)
	for nick, id in self.members 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 = {},
			members = { [owner] = 1 },
			chat = botchat
		}; self.items[name] = tmp
		return tmp
	end,

	load = function(self)
		self.items = dofile("chatrooms.dat") or {}
		for name, room in self.items do
			frmHub:RegBot(name)
			room.chat = botchat
			room:chat("hello", name)
		end
	end,

	save = function(self)
		local f = openfile("chatrooms.dat", "w+")
		assert(f, "chatrooms.dat") write(f, "return {\n")
		for name, tmp in self.items do
			write(f, 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
				write(f, format("\t\t\t[%d] = %d,\n", id, stat))
			end; write(f, "\t\t},\n\t\tmembers = {\n")
			for nick, stat in tmp.members do
				write(f, format("\t\t\t[%q] = %d,\n", nick, stat))
			end; write(f, "\t\t}\n\t},\n")
		end; write(f, "}")
		closefile(f)
	end
}

thanks for the feedback
tezlo

Mandor

QuoteOriginally posted by tezlo
i wanted to make the script more flexible but didnt think it was being used much
rewrote the whole thing, same commands but...

I tested it on PtokaX DC Hub 0.3.2.6 TestDrive 4. I created two groups: GroupA and GroupB. When GroupA-User sends a message to the created for his group Chat, this message does not appear in Operators window, only "GroupA-User joined" appears. Every time the message is send.

Two users from the same group do not see each other's messages. They do not appear in each other's chat window.

I like the added feature of [groups]. Thank you.


--
Mandor

tezlo

sorry about that.. fixed and edited the post above

Mandor

THANK YOU VERY VERY MUCH!

It works PERFECTLY! =) Well, first tries were 100% successful and I think I won't bug you anymore. ;)



--
Mandor

bastya_elvtars

hmmmmmmm

how does this work?

/me lamer but wanna know lol
Everything could have been anything else and it would have just as much meaning.

bastya_elvtars

How can i invite some1, how can i assign who can see the room etc.
thats what i meant - sorry but i  was sleepy.
Everything could have been anything else and it would have just as much meaning.

Mandor

QuoteOPs can setup chatrooms
!mkchat [userlist]

once you set one up you can (in PM to the bot)
!delchat
!invite [userlist]
!remove [userlist]

any member can
!leave
!members


--
Mandor

bastya_elvtars

#17
ty i havent noticed
I was really sleepy lol

thank you

P. S.: !mkchat [userlist]  what the userlist argument means, or what is the syntax?
Everything could have been anything else and it would have just as much meaning.

Reefa

Hey! What happened to the !remove command in the re-written version? :P

tezlo

i removed it :) but its back now
reefa lol.. just about to skin up

Reefa

lol hope they're silvers :D

Thanks for the edit mate, would it be possible to add offline peeps too or is that asking for trouble? :P

tezlo

done B] hehe i wouldn't roll em any other way

Reefa

Nice one!!! Quick too :D

Is there any way for the script to remember the table when scripts are reset?

Ta!

tezlo

it should save into chatrooms.dat everytime changes are made (and on script exit if you're using one of the latest betas)

Reefa

#24
Working like a dream :D

SMF spam blocked by CleanTalk