PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: tezlo on 17 November, 2003, 03:38:16

Title: chatrooms
Post by: tezlo on 17 November, 2003, 03:38:16
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
Title:
Post by: lazyj189 on 17 November, 2003, 05:52:53
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   [aXs] Wellx   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 = { -1 , 0 , 1 , 2 , 3 } -- Can Use Chat Bot Commands Lvl ( 0 = Master ~~ 1 = Operators ~~ 2 = VIPs ~~ 3 = Reg ~~ etc.)

ChatArray={}
ChatFile = "Chatters.tbl"

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

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

function DataArrival(user, data)
if (strsub(data, 1, 1) == "<" ) then
data=strsub(data,1,strlen(data)-1)
_,_,cmd=strfind(data, "%b<>%s+(%S+)")
local Commands = (DeveloperCommands(user, data, cmd))
return Commands
elseif strsub(data, 1, 5) == "$To: " then
local s, e, to = 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~=nil) then
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(user, data, cmd))
end
end
end
end

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

function DeveloperCommands(user, data, cmd)
if tfind(CanUseCommands, user.iProfile) then
if (cmd == "!chathelp") then
DevHelp(user)
return 1
elseif (cmd == "!chat") then
local s,e,cmd,ChatName = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
if (ChatName == nil) then
ChatName = user.sName
end
if ChatArray[ChatName] == nil then
ChatArray[ChatName] = ChatName
for index, value in ChatArray do
SendPmToNick(index, ChatBot, "  "..ChatName.." Has joined the "..ChatBot)
end
else
for index, value in ChatArray do
SendPmToNick(index, ChatBot, "  "..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 index, value in ChatArray do
local line = index
if GetItemByName(index) then
if (strlen(index) <= 10) then
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) <= 10) then
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 - 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(ChatBot, disp)
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(table, key)
return foreachi(table, function(id, tmp) 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 (t) local nt={}; for i, v 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 = s.."{\n"
for i, v in t do
s = format("%s[%s]=%s,\n", s, self:value_(i), self:value_(v))
end
s = 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 t == self then error("can't pickle the pickle class") end
tinsert(self._refToTable, t)
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 = 1, getn(tables) do
local t = tables[tnum]
local tcopy = {}; for i, v in t do tcopy[i] = v end
for i, v in tcopy do
local ni, nv
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
Title:
Post by: tezlo on 17 November, 2003, 13:10:56
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
Title:
Post by: jansan on 07 December, 2003, 04:26:43
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?
Title:
Post by: IceCoder on 09 December, 2003, 14:07:45
good thought
Title:
Post by: SaintSinner on 09 December, 2003, 14:18:05
very good thought
Title: Chatrooms continued...
Post by: Stravides on 19 December, 2003, 23:08:26
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
Title:
Post by: Snooze on 03 March, 2004, 17:42:24
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
Title:
Post by: jsjen on 10 May, 2004, 13:15:17
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?
Title:
Post by: Mandor on 13 May, 2004, 13:00:35
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
Title:
Post by: tezlo on 14 May, 2004, 05:57:11
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
Title:
Post by: Mandor on 14 May, 2004, 10:18:25
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
Title:
Post by: tezlo on 14 May, 2004, 17:16:06
sorry about that.. fixed and edited the post above
Title:
Post by: Mandor on 14 May, 2004, 21:08:40
THANK YOU VERY VERY MUCH!

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



--
Mandor
Title:
Post by: bastya_elvtars on 24 May, 2004, 04:04:39
hmmmmmmm

how does this work?

/me lamer but wanna know lol
Title:
Post by: bastya_elvtars on 24 May, 2004, 19:53:13
How can i invite some1, how can i assign who can see the room etc.
thats what i meant - sorry but i  was sleepy.
Title:
Post by: Mandor on 24 May, 2004, 20:39:14
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
Title:
Post by: bastya_elvtars on 24 May, 2004, 23:22:43
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?
Title:
Post by: Reefa on 03 June, 2004, 13:09:19
Hey! What happened to the !remove command in the re-written version? :P
Title:
Post by: tezlo on 03 June, 2004, 13:56:18
i removed it :) but its back now
reefa lol.. just about to skin up
Title:
Post by: Reefa on 03 June, 2004, 14:34:41
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
Title:
Post by: tezlo on 03 June, 2004, 15:06:18
done B] hehe i wouldn't roll em any other way
Title:
Post by: Reefa on 03 June, 2004, 15:36:03
Nice one!!! Quick too :D

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

