as i just made version 3 of this bot it seems a nice idea 2 me 2 place them all in 1 topic.
version 1:
-- really lame chat room bot
-- by plop
Bot = "Chat_room"
function Main()
frmHub:RegBot(Bot)
end
function DataArrival(user, data)
if(strsub(data, 1, 4) == "$To:") then
local s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if whoTo == Bot then
data=strsub(data,1,strlen(data)-1)
local s,e,txt = strfind(data, "%$(%b<>.+)")
if txt then
SendPmToAll(Bot, txt.."|")
end
end
end
end
version 2:
---------------------------------------
-- V 1
-- really lame chat room bot
----
-- V 2
-- doesn't repeat 2 the sender
-- doesn't show botname on the pm's
---------------------------------------
-- by plop http://www.plop.nl --
---------------------------------------
Bot = "Chat_room"
tUsers = {}
function Main()
frmHub:RegBot(Bot)
end
function DataArrival(user, data)
if tUsers[user.sName] == nil then
tUsers[user.sName] = 1
end
if(strsub(data, 1, 4) == "$To:") then
local s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if whoTo == Bot then
data=strsub(data,1,strlen(data)-1)
local s,e,txt = strfind(data, "%$(%b<>.+)")
local usr
if txt then
for a,b in tUsers do
if a ~= user.sName then
usr = GetItemByName(a)
if usr then
usr:SendData("$To: "..usr.sName.." From: "..Bot.." $"..txt.."|")
else
tUsers[a] = nil
end
end
end
end
end
end
end
function OpConnected(user)
if tUsers[user.sName] == nil then
tUsers[user.sName] = 1
end
end
NewUserConnected = OpConnected
function OpDisconnected(user)
if tUsers[user.sName] then
tUsers[user.sName] = nil
end
end
UserDisconnected = OpDisconnected
and version 3:
---------------------------------------
-- V 1
-- really lame chat room bot
----
-- V 2
-- doesn't repeat 2 the sender
-- doesn't show botname on the pm's
----
-- V3
-- added a level system
-- every level has it's own room
-- 1 level can read all
---------------------------------------
-- by plop http://www.plop.nl --
---------------------------------------
Bot = "_room" -- name of the level is attached 2 the name
tUsers = {}
tBot = {}
trBot = {}
tLevels = {
[0] = 1,
[1] = 1,
[2] =1
}
-- the next level can read all chats
iMaster = 0
function Main()
for a,b in tLevels do
tUsers[a] = {}
tBot[a]=GetProfileName(a)..Bot
trBot[GetProfileName(a)..Bot] = a
frmHub:RegBot(tBot[a])
end
end
function OnExit()
for a,b in tBot do
frmHub:UnregBot(b)
end
end
function DataArrival(user, data)
if tUsers[user.iProfile] == nil then
tUsers[user.iProfile] = {}
end
if tUsers[user.iProfile][user.sName] == nil then
tUsers[user.iProfile][user.sName] = 1
end
if(strsub(data, 1, 4) == "$To:") then
local s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if trBot[whoTo] then
if user.iProfile == trBot[whoTo] or user.iProfile == iMaster then
data=strsub(data,1,strlen(data)-1)
local s,e,txt = strfind(data, "%$(%b<>.+)")
local usr
local t = trBot[whoTo]
if txt then
for a,b in tUsers[t] do
if a ~= user.sName then
usr = GetItemByName(a)
if usr then
usr:SendData("$To: "..usr.sName.." From: "..tBot[t].." $"..txt.."|")
else
tUsers[t][a] = nil
end
end
end
for a,b in tUsers[iMaster] do
if a ~= user.sName then
usr = GetItemByName(a)
if usr then
usr:SendData("$To: "..usr.sName.." From: "..tBot[t].." $"..txt.."|")
else
tUsers[iMaster][a] = nil
end
end
end
end
else
user:SendPM(tBot[trBot[whoTo]], "You may not acces this chat room!|")
return 1
end
end
end
end
function OpConnected(user)
if tUsers[user.iProfile] == nil then
tUsers[user.iProfile] = {}
end
if tUsers[user.iProfile][user.sName] == nil then
tUsers[user.iProfile][user.sName] = 1
end
end
NewUserConnected = OpConnected
function OpDisconnected(user)
if tUsers[user.iProfile] == nil then
tUsers[user.iProfile] = {}
end
if tUsers[user.iProfile] then
if tUsers[user.iProfile][user.sName] then
tUsers[user.iProfile][user.sName] = nil
end
end
end
UserDisconnected = OpDisconnected
plop
good script