Word replace script - Page 2
 

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

Word replace script

Started by VAZ, 19 September, 2004, 02:38:42

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

BottledHate

new version... 0.4

+abilty to turn main chat or pm wordreplace on or off...
+changed code around a bit... hopefully more efficient.
+added global bot on or off.
+something else i'm sure but i forget :D

--//Word Replace Bot v0.4
--//By: BottledHate
--//Requested by: VAZ
--//23/09/04
--//18/09/04(first release)

--//if using new pto w/ lua 5 erase this stuff...
string = {}
string.sub = strsub
string.find = strfind
string.gsub = gsub
string.len = strlen
string.lower = strlower
string.type = type
string.format = format
io = {}
io.open = openfile
io.close = closefile
io.write = write
os={}
os.execute = execute
os.clock = clock
table= {}
table.getn = getn
table.insert = tinsert
table.remove = tremove
math = {}
math.random = random
--// ok stop erasing!

rUserDefined = {
--//edit only the stuff in quotes to your liking:
 --//(****COMMANDS are for OPS ONLY****)
aWord = "!aword", --//   --//add a  to the repace list. a "*" in front of the  makes it absolute.
rWord = "!rword", --//  --//remove a  from the replace list.
rHelp = "!rhelp", --//displays the help list
rView = "!rview", --//displays the current list of replace words.
BotOnOff = "!rbot", --//toggle Word Replace Bot ON or OFF.
MainOnOff = "!rmain", --//toggle main chat word replace ON or OFF.
PmOnOff = "!rpm", --//toggle PM word replace ON or OFF.
--//OK STOP EDITING!
}
----------------------------------------
rFileName = "ReplaceBot.dat"
rSFileName = "ReplaceBotSet.dat"
rTable = {}
rSTable = {}
rSTable = {["MainOnOff"] = 1, ["PmOnOff"] = 0, ["BotOnOff"] = 1}
rVer = "v0.4"
function DataArrival(user, data) 
   if (string.sub(data, 1, 1) == "<" ) then 
      data= string.sub(data,1,string.len(data)-1)
      ------------
      local _,_,c =strfind(data, "%b<>%s+(%S+)")
      if rcmdF[c] and user.bOperator then
         local _,_,c,p1,p2,p3=strfind(data, "%b<>%s+(%S+)%s*(%S*)%s*(.*)")
         rcmdF[c](user,p1,p2,p3)
         return 1
      end
      ------------
      if rSTable.BotOnOff == 0 then return end
      if rSTable.MainOnOff == 0 then return end
      local x = nil
      local _,_,data = strfind(data, "%b<>%s?(.*)")
      data = string.lower(data)
      x = rFunctions.doStuff(data)      
      if x then
         SendToAll(user.sName, x)
         return 1 
      end
   elseif strsub(data, 1, 5) == "$To: " then
      if rSTable.BotOnOff == 0 then return end
      if rSTable.PmOnOff == 0 then return end
      local s,e,to = strfind(data, "$To: (%S+)")
      local x=nil
      local _,_,to,d =string.find(data, "$To:%s(%S+)%sFrom:%s%S+%s%$%b<> (.*)|")
      x = rFunctions.doStuff(d)      
      if x then
         GetItemByName(to):SendData("$To: "..to.." From: "..user.sName.." $<"..user.sName.."> "..x.."|")
         return 1
      end
   end
