Here is a Lua5 version of plop's Crazy Bot converted for someone at the other Lua forums.
-- crazy bot by plop
-- marvelous string reverse function by lua guru rabidwombat
-- lot of folks are gonne need meditation if this bot releases it's powers
-- no i didn't have 2 much time, it was a great way 2 learn 2 manipulate strings
-- converted to Lua5 by Rincewind (14/11/2005)
Bot = "crazy bot"
-- default mode wich is starts in
MODE = 1
-- put this on 1 to start it default in random mode, otherwise 0
RANDOM = 0
-- if you set this to 1 it will start the moment you launch the bot, better to keep it on 0
CRAZY = 0
function ChatArrival(user, data)
if user.bOperator ~= nil then
name = user.sName
s,e,cmd,onoff= string.find(data,"%b<>%s(.+)%s(.+)")
if (cmd == "!crazy") then
if string.find(onoff, "on") then
CRAZY = 1
user:SendData(Bot, "Crazy mode enabled |" ) return 1
elseif string.find(onoff, "off")then
CRAZY = 0
user:SendData(Bot, "Crazy mode disabled |" ) return 1
elseif string.find(onoff, "full") then
MODE = 1
user:SendData(Bot, "Full lines will be reversed |" ) return 1
elseif string.find(onoff, "msg") then
MODE = 2
user:SendData(Bot, "Only the message will be reversed |" ) return 1
elseif string.find(onoff, "words") then
MODE = 3
user:SendData(Bot, "Single words will be reversed |" ) return 1
elseif string.find(onoff, "flipfull") then
MODE = 4
user:SendData(Bot, "Full lines will be flipped |" ) return 1
elseif string.find(onoff, "flipnick") then
MODE = 5
user:SendData(Bot, "Nicks will be flipped |" ) return 1
elseif string.find(onoff, "flip") then
MODE = 6
user:SendData(Bot, "Only the message will be flipped |" ) return 1
elseif string.find(onoff, "nick") then
MODE = 7
user:SendData(Bot, "Nicks will be reversed |" ) return 1
elseif string.find(onoff, "random") then
if RANDOM == 0 then
RANDOM = 1
user:SendData(Bot, "Get ready, random mode enabled |" )
else
RANDOM = 0
user:SendData(Bot, "Order restored, random mode disabled |" ) return 1
end
elseif string.find(onoff, "help") then
CrazyHelp(user) return 1
end
end
end
if CRAZY == 1 then
if not string.find(data, "$.+") then
if RANDOM == 1 then MODE = math.random(7) end
if MODE == 1 then
data = string.sub(data, 1, (string.len(data)-1))
msg2 = reverse(data)
SendToAll(msg2)
return 1
elseif MODE == 2 then
data = string.sub(data, 1, (string.len(data)-1))
s,e,msg= string.find(data,"%b<>%s(.+)")
SendToAll(user.sName, reverse(msg))
return 1
elseif MODE == 3 then
data = string.sub(data, 1, (string.len(data)-1))
s,e,msg= string.find(data,"%b<>%s(.+)")
_, count = string.gsub(msg, " ", " ")
local line = ""
for i=1,(count+1) do
s,e,msg2,msg3 = string.find(msg,"(.+)%s(.+)")
if msg3 == nil then
line = (reverse(msg).." "..line)
else
line = (reverse(msg3).." "..line)
msg = string.sub(msg, 1, (string.len(msg2)))
end
end
SendToAll(user.sName, line)
return 1
elseif MODE == 4 then
data = string.sub(data, 1, (string.len(data)-1))
msg2 = string.gsub(data, "(.)(.)", "%2%1")
SendToAll(msg2)
return 1
elseif MODE == 5 then
data = string.sub(data, 1, (string.len(data)-1))
s,e,msg= string.find(data,"%b<>%s(.+)")
who = string.gsub(user.sName, "(.)(.)", "%2%1")
SendToAll(who, msg)
return 1
elseif MODE == 6 then
data = string.sub(data, 1, (string.len(data)-1))
s,e,msg= string.find(data,"%b<>%s(.+)")
msg2 = string.gsub(msg, "(.)(.)", "%2%1")
SendToAll(user.sName, msg2)
return 1
elseif MODE == 7 then
data = string.sub(data, 1, (string.len(data)-1))
s,e,msg= string.find(data,"%b<>%s(.+)")
who = reverse(user.sName)
SendToAll(who, msg)
return 1
end
end
end
end
function reverse(str)
if(string.len(str) < 2) then
return str;
else
str = string.gsub(str, "^(.)(.*)(.)$", function(a, b, c) return c..reverse(b)..a; end, 1);
return str;
end
end
function CrazyHelp(user)
user:SendPM(Bot, "!crazy on \t- enables crazy bot|" )
user:SendPM(Bot, "!crazy off \t- disables crazy bot|" )
user:SendPM(Bot, "!crazy full \t- Full lines will be reversed|" )
user:SendPM(Bot, "!crazy msg \t- Only the message will be reversed|" )
user:SendPM(Bot, "!crazy words \t- Single words will be reversed|" )
user:SendPM(Bot, "!crazy flipfull \t- Full lines will be flipped|" )
user:SendPM(Bot, "!crazy flipnick \t- Nicks will be flipped|" )
user:SendPM(Bot, "!crazy nick \t- Message will be flipped|" )
user:SendPM(Bot, "!crazy flip \t- Nicks will be reversed|" )
user:SendPM(Bot, "!crazy random \t- Picks on random from the above types, trigger again to disable|" )
user:SendPM(Bot, "!crazy help \t- What you are looking at now|" )
end
Quote-- no i didn't have 2 much time, it was a great way 2 learn 2 manipulate strings
Thought so, that script is veeeery, repetitive but the output must be interesting !
The output is interestingly like gibberish in most cases but with some of my users no-one will notice the difference :D
Very usefull script :)
nice script thx :))