PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: lynyrd on 20 December, 2003, 22:45:54

Title: i need help with modifying vip chat
Post by: lynyrd on 20 December, 2003, 22:45:54
hi! i would like to get some help with the chatbot made by piglja..
i have some ideas that would make it suite my needs better.
is it possible to make it get acsessed by a command in main, example #chatroom1 and have a password for it
that the user needs to input.
and have a chat master wich is'nt an op, that have the possibility to invite and kick users from the chat that he has control of?
i don't want ordinary users to know there is a chatroom there..please help me if it's possible to make
best regards lynyrd

-- Very Simple(I am lying) ChatBot by piglja - 24/04/03 till 27/04/03
-- and lots of kisses for the sweet aMutex for his help by piglja 24/04/03 till 27/04/03
-- Modifyed to add users by a file and script restart does not matter by piglja - 02/05/03

botname = "Itchatten"
fname = "table4.tbl"
FFile = "itch.txt"
nick={}
name={}

function Main()
frmHub:RegBot(botname)
Restart()
end

function DataArrival(user, data)
if(strsub(data, 1, 4) == "$To:") then  
data=strsub(data,1,strlen(data)-1)  
s,e,whoTo,from,msg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(.+)")  
if (whoTo == botname) then
if nick[user.sName] ~= nil then
nick[user.sName] = nil
SaveToFile(user.sName,fname,nick)
PmToAStupidTablesGrrrButIAmStartingToLikeThemLOL(msg,from,user.sName)
nick[user.sName]=user.sName
SaveToFile(user.sName,fname,nick)
else
user:SendPM(botname,"You don't have acsess to this chatroom")
end
end
end
end

function PmToAStupidTablesGrrrButIAmStartingToLikeThemLOL(msg,user,one)
   for i,v in nick do
      SendPmToNick(i,botname,"<"..one..">"..msg)
   end
end

function Restart()
local handle = openfile(FFile, "r")
  if (handle ~= nil) then
    local line = read(handle)
    while line do
      nick[line]=line
      SaveToFile(line,fname,nick)
      line = read(handle)
    end
    closefile(handle)
  end
  end

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

function pickle(t)
  return Pickle:clone():pickle_(t)
end
Pickle = {
  clone = function (t) local nt={}; for i, v in t do nt=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\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("%s", v)
  elseif vtype == "number" then return v
  elseif vtype == "table" then return "{"..self:ref_(v).."}"
  else
  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
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 = 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