end
-------------------------
rFunctions = {
   doStuff = function(d)
      local reply = d
      r = nil
      for k,v in rTable do
         x = k
         if string.sub(x,1,1) =="*" then
            x = string.gsub(k,"*","")
            rr = nil
            local msg = gsub(reply,"(%S+)",
            function (w)
               if w == x then
                  r,rr = 1,1
                  return rTable["*"..x]
               else
                  return w
               end
            end)
            if rr then reply = msg end               
         else
            if string.find(reply, x) then
               r = 1
               reply = string.gsub(reply,"("..x..")",v)
            end
         end
      end
      if r then
         return reply
      end
   end,
   -------------------------   
   saveData = function(t,tn,file)
      local data = rFunctions.Serialize(t, tn, "")
      local f,e = io.open( file, "w+" ) 
      if f then
        io.write(f, data )
        io.close(f)
      end
   end,
   -------------------------   
   VerifyFile = function(file)
      local f,e = io.open(file, "a+" ) 
      if f then io.close(f) return 1
      else 
         local _,_,path = string.find(file, "(.+[/_\\]).+$") 
         if path ~= nil then os.execute("mkdir ".."\""..string.gsub(path, "/", "\\").."\"") end
         f,e = io.open( file, "a+" )
         if f then io.close(f) return 2
         else return 0 end
      end
   end,
   -------------------------
   Serialize = function(Table, sTableName, sTab)
      sTab = sTab or "";
      sTmp = ""
      sTmp = sTmp..sTab..sTableName.."={"
      local tStart = 0
      for key, value in Table do
         if tStart == 1 then
            sTmp = sTmp..",\r\n"
         else
            sTmp = sTmp.."\r\n"
            tStart = 1
         end
         local sKey = (string.type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
         if(type(value) == "table") then
            sTmp = sTmp..rFunctions.Serialize(value, sKey, sTab.."\t");
         else
            local sValue = (string.type(value) == "string") and string.format("%q",value) or tostring(value);
            sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
         end
      end
      sTmp = sTmp.."\r\n"..sTab.."}"
      return sTmp 
   end,
}

---------------------------------------
rcmdF = {
   [rUserDefined.aWord] = function(u,p1,p2)
      if p1 ~= "" then
         rTable[p1] = p2
         u:SendData("*** Word Replacce Bot "..rVer..": The word '"..p1.."' will be replaced with '"..p2.."'. ***")
         rFunctions.saveData(rTable,"rTable",rFileName)
      else
         u:SendData("*** Word Replacce Bot "..rVer..": Syntax Error. "..rUserDefined.rhelp.." for help. ***")
      end
   end,
-------------------------    
   [rUserDefined.rWord] = function(u,p1)
      if rTable[p1] then
         rTable[p1] = nil
         u:SendData("*** Word Replacce Bot "..rVer..": The word '"..p1.."' was removed from the words list. ***")
         rFunctions.saveData(rTable,"rTable",rFileName)
      else
         u:SendData("*** Word Replacce Bot "..rVer..": Error '"..p1.."' not on words list. "..rUserDefined.rView.." to view the words list. ***")
      end
   end,
-------------------------    
   [rUserDefined.rHelp] = function(u)
      local txtT = {[0] = "OFF", [1] = "ON"}
      u:SendData("*** Word Replacce Bot "..rVer.." ***\r\n\r\n"..
         "\t\t\t\t-=Bot Status=-\r\n\r\n"..
         "\tThe Word Replace Bot is currently: "..txtT[rSTable.BotOnOff].."    (global)\r\n"..
         "\tMain Chat Word Replace Bot is currently: "..txtT[rSTable.MainOnOff].."\r\n"..
         "\tPrivate Message Word Replace Bot is currently: "..txtT[rSTable.PmOnOff].."\r\n\r\n"..
         "\t\t\t\t-=Help Menu=-\r\n\r\n"..
         "\t"..rUserDefined.aWord.."  \tAdds a word to the words list. (\"*\" in front of  makes  absolute.)\r\n"..
         "\t"..rUserDefined.rWord.." \t\t\tRemoves a word from the words list.\r\n"..
         "\t"..rUserDefined.rView.."\t\t\t\tShows the current words list.\r\n"..
         "\t"..rUserDefined.BotOnOff.."\t\t\t\tToggles Word Replace Bot "..rVer.." ON or OFF. (settings are not changed)\r\n"..
         "\t"..rUserDefined.MainOnOff.."\t\t\t\tToggles Main Chat word replace ON or OFF.\r\n"..
         "\t"..rUserDefined.PmOnOff.."\t\t\t\tToggles Private Message word replace ON or OFF.\r\n"..
         "\t"..rUserDefined.rHelp.."\t\t\t\tTHIS.\r\n\r\n")
   end,
------------------------- 
   [rUserDefined.rView] = function(u)
      local x = "*** Word Replacce Bot "..rVer.." ***\r\n\r\n"..
         "\t\t-=Current Words List=-\r\n"..
         "\t  Word\t\t-\t  Replace Word\r\n"..
         "\t------------------------------------------------------------\r\n"
      for k,v in rTable do
         if string.len(k) >= 7 then
            x = x.."\t"..k.."\t-\t"..v.."\r\n"
         else
            x = x.."\t"..k.."\t\t-\t"..v.."\r\n"
         end
      end
      u:SendData(x)
   end,
-------------------------
   [rUserDefined.BotOnOff] = function(u)
      if rSTable.BotOnOff == 1 then
         rSTable.BotOnOff = 0
         u:SendData("*** Word Replacce Bot "..rVer..": Is now completly *OFF*. ***")
      else
         rSTable.BotOnOff = 1
         u:SendData("*** Word Replacce Bot "..rVer..": Is now *ON*. ***")
      end   
      rFunctions.saveData(rSTable,"rSTable",rSFileName)
   end,   
-------------------------
   [rUserDefined.MainOnOff] = function(u)
      if rSTable.MainOnOff == 1 then
         rSTable.MainOnOff = 0
         u:SendData("*** Word Replacce Bot "..rVer..": Main Chat toggled *OFF*. ***")
      else
         rSTable.MainOnOff = 1
         u:SendData("*** Word Replacce Bot "..rVer..": Main Chat toggled *ON*. ***")
      end
      rFunctions.saveData(rSTable,"rSTable",rSFileName)
   end,
-------------------------
   [rUserDefined.PmOnOff] = function(u)
      if rSTable.PmOnOff == 1 then
         rSTable.PmOnOff = 0
         u:SendData("*** Word Replacce Bot "..rVer..": PM toggled *OFF*. ***")
      else
         rSTable.PmOnOff = 1
         u:SendData("*** Word Replacce Bot "..rVer..": PM Chat toggled *ON*. ***")
      end   
      rFunctions.saveData(rSTable,"rSTable",rSFileName)
   end,
}
-----------------------------------
local r = rFunctions.VerifyFile(rFileName)
if r ==1 then
   dofile(rFileName)
end
local r = rFunctions.VerifyFile(rSFileName)
if r ==1 then
   dofile(rSFileName)
end


--//Word Replacce Bot v0.4, by BottledHate (23/09/04)

-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

VAZ

hehe ok i understand.

Madman

#27
Hello BH..
I found a little bug.. Dont know if anything u can do about it though...

Okey.. some background info.. Me and a freind got a hub each.. And i got a multi hub prg.. So our mainchats act as one..
This prg has to be a op.. i named it Multi..
My hub is called D1 and hes D2

Okey now to the bug... it is kind of the same bug i reported last.. ;p

I write this in D2
[23:03:39] <[DN]Madman> test  av script... adn dide , sunis aaa
And in D1 is comes up as this
[23:03:41] {d2•[dn]madman } test  av script... and Didde , Sunnis Japp

As u can see my named got smal letters again.... and D2 is writen in smal chars...

Can u fix it? or is the only way to tell my freind to use the script to?

*edit*
• is suposed to be a some kind of dot... It is the forum that dosn't support it..

Thanx in advance //Madman
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

BottledHate

#28
the reason it does that is because it considers anything after the name to be text.... if you both ran the bot, it would solve that problem.... because the text will get fixed in the appropriate hub, before getting sent out to multi hub.


-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

Madman

Okey.. Thats what i thought =) just had to ask...
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

