Crazy Bot Lua5
 

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

Crazy Bot Lua5

Started by Rincewind, 15 November, 2005, 13:11:39

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rincewind

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

Dessamator

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 !
Ignorance is Bliss.

Rincewind

The output is interestingly like gibberish in most cases but with some of my users no-one will notice the difference :D

Dessamator

Very usefull script :)
Ignorance is Bliss.

m1lk

nice script thx :))

SMF spam blocked by CleanTalk