Ta!
Title:
Post by: tezlo on 03 June, 2004, 15:49:29
it should save into chatrooms.dat everytime changes are made (and on script exit if you're using one of the latest betas)
Title:
Post by: Reefa on 03 June, 2004, 15:54:34
Working like a dream :D
Title: >>> 0o0o0o <<<
Post by: Cp6uja on 07 June, 2004, 11:08:21
This script (ChatRoom) not work on my hub.
Title: MultiChatRoom -=- BOT -=-
Post by: Cp6uja on 07 June, 2004, 11:20:32
This script not work WHY ?!?!?!
But script is good,nice idea etc.

******************************************
--// MultiProfile Chat Room
--// By Chaggydawg
--// This is a multiprofile Secondary Chat Bot, You could in theory rename script and bot and run mutliple seperate chats too
--// Uncomment and Rename People# Profiles appropriately ("within quotes")
--// Prolly a bunch of these around, But I wrote it, so I'm sharing it, plus its nice and simple ;)
--// Version... oh I don't know... v17.1854a   yah that looks good....

BotName = "AdminChat"


--// Uncomment who will use this chat, also possible to change profile names, but don't try to add People6, etc.
People1 = GetUsersByProfile("Admin")
People2 = GetUsersByProfile("Master")
--//People3 = GetUsersByProfile("Operator")
--//People4 = GetUsersByProfile("VIP")
--//People5 = GetUsersByProfile("Reg")

function Main()
frmHub:RegBot(BotName)
end

function DataArrival(curUser,Data)
s,e,mess = strfind(Data,"%b<>%s+(.*)")
if strsub(Data,1,3) == "$To" and strsub(Data,6,strlen(BotName)+5) == BotName then
DoChatter(curUser,mess)
end
end

function DoChatter(curUser,mess)
if (People1) then
for i,v in People1 do
if strlower(v) ~= strlower(curUser.sName) then
   SendToNick(v, "$To: "..v.." From: "..BotName.." $<"..curUser.sName.."> "..mess)
end
end
end
if (People2) then
for i,v in People2 do
if strlower(v) ~= strlower(curUser.sName) then
   SendToNick(v, "$To: "..v.." From: "..BotName.." $<"..curUser.sName.."> "..mess)
end
end
end
if (People3) then
for i,v in People3 do
if strlower(v) ~= strlower(curUser.sName) then
   SendToNick(v, "$To: "..v.." From: "..BotName.." $<"..curUser.sName.."> "..mess)
end
end
end
if (People4) then
for i,v in People4 do
if strlower(v) ~= strlower(curUser.sName) then
   SendToNick(v, "$To: "..v.." From: "..BotName.." $<"..curUser.sName.."> "..mess)
end
end
end
if (People5) then
for i,v in People5 do
if strlower(v) ~= strlower(curUser.sName) then
   SendToNick(v, "$To: "..v.." From: "..BotName.." $<"..curUser.sName.."> "..mess)
end
end
end
Title: tezlo !!
Post by: Cp6uja on 09 June, 2004, 22:50:56
tezlo your script not work on my hub.!.
Why ???

/Cp6uja  8)
Title:
Post by: tezlo on 10 June, 2004, 16:47:01
because you didn't make any chatrooms? try reading the whole thread
Title:
Post by: Cain on 03 August, 2005, 13:58:21
Hi,

The first code by tezlo is perfect for my needs and works like a charm except for a small thing....

Can you please modify it so users can join the chat themselves without an invite?

Thanx,

|Cain|