BottledHate

or if you don't want to run it in both hubs.. here is a modded versoin for your multi hub based on the sample text provided above....

this version works as normal if you don't use multi hub.... only thing that is different is if it finds "{nick}" at the beginning of the text, it leaves it alone.

--//Word Replace Bot v0.4(multi)
--//By: BottledHate
--//Requested by: VAZ
--//25/09/04
--//18/09/04(first release)

--//if using new pto w/ lua 5 erase this stuff...
string = {}
string.sub = strsub
string.find = strfind
string.gsub = gsub
string.len = strlen
string.lower = strlower
string.type = type
string.format = format
io = {}
io.open = openfile
io.close = closefile
io.write = write
os={}
os.execute = execute
os.clock = clock
table= {}
table.getn = getn
table.insert = tinsert
table.remove = tremove
math = {}
math.random = random
--// ok stop erasing!

rUserDefined = {
--//edit only the stuff in quotes to your liking:
 --//(****COMMANDS are for OPS ONLY****)
aWord = "!aword", --//   --//add a  to the repace list. a "*" in front of the  makes it absolute.
rWord = "!rword", --//  --//remove a  from the replace list.
rHelp = "!rhelp", --//displays the help list
rView = "!rview", --//displays the current list of replace words.
BotOnOff = "!rbot", --//toggle Word Replace Bot ON or OFF.
MainOnOff = "!rmain", --//toggle main chat word replace ON or OFF.
PmOnOff = "!rpm", --//toggle PM word replace ON or OFF.
--//OK STOP EDITING!
}
----------------------------------------
rFileName = "ReplaceBot.dat"
rSFileName = "ReplaceBotSet.dat"
rTable = {}
rSTable = {}
rSTable = {["MainOnOff"] = 1, ["PmOnOff"] = 0, ["BotOnOff"] = 1}
rVer = "v0.4(multi)"
function DataArrival(user, data) 
   if (string.sub(data, 1, 1) == "<" ) then 
      data= string.sub(data,1,string.len(data)-1)
      ------------
      local _,_,c =strfind(data, "%b<> (%S*)")
      if rcmdF[c] and user.bOperator then
         local _,_,c,p1,p2,p3=strfind(data, "%b<>%s+(%S+)%s*(%S*)%s*(.*)")
         rcmdF[c](user,p1,p2,p3)
         return 1
      end
      ------------
      if rSTable.BotOnOff == 0 then return end
      if rSTable.MainOnOff == 0 then return end
      local x = nil
      local multi = nil
      local _,_,text = strfind(data, "%b<>%s?(.*)")
      if string.sub(text, 1,1) == "{" then
         _,_,multi,text = string.find(data,"%b<> (%bxy)%s?(.*)")
      end
      text = string.lower(text)
      x = rFunctions.doStuff(text)      
      if x then
         if multi then
            SendToAll(user.sName, multi.." "..x)
            return 1
         else
            SendToAll(user.sName, x)
            return 1 
         end
      end
   elseif strsub(data, 1, 5) == "$To: " then
      if rSTable.BotOnOff == 0 then return end
      if rSTable.PmOnOff == 0 then return end
      local s,e,to = strfind(data, "$To: (%S+)")
      local x=nil
      local _,_,to,d =string.find(data, "$To:%s(%S+)%sFrom:%s%S+%s%$%b<> (.*)|")
      x = rFunctions.doStuff(d)      
      if x then
         GetItemByName(to):SendData("$To: "..to.." From: "..user.sName.." $<"..user.sName.."> "..x.."|")
         return 1
      end
   end
