PtokaX forum

Archive => Archived 5.0 boards => Finished Scripts => Topic started by: CaSaNoVa on 30 May, 2005, 03:30:07

Title: Don't Work ?!
Post by: CaSaNoVa on 30 May, 2005, 03:30:07
-- word replace script.
-- by plop


---- filter what? use 1 to enable, nil to disable the filter.
FilterPm = 1
FilterMain = 1

---- the words to be replaced and by what.
tBadWords = {
   ["fuck"]= "havin sex",
   ["shit"] = "bleeeeeeeeh",
   ["ass"] = "my hiny",
   ["asshole"] = "(place where dirty stuff exits the body)",
   ["dick"] = "male saucage",
   ["cum"] = "body cream",
   ["fucker"] = "I love you",
   ["fuckers"] = "I love you guy's",
   ["fucking"] = "doing dirty",
   ["bastard"] = "naughty boy",
   ["hell"] = "mac donalds",
   ["whore"] = "angel",
   ["rtfm"] = "read the fucking manual",
   ["stfw"] = "surf the fucking web",
   ["coffee"] = "ploppy potion",
}

---- the words to be replaced and by what (function mode).
tBadFuncs = {
   -- replace lol with a random amount of o's
   ["lol"] = function()
      local i = random(1,20)
      return "L"..(strrep("o", i)).."L"
   end
}

-- prefixes table, allowed for me and let commands bypase the replacer
tPre = { ["+"] = 1, ["!"] = 1, ["/"] = 1, ["-"]=1 }

function Main()
   local num = gsub(os.date, "%D", "")
   randomseed(tonumber(num))
end

function CheckWord(word)
   local wordl = strlower(word)
   if tBadWords[wordl] then
      return tBadWords[wordl]
   elseif tBadFuncs[wordl] then
      return tBadFuncs[wordl]()
   else
      return word
   end
end

function DataArrival(user, data)
   if( strsub(data, 1, 1) == "<" ) then
      if FilterMain then
         local s,e,data =strfind(strsub(data, 1, (strlen(data)-1)), "%b<>%s+(.*)")
         local data,c = gsub(data , "(%w+)", function(word) return CheckWord(word) end)
         local s,e,pre, cmd = strfind(data, "^%s*(%W)(%S+)")
         if c ~= 0 then
            if pre and tPre
 then
               if cmd == "me" then
                  SendToAll("* "..user.sName.." "..strsub(data, 5, strlen(data)).."|")
                  return 1
               else
                  return 0
               end
            else
               SendToAll(user.sName, data.."|")
               return 1
            end
         end
      end
   elseif(strsub(data, 1, 4) == "$To:") then
      if FilterPm then
         local s,e,whoto = strfind(data, "%S+%s*(%S+)")
         local s,e,data = strfind(strsub(data, 1, (strlen(data)-1)), "$%b<>%s*(.*)$")
         local data,c=gsub(data , "(%S+)", function(word) return CheckWord(word) end)
         if c ~= 0 then
            SendPmToNick(whoto, user.sName, data.."|")
            return 1
         end
      end
   end
end



>> Syntax ...0.3.3.0.b17.09.nt.dbg\scripts\word_replacer_1.1p.lua:41: attempt to call global `gsub' (a nil value)