end
-------------------------
rFunctions = {
   doStuff = function(d)
      local reply = d
      r = nil
      for k,v in rTable do
         x = k
         if string.sub(x,1,1) =="*" then
            x = string.gsub(k,"*","")
            rr = nil
            local msg = gsub(reply,"(%S+)",
            function (w)
               if w == x then
                  r,rr = 1,1
                  return rTable["*"..x]
               else
                  return w
               end
            end)
            if rr then reply = msg end               
         else
            if string.find(reply, x) then
               r = 1
               reply = string.gsub(reply,"("..x..")",v)
            end
         end
      end
      if r then
         return reply
      end
   end,
   -------------------------   
   saveData = function(t,tn,file)
      local data = rFunctions.Serialize(t, tn, "")
      local f,e = io.open( file, "w+" ) 
      if f then
        io.write(f, data )
        io.close(f)
      end
   end,
   -------------------------   
   VerifyFile = function(file)
      local f,e = io.open(file, "a+" ) 
      if f then io.close(f) return 1
      else 
         local _,_,path = string.find(file, "(.+[/_\\]).+$") 
         if path ~= nil then os.execute("mkdir ".."\""..string.gsub(path, "/", "\\").."\"") end
         f,e = io.open( file, "a+" )
         if f then io.close(f) return 2
         else return 0 end
      end
   end,
   -------------------------
   Serialize = function(Table, sTableName, sTab)
      sTab = sTab or "";
      sTmp = ""
      sTmp = sTmp..sTab..sTableName.."={"
      local tStart = 0
      for key, value in Table do
         if tStart == 1 then
            sTmp = sTmp..",\r\n"
         else
            sTmp = sTmp.."\r\n"
            tStart = 1
         end
         local sKey = (string.type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
         if(type(value) == "table") then
            sTmp = sTmp..rFunctions.Serialize(value, sKey, sTab.."\t");
         else
            local sValue = (string.type(value) == "string") and string.format("%q",value) or tostring(value);
            sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
         end
      end
      sTmp = sTmp.."\r\n"..sTab.."}"
      return sTmp 
   end,
}

---------------------------------------
rcmdF = {
   [rUserDefined.aWord] = function(u,p1,p2)
      if p1 ~= "" then
         rTable[p1] = p2
         u:SendData("*** Word Replacce Bot "..rVer..": The word '"..p1.."' will be replaced with '"..p2.."'. ***")
         rFunctions.saveData(rTable,"rTable",rFileName)
      else
         u:SendData("*** Word Replacce Bot "..rVer..": Syntax Error. "..rUserDefined.rhelp.." for help. ***")
      end
   end,
-------------------------    
   [rUserDefined.rWord] = function(u,p1)
      if rTable[p1] then
         rTable[p1] = nil
         u:SendData("*** Word Replacce Bot "..rVer..": The word '"..p1.."' was removed from the words list. ***")
         rFunctions.saveData(rTable,"rTable",rFileName)
      else
         u:SendData("*** Word Replacce Bot "..rVer..": Error '"..p1.."' not on words list. "..rUserDefined.rView.." to view the words list. ***")
      end
   end,
-------------------------    
   [rUserDefined.rHelp] = function(u)
      local txtT = {[0] = "OFF", [1] = "ON"}
      u:SendData("*** Word Replacce Bot "..rVer.." ***\r\n\r\n"..
         "\t\t\t\t-=Bot Status=-\r\n\r\n"..
         "\tThe Word Replace Bot is currently: "..txtT[rSTable.BotOnOff].."    (global)\r\n"..
         "\tMain Chat Word Replace Bot is currently: "..txtT[rSTable.MainOnOff].."\r\n"..
         "\tPrivate Message Word Replace Bot is currently: "..txtT[rSTable.PmOnOff].."\r\n\r\n"..
         "\t\t\t\t-=Help Menu=-\r\n\r\n"..
         "\t"..rUserDefined.aWord.."  \tAdds a word to the words list. (\"*\" in front of  makes  absolute.)\r\n"..
         "\t"..rUserDefined.rWord.." \t\t\tRemoves a word from the words list.\r\n"..
         "\t"..rUserDefined.rView.."\t\t\t\tShows the current words list.\r\n"..
         "\t"..rUserDefined.BotOnOff.."\t\t\t\tToggles Word Replace Bot "..rVer.." ON or OFF. (settings are not changed)\r\n"..
         "\t"..rUserDefined.MainOnOff.."\t\t\t\tToggles Main Chat word replace ON or OFF.\r\n"..
         "\t"..rUserDefined.PmOnOff.."\t\t\t\tToggles Private Message word replace ON or OFF.\r\n"..
         "\t"..rUserDefined.rHelp.."\t\t\t\tTHIS.\r\n\r\n")
   end,
------------------------- 
   [rUserDefined.rView] = function(u)
      local x = "*** Word Replacce Bot "..rVer.." ***\r\n\r\n"..
         "\t\t-=Current Words List=-\r\n"..
         "\t  Word\t\t-\t  Replace Word\r\n"..
         "\t------------------------------------------------------------\r\n"
      for k,v in rTable do
         if string.len(k) >= 7 then
            x = x.."\t"..k.."\t-\t"..v.."\r\n"
         else
            x = x.."\t"..k.."\t\t-\t"..v.."\r\n"
         end
      end
      u:SendData(x)
   end,
-------------------------
   [rUserDefined.BotOnOff] = function(u)
      if rSTable.BotOnOff == 1 then
         rSTable.BotOnOff = 0
         u:SendData("*** Word Replacce Bot "..rVer..": Is now completly *OFF*. ***")
      else
         rSTable.BotOnOff = 1
         u:SendData("*** Word Replacce Bot "..rVer..": Is now *ON*. ***")
      end   
      rFunctions.saveData(rSTable,"rSTable",rSFileName)
   end,   
-------------------------
   [rUserDefined.MainOnOff] = function(u)
      if rSTable.MainOnOff == 1 then
         rSTable.MainOnOff = 0
         u:SendData("*** Word Replacce Bot "..rVer..": Main Chat toggled *OFF*. ***")
      else
         rSTable.MainOnOff = 1
         u:SendData("*** Word Replacce Bot "..rVer..": Main Chat toggled *ON*. ***")
      end
      rFunctions.saveData(rSTable,"rSTable",rSFileName)
   end,
-------------------------
   [rUserDefined.PmOnOff] = function(u)
      if rSTable.PmOnOff == 1 then
         rSTable.PmOnOff = 0
         u:SendData("*** Word Replacce Bot "..rVer..": PM toggled *OFF*. ***")
      else
         rSTable.PmOnOff = 1
         u:SendData("*** Word Replacce Bot "..rVer..": PM Chat toggled *ON*. ***")
      end   
      rFunctions.saveData(rSTable,"rSTable",rSFileName)
   end,
}
-----------------------------------
local r = rFunctions.VerifyFile(rFileName)
if r ==1 then
   dofile(rFileName)
end
local r = rFunctions.VerifyFile(rSFileName)
if r ==1 then
   dofile(rSFileName)
end


--//Word Replacce Bot v0.4(multi), by BottledHate (25/09/04)



-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

Madman

Yup it left the text alone.. so now if i write in D2 all in D1 will see how bad speller i'm... lol
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

BottledHate

if you put the script on both hubs and just give the "ReplaceBot.dat" to the other hub.. it contains all of your replace words.. then everything will be the same.

i hope everything works out ok... :D

-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

Madman

#33
Found a little bug...
We added hammarby and replaced it with AIK
The a clever Op realiced that if he wrote h-a-m-m-a-r-b-y it would get replaced.. so we added h-a-m-m-a-r-b-y to...
But beacuse of that every time someone wrote a y it was replaced with a AIK
*edit*
Found another bug..

the word scruffy is replaced with Scruffy

then if i use the the command !kenny
!kenny [OP]Scruffy
it shows !kenny [op]Scruffy in main.. and he does'nt get kennyed...

*edit 2*
Damm... The little letters are evil....
I wrote this..
[20:44:45] <[DN]Madman> nej d?.. bara onykter.....*ljuger*
and then a bart copyed it
[20:49:02] <[OP]Bart_simpson> "<[dn]Madman> nej d?.. bara onykter.....*ljuger*"

as u can see the my nick got [dn] again..
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

BottledHate

#34
ok.. i completly redid the word replaceing function itself... and it should be all good now. it should effect any other words than the replace words....

--//Word Replace Bot v0.5
--//By: BottledHate
--//Requested by: VAZ
--//25/09/04
--//18/09/04(first release)

--//if using new pto w/ lua 5 erase this stuff...
string = {}
string.sub = strsub
string.find = strfind
string.gsub = gsub
string.len = strlen
string.lower = strlower
string.type = type
string.format = format
io = {}
io.open = openfile
io.close = closefile
io.write = write
os={}
os.execute = execute
os.clock = clock
table= {}
table.getn = getn
table.insert = tinsert
table.remove = tremove
math = {}
math.random = random
--// ok stop erasing!

rUserDefined = {
--//edit only the stuff in quotes to your liking:
 --//(****COMMANDS are for OPS ONLY****)
aWord = "!aword", --//   --//add a  to the repace list. a "*" in front of the  makes it absolute.
rWord = "!rword", --//  --//remove a  from the replace list.
rHelp = "!rhelp", --//displays the help list
rView = "!rview", --//displays the current list of replace words.
BotOnOff = "!rbot", --//toggle Word Replace Bot ON or OFF.
MainOnOff = "!rmain", --//toggle main chat word replace ON or OFF.
PmOnOff = "!rpm", --//toggle PM word replace ON or OFF.
--//OK STOP EDITING!
}
----------------------------------------
rFileName = "ReplaceBot.dat"
rSFileName = "ReplaceBotSet.dat"
rTable = {}
rSTable = {}
rSTable = {["MainOnOff"] = 1, ["PmOnOff"] = 0, ["BotOnOff"] = 1}
rVer = "v0.5"
function DataArrival(user, data) 
   if (string.sub(data, 1, 1) == "<" ) then 
      data= string.sub(data,1,string.len(data)-1)
      ------------
      local _,_,c =strfind(data, "%b<> (%S*)")
      if rcmdF[c] and user.bOperator then
         local _,_,c,p1,p2,p3=strfind(data, "%b<>%s+(%S+)%s*(%S*)%s*(.*)")
         rcmdF[c](user,p1,p2,p3)
         return 1
      end
      ------------
      if rSTable.BotOnOff == 0 then return end
      if rSTable.MainOnOff == 0 then return end
      local x = nil
      local multi = nil
      local _,_,text = strfind(data, "%b<>%s?(.*)")
      if string.sub(text, 1,1) == "{" then
         _,_,multi,text = string.find(data,"%b<> (%b{})%s?(.*)")
      end
      x = rFunctions.doStuff(text)      
      if x then
         if multi then
            SendToAll(user.sName, multi.." "..x)
            return 1
         else
            SendToAll(user.sName, x)
            return 1 
         end
      end
   elseif strsub(data, 1, 5) == "$To: " then
      if rSTable.BotOnOff == 0 then return end
      if rSTable.PmOnOff == 0 then return end
      local s,e,to = strfind(data, "$To: (%S+)")
      local x=nil
      local _,_,to,d =string.find(data, "$To:%s(%S+)%sFrom:%s%S+%s%$%b<> (.*)|")
      x = rFunctions.doStuff(d)      
      if x then
         GetItemByName(to):SendData("$To: "..to.." From: "..user.sName.." $<"..user.sName.."> "..x.."|")
         return 1
      end
   end
end
-------------------------
rFunctions = {
   doStuff = function(d)
      local reply = d
      r = nil
      for k,v in rTable do
         x = k
         if string.sub(x,1,1) =="*" then
            x = string.sub(k,2)
            reply = string.gsub(reply,"(%S+)",
               function(w)
                  if string.lower(w) == x then
                     r = 1
                     return rTable["*"..x]
                  else
                     return w
                  end
               end)
         else
            WRcnt = 0
            local m = gsub(string.lower(reply),"(%S+)",
               function (w)
                  if string.find(w,x) then
                     WRcnt = WRcnt + 1
                  end
               end)
            for y = -1,WRcnt do
               local s,e = nil,nil
               s,e = string.find(string.lower(reply), x)
               if s then
                  r = 1
                  reply = string.sub(reply,1,s-1)..v..string.sub(reply,e+1)
               end
            end
         end
      end
      if r then
         return reply
      end
   end,
   -------------------------   
   saveData = function(t,tn,file)
      local data = rFunctions.Serialize(t, tn, "")
      local f,e = io.open( file, "w+" ) 
      if f then
        io.write(f, data )
        io.close(f)
      end
   end,
   -------------------------   
   VerifyFile = function(file)
      local f,e = io.open(file, "a+" ) 
      if f then io.close(f) return 1
      else 
         local _,_,path = string.find(file, "(.+[/_\\]).+$") 
         if path ~= nil then os.execute("mkdir ".."\""..string.gsub(path, "/", "\\").."\"") end
         f,e = io.open( file, "a+" )
         if f then io.close(f) return 2
         else return 0 end
      end
   end,
   -------------------------
   Serialize = function(Table, sTableName, sTab)
      sTab = sTab or "";
      sTmp = ""
      sTmp = sTmp..sTab..sTableName.."={"
      local tStart = 0
      for key, value in Table do
         if tStart == 1 then
            sTmp = sTmp..",\r\n"
         else
            sTmp = sTmp.."\r\n"
            tStart = 1
         end
         local sKey = (string.type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
         if(type(value) == "table") then
            sTmp = sTmp..rFunctions.Serialize(value, sKey, sTab.."\t");
         else
            local sValue = (string.type(value) == "string") and string.format("%q",value) or tostring(value);
            sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
         end
      end
      sTmp = sTmp.."\r\n"..sTab.."}"
      return sTmp 
   end,
}

---------------------------------------
rcmdF = {
   [rUserDefined.aWord] = function(u,p1,p2)
      if p1 ~= "" then
         rTable[p1] = p2
         u:SendData("*** Word Replacce Bot "..rVer..": The word '"..p1.."' will be replaced with '"..p2.."'. ***")
         rFunctions.saveData(rTable,"rTable",rFileName)
      else
         u:SendData("*** Word Replacce Bot "..rVer..": Syntax Error. "..rUserDefined.rhelp.." for help. ***")
      end
   end,
-------------------------    
   [rUserDefined.rWord] = function(u,p1)
      if rTable[p1] then
         rTable[p1] = nil
         u:SendData("*** Word Replacce Bot "..rVer..": The word '"..p1.."' was removed from the words list. ***")
         rFunctions.saveData(rTable,"rTable",rFileName)
      else
         u:SendData("*** Word Replacce Bot "..rVer..": Error '"..p1.."' not on words list. "..rUserDefined.rView.." to view the words list. ***")
      end
   end,
-------------------------    
   [rUserDefined.rHelp] = function(u)
      local txtT = {[0] = "OFF", [1] = "ON"}
      u:SendData("*** Word Replacce Bot "..rVer.." ***\r\n\r\n"..
         "\t\t\t\t-=Bot Status=-\r\n\r\n"..
         "\tThe Word Replace Bot is currently: "..txtT[rSTable.BotOnOff].."    (global)\r\n"..
         "\tMain Chat Word Replace Bot is currently: "..txtT[rSTable.MainOnOff].."\r\n"..
         "\tPrivate Message Word Replace Bot is currently: "..txtT[rSTable.PmOnOff].."\r\n\r\n"..
         "\t\t\t\t-=Help Menu=-\r\n\r\n"..
         "\t"..rUserDefined.aWord.."  \tAdds a word to the words list. (\"*\" in front of  makes  absolute.)\r\n"..
         "\t"..rUserDefined.rWord.." \t\t\tRemoves a word from the words list.\r\n"..
         "\t"..rUserDefined.rView.."\t\t\t\tShows the current words list.\r\n"..
         "\t"..rUserDefined.BotOnOff.."\t\t\t\tToggles Word Replace Bot "..rVer.." ON or OFF. (settings are not changed)\r\n"..
         "\t"..rUserDefined.MainOnOff.."\t\t\t\tToggles Main Chat word replace ON or OFF.\r\n"..
         "\t"..rUserDefined.PmOnOff.."\t\t\t\tToggles Private Message word replace ON or OFF.\r\n"..
         "\t"..rUserDefined.rHelp.."\t\t\t\tTHIS.\r\n\r\n")
   end,
------------------------- 
   [rUserDefined.rView] = function(u)
      local x = "*** Word Replacce Bot "..rVer.." ***\r\n\r\n"..
         "\t\t-=Current Words List=-\r\n"..
         "\t  Word\t\t-\t  Replace Word\r\n"..
         "\t------------------------------------------------------------\r\n"
      for k,v in rTable do
         if string.len(k) >= 7 then
            x = x.."\t"..k.."\t-\t"..v.."\r\n"
         else
            x = x.."\t"..k.."\t\t-\t"..v.."\r\n"
         end
      end
      u:SendData(x)
   end,
-------------------------
   [rUserDefined.BotOnOff] = function(u)
      if rSTable.BotOnOff == 1 then
         rSTable.BotOnOff = 0
         u:SendData("*** Word Replacce Bot "..rVer..": Is now completly *OFF*. ***")
      else
         rSTable.BotOnOff = 1
         u:SendData("*** Word Replacce Bot "..rVer..": Is now *ON*. ***")
      end   
      rFunctions.saveData(rSTable,"rSTable",rSFileName)
   end,   
-------------------------
   [rUserDefined.MainOnOff] = function(u)
      if rSTable.MainOnOff == 1 then
         rSTable.MainOnOff = 0
         u:SendData("*** Word Replacce Bot "..rVer..": Main Chat toggled *OFF*. ***")
      else
         rSTable.MainOnOff = 1
         u:SendData("*** Word Replacce Bot "..rVer..": Main Chat toggled *ON*. ***")
      end
      rFunctions.saveData(rSTable,"rSTable",rSFileName)
   end,
-------------------------
   [rUserDefined.PmOnOff] = function(u)
      if rSTable.PmOnOff == 1 then
         rSTable.PmOnOff = 0
         u:SendData("*** Word Replacce Bot "..rVer..": PM toggled *OFF*. ***")
      else
         rSTable.PmOnOff = 1
         u:SendData("*** Word Replacce Bot "..rVer..": PM Chat toggled *ON*. ***")
      end   
      rFunctions.saveData(rSTable,"rSTable",rSFileName)
   end,
}
-----------------------------------
local r = rFunctions.VerifyFile(rFileName)
if r ==1 then
   dofile(rFileName)
end
local r = rFunctions.VerifyFile(rSFileName)
if r ==1 then
   dofile(rSFileName)
end


--//Word Replacce Bot v0.5, by BottledHate (26/09/04)


-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

Madman

Okey.. i will give it a try efter school tomorrow.. i'm going to bed now...
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Madman

Nope... It dont work... =(

[16:12] <[DN]Madman> [16:11] <[dn]Madman> test av script japp Con Didde Sunnis madman and Bart
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

BottledHate

my bad... forgot to remove one line. edited above.. and working now :D

-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

Madman

Yes, working great.. Thankx =)
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

erre

#39
Hi gentlemen, I have been trying to use this word replace bot but with no success. Is it possble to post a biref explanation on how to install and acitvate this bot?

I am using ptokax 0.3.3.2.21 and a 0.3.3.0 build 15.25

I have made the modification suggested for use in Pto with LUA 5. I have placed replaceobt.dat in de root directory of ptokax and in the scrits directory along with the bot, what is it that I am doing wrong?


Thaks for you help

SMF spam blocked by CleanTalk