PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: LordSqueak on 25 January, 2005, 07:11:03

Title: 8ball , with an twist.
Post by: LordSqueak on 25 January, 2005, 07:11:03
I just had this idea for an annoying script.

it should give answers very much in the same way an magic 8ball works.
However, the trigger should be whenever someone asks a question in chat.
in other words if there is an ? in the chat.

(and while im at it , how about making it spout statements like "Not it's not!!!" if someone uses !!'s

silly idea , but I could use something like that to liven up an otherwise dead chat in my puny hub. =)
Title:
Post by: n1ck on 25 January, 2005, 10:09:57
This is what i have so far, i dont get any errors but it doesnt seem to work if a REAL coder could finish this off thanks

-------------------------------------

Version = "4.3"
Bot = "Doorman" --//The Bot...

--==NewFunctionCommand==--
      if cmd == "!8ball" then magicball(curUser)
end

--//For Magicball
function magicball(curUser)
   random = random(7)
      if Taste == 1 then
         SendToAll(" The 8ball says 'Not today'")
      elseif random == 2 then
         SendToAll("The 8ball says 'Yes'")
      elseif random == 3 then
         SendToAll("The 8ball says 'No!'")
      elseif random == 4 then
         SendToAll("The 8ball says 'In time'")
      elseif random == 5 then
         SendToAll("The 8ball says 'Not in your life time'")
      elseif random == 6 then
         SendToAll("The 8ball says 'Ask again'")
      elseif random == 7 then
         SendToAll("The 8ball says 'Probably'")
   end
end

-----------------------------------------------------
Title:
Post by: Madman on 25 January, 2005, 10:52:01
--//8Ball script
--//Requested by LordSqueak
--//Base script made by n1ck
--//Rewritten by Madman
--//Added response to ?
--//Rewrote the random function

Bot = "Doorman" --//The Bot...

--// This function is fired when a new data arrives
function DataArrival(curUser,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == "!8ball" then --//The cmd
MagicBall(curUser) --//Do the function
return 1 --//Do not show the command
end
local s,e,question = strfind(data,"(?)")
if question ~= nil then --//If ? then
MagicBall(curUser) --//Do this
end
end
end

--//For MagicBall
function MagicBall(curUser)
Magic = {
"Not today",
"Yes",
"No!",
"In time",
"Ask again",
"Probably",
"No luck today",
}
SendToAll(Bot, "The 8ball says '" ..Magic[random(getn(Magic))].. "'") --//Coose random in Magic Table
end

This works... and respond to whenever someone writes a ?

QuoteOriginally posted by LordSqueak
and while im at it , how about making it spout statements like "Not it's not!!!" if someone uses !!'s

What do you mean by that?
Please explain more... =)
Title:
Post by: n1ck on 25 January, 2005, 15:08:40
Nice work fella - Hardly my base script lol
Title:
Post by: LordSqueak on 31 January, 2005, 09:24:46
First off , Thank you thank you , it works like a charm , just what i had in mind.
(well , almost , which is why I maimed the code a bit )  :D

Added responce to !
(and a bit of renaming to make it more in style with the Guru)


--//The Guru script
--//Requested by LordSqueak
--//Base script made by n1ck
--//Rewritten by Madman
--//Added response to ?
--//Rewrote the random function
--//Maimed and disected by LordSqueak
--//Added response to !


Bot = "TheGuru" --//The Bot...

--// This function is fired when a new data arrives

function DataArrival(curUser,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == "!guru" then --//The cmd
Question(curUser) --//Do the function
return 1 --//Do not show the command
end

local s,e,question = strfind(data,"(?)")
if question ~= nil then --//If ? then
Question(curUser) --//Do this
end
local s,e,question = strfind(data,"(!)")
if question ~= nil then --//If ! then
Statement(curUser) --//Do this
end
end
end

--//For Question

function Question(curUser)
Wisdom = {
"Not today",
"Yes",
"No!",
"In time",
"Ask again",
"Probably",
"No luck today",
}
SendToAll(Bot, "The Guru says '" ..Wisdom[random(getn(Wisdom))].. "'") --//Choose random in Wisdom Table
end

--//For Statement

function Statement(curUser)
Wisewords = {
"Not today",
"Yes",
"No!",
"That's what you say",
"Oh, Realy?",
"Probably",
}
SendToAll(Bot, "The Guru says '" ..Wisewords[random(getn(Wisewords))].. "'") --//Choose random in Wisewords Table
end
Title:
Post by: Madman on 31 January, 2005, 10:07:19
Np, always happy to help
and nice mod =)
Title:
Post by: LordSqueak on 02 February, 2005, 21:37:15
hmm , I've been adding some silly facts for it to say at unsuspecting chatters.

however , it can get a bit spammy.

is there a simple way to add an timer , so it doesnt spam the chat quite so often, (unless you use the !guru command)

Another thought i had was to make it react with a certain responce to a selection of words, for example beer,drink,booze it would have a set of responces suited for that.
how could I make local s,e,question = strfind(data,"(!)") a set of OR's ?
Title:
Post by: Madman on 03 February, 2005, 23:22:56
--//The Guru script a.k.a 8ball with a twist
--//Requested by LordSqueak
--//Base script made by n1ck
--//Rewritten by Madman
--//Added response to ?
--//Rewrote the random function
--//Maimed and disected by LordSqueak
--//Added response to !
--//Added DeFlood
--//Thanks Mutor And Hawk For The Help With The Word Responds
--//Changed The Word Response

Bot = "TheGuru" --//The Bot...

Timer = 1000 * 10 --1000 * 10 means 10 secs between ! or ?
--milisec * sec * min * hour

function Main()
DeFlood = 0 --//Sets DeFlood To 0 At Script Restart
end

function OnTimer()
DeFlood = 0
StopTimer()
-- SendToAll(Bot, "DeFlood Has Been DeActivated") --//Only For Test Purpose
end

--// This function is fired when a new data arrives
function DataArrival(curUser,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == "!guru" then --//The cmd
Question(curUser) --//Do the function
return 1 --//Do not show the command
end
local s,e,question = strfind(data,"(?)")
if question ~= nil then --//If ? then
if DeFlood == 0 then
StopTimer() --//Stop The Timer If It's Active
SetTimer(Timer) --//What Timer To Set
StartTimer() --//Avtivates The Timer
DeFlood = 1 --//Sets DeFlood High
Question(curUser) --//Do this
elseif DeFlood == 1 then
-- Do Nothing
--curUser:SendData(Bot, "DeFlood Is Active") --//Only For Test Purpose
end
end
local s,e,exclamation = strfind(data,"(!)")
if exclamation ~= nil then --//If ! then
if DeFlood == 0 then
StopTimer()
SetTimer(Timer)
StartTimer()
DeFlood = 1
Statement(curUser) --//Do this
elseif DeFlood == 1 then
-- Do Nothing
--curUser:SendData(Bot, "DeFlood Is Active") --//Only For Test Purpose
end
end
if strfind(strlower(data), "beer") or strfind(strlower(data), "drink") then
if not strfind(data,"(!)") or strfind(data,"(?)") then --//But If ! or ? Do ! Or ? Response
curUser:SendData(Bot, "Beer and Drinking is what i do best") --//Stuff To Do
end
end
end
end

--//For Question
function Question(curUser)
Wisdom = {
"Not today",
"Yes",
"No!",
"In time",
"Ask again",
"Probably",
"No luck today",
}
SendToAll(Bot, "The Guru says '" ..Wisdom[random(getn(Wisdom))].. "'") --//Choose random in Wisdom Table
end

--//For Statement
function Statement(curUser)
Wisewords = {
"Not today",
"Yes",
"No!",
"That's what you say",
"Oh, Realy?",
"Probably",
}
SendToAll(Bot, "The Guru says '" ..Wisewords[random(getn(Wisewords))].. "'") --//Choose random in Wisewords Table
end

I had some prob makeing the word response...
but this is what i come up with....
when typing --->  beer
it will repond with
curUser:SendData(Bot, "Beer and Drinking is what i do best")
but when typing ---> beer! it will answer with
Statement(curUser)
since it responds to the !

*Edit*
Found a bug... So i changed the Word Response...
Title:
Post by: LordSqueak on 07 March, 2005, 07:26:52
Thanks alot , I have been absent for a bit , but I just tested it , and it seems to work just great.

This is the code as it looks after me tweaking it a bit to fit in with my idea.

--//The Guru script a.k.a 8ball with a twist
--//Requested by LordSqueak
--//Base script made by n1ck
--//Rewritten by Madman
--//Added response to ?
--//Rewrote the random function
--//Maimed and disected by LordSqueak
--//Added response to !
--//Added DeFlood
--//Thanks Mutor And Hawk For The Help With The Word Responds
--//Changed The Word Response
--//Tweaked a bit by LordSqueak

--//Version 10

Bot = "TheGuru" --//The Bot...

Timer = 1000 * 10 --1000 * 10 means 10 secs between ! or ?
--milisec * sec * min * hour



function Main()
DeFlood = 0 --//Sets DeFlood To 0 At Script Restart
end



function OnTimer()
DeFlood = 0
StopTimer()
-- SendToAll(Bot, "DeFlood Has Been DeActivated") --//Only For Test Purpose
end


--// This function is fired when a new data arrives
function DataArrival(curUser,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == "!guru" then --//The cmd
Question(curUser) --//Do the function
return 1 --//Do not show the command
end
local s,e,question = strfind(data,"(?)")
if question ~= nil then --//If ? then
if DeFlood == 0 then
StopTimer() --//Stop The Timer If It's Active
SetTimer(Timer) --//What Timer To Set
StartTimer() --//Avtivates The Timer
DeFlood = 1 --//Sets DeFlood High
Question(curUser) --//Do this
elseif DeFlood == 1 then
-- Do Nothing
--curUser:SendData(Bot, "DeFlood Is Active") --//Only For Test Purpose
end
end
local s,e,exclamation = strfind(data,"(!)")
if exclamation ~= nil then --//If ! then
if DeFlood == 0 then
StopTimer()
SetTimer(Timer)
StartTimer()
DeFlood = 1
Statement(curUser) --//Do this
elseif DeFlood == 1 then
-- Do Nothing
--curUser:SendData(Bot, "DeFlood Is Active") --//Only For Test Purpose
end
end
if strfind(strlower(data), "beer") or strfind(strlower(data), "drink") then
if not strfind(data,"(!)") or strfind(data,"(?)") then --//But If ! or ? Do ! Or ? Response
FatherJack(curUser) --//do this
--curUser:SendData(Bot, "Beer and Drinking is what i do best") --//Stuff To Do
end
end
end
end

--//For Question
function Question(curUser)
Wisdom = {
"Not today",
"Yes",
"No!",
"In time",
"Ask again",
"Probably",
"No luck today",
"Uh, I think so",
"The answer shall be written",
"*** Mouse not moving - Out of Cheese Error ***",
"*** Low Memory Alert - the Ram ran away. ****",
"What do you mean?",
"Maybe",
"Perhaps",
"A bit more to the right",
"The answer you seek lies deep within the cave of caerbannog.",
"Is that a philosophical question?",
"I refuse to answer that.",
"Can you be more specific?",
"Can you be less specific?",
"ETA in 37 hours",
"I dont know.",
}
SendToAll(Bot, "The Guru says '" ..Wisdom[random(getn(Wisdom))].. "'") --//Choose random in Wisdom Table
end

--//For Statement
function Statement(curUser)
Wisewords = {
"Give a man a fire, and he will keep warm the whole day.  Set the man on fire, and he will keep warm for the rest of his life.",
"There are 10 types of people in the world... those who understand binary and those who don't.",
"Fire fighters , fight fires. but do Freedom fighters ,, fight freedom?",
"Learning curve - The bend on the leadpipe you get from hitting newbies on the head. ",
"A technician friend of mine says that high-tech devices run on smoke. He says that everything works fine until a malfunction lets the smoke out, and after that the

device doesn't work anymore.",
"If you can read this unaided, You probably dont need glasses.",
"Where does the white go, when snow melts?",
"There Are No Stupid Questions, But There Are A Lot Of Inquisitive Idiots.",
"When You Earnestly Believe You Can Compensate For A Lack Of Skill By Doubling Your Efforts, There's No End To What You Can't Do.",
"Trying Is The First Step Towards Failure",
"Deja Moo: The feeling you've heard this bullshit before.",
"90% of being smart is knowing what you're dumb at.",
"None Of Us Is As Dumb As All Of Us.",
"If You're Not A Part Of The Solution, There's Good Money To Made In Prolonging The Problem.",
"Why do bullies always ask 'what?s your problem' when they're obviously not going to solve it? ",
"Aren't the 'good things that come to those who wait' just the leftovers from the people that got there first?",
"Who was the first person to look at a cow and say, 'I think I'll squeeze these dangly things here and drink what comes out'?",
"Isn't Disney World just a people trap operated by a mouse?",
"If electricity comes from electrons, does morality come from morons?",
"Why is it that if something says, 'do not eat' on the packaging it becomes extra tempting to eat?",
"Isn't it funny how the word 'politics' is made up of the words 'poli' meaning 'many' in Latin, and 'tics' as in 'bloodsucking creatures??",
"Why is there that little space inside strawberries, as if it was meant for a pit, and then the seeds are on the outside?",
"Why is it when we talk to God we are praying, but when God talks to us we are put into the loony bin?",
"How important does a person have to be before they are considered assassinated instead of just murdered?",
"Why does a round pizza come in a square box?",
"If ignorance is bliss, why aren?t more people happy?",
"Isn't it scary that the word 'therapist' is the same as the words 'the' and 'rapist' put together?",
"When pigs fart, does it smell like bacon?",
"Do you need a silencer if you are going to shoot a mime?",
"Do infants enjoy infancy as much as adults enjoy adultery?",
"If olive oil comes from olives, where does baby oil come from?",
"If one synchronized swimmer drowns, do the rest have to drown too?",
"If you spend your day doing nothing, how do you know when you're done?",
"Support bacteria - they're the only culture some people have.",
"I bought some powdered water, but I don't know what to add to it.",
"Did you know that coconuts kill more people than shark attacks?",
"Beer is made by fermentation cause by bacteria feeding on yeast cells and then defecating. In other words, it's a nice tall glass of bacteria doo-doo.",
"Researchers in Denmark found that beer tastes best when drunk to the accompaniment of a certain musical tone. The optimal frequency is different for each beer, they

reported. The correct harmonious tone for Carlsberg Lager, for example, is 510-520 cycles per second.",
"if a fly lost its wings, would it be called a walk?",
"The future is like a baboons ass: Colourful and full of shit.",
"All generalizations are bad.",
"War is god's method of teaching americans Geography",
}
SendToAll(Bot, "The Guru says '" ..Wisewords[random(getn(Wisewords))].. "'") --//Choose random in Wisewords Table
end

--//For Father Jack
function FatherJack(curUser)
Jack = {
"GOBSHITE!",
"DRINK!",
"ARSE!",
"GURLS!",
"DRINK!!!",
"FECK!",
"That would be an eccumenical question.",
"YES!",
}
SendToAll("FatherJack", "" ..Jack[random(getn(Jack))].. "" ) --//Choose random in Jack Table , notice it will post as FatherJack
end


I only need to add a bit where father jack screams "AAAAAAH NUNS!" if someone mentions nuns.
I think i can do that myself .

Thank you all, without you guys , this scritp would never had happened.  :D
Title:
Post by: LordSqueak on 21 September, 2005, 10:18:52
Latest update. Made it run on lua5

TheGuru(5,0).lua

--//The Guru script a.k.a 8ball with a twist
--//Requested by LordSqueak
--//Base script made by n1ck
--//Rewritten by Madman
--//Added response to ?
--//Rewrote the random function
--//Maimed and disected by LordSqueak
--//Added response to !
--//Added DeFlood
--//Thanks Mutor And Hawk For The Help With The Word Responds
--//Changed The Word Response
--//Tweaked a bit by LordSqueak
--//Converted to lua5 by LordSqueak

--//Version 5.0

--//Variables
Bot = "TheGuru" --//The Bot...
Timer = 1000 * 60 --// 1000 * 60 means 60 secs between ! or ?

function Main()
DeFlood = 0 --//Sets DeFlood To 0 At Script Restart
end

function OnTimer()
DeFlood = 0
StopTimer()
-- SendToAll(Bot, "DeFlood Has Been DeActivated") --//Only For Test Purpose
end

--// This function is fired when a new data arrives
function ChatArrival(curUser,data)
if string.sub(data, 1, 1) == "<" then
data=string.sub(data,1,string.len(data)-1)
s,e,cmd = string.find(data,"%b<>%s+(%S+)")
if cmd == "!guru" then --//The cmd
Statement(curUser) --//Do the function
return 1 --//Do not show the command
end
local s,e,question = string.find(data,"(?)")
if question ~= nil then --//If ? then
if DeFlood == 0 then
StopTimer() --//Stop The Timer If It's Active
SetTimer(Timer) --//What Timer To Set
StartTimer() --//Avtivates The Timer
DeFlood = 1 --//Sets DeFlood High
Question(curUser) --//Do this
elseif DeFlood == 1 then
-- Do Nothing
--curUser:SendData(Bot, "DeFlood Is Active") --//Only For Test Purpose
end
end
local s,e,exclamation = string.find(data,"(!!)")
if exclamation ~= nil then --//If ! then
if DeFlood == 0 then
StopTimer()
SetTimer(Timer)
StartTimer()
DeFlood = 1
Statement(curUser) --//Do this
elseif DeFlood == 1 then
-- Do Nothing
--curUser:SendData(Bot, "DeFlood Is Active") --//Only For Test Purpose
end
end

--Father Jack
if string.find(string.lower(data), "nuns") then curUser:SendData("FatherJack", "NUNS!, AAAAAHH!!!") end
if string.find(string.lower(data), "beer") or string.find(string.lower(data), "drink") then
if not string.find(data,"(!!)") or string.find(data,"(?)") then --//But If ! or ? Do ! Or ? Response
FatherJack(curUser) --//do this
--curUser:SendData(Bot, "Beer and Drinking is what i do best") --//Stuff To Do
end
end
end
end

--//For Question
function Question(curUser)
Wisdom = {
"Not today",
"Yes",
"No!",
"In time",
"Ask again",
"Probably",
"No luck today",
"Uh, I think so",
"The answer shall be written",
"*** Mouse not moving - Out of Cheese Error ***",
"*** Low Memory Alert - the Ram ran away. ****",
"What do you mean?",
"Maybe",
"Perhaps",
"A bit more to the right",
"The answer you seek lies deep within the cave of caerbannog.",
"Is that a philosophical question?",
"I refuse to answer that.",
"Can you be more specific?",
"Can you be less specific?",
"ETA in 37 hours",
"I dont know.",
}
SendToAll(Bot, "The Guru says '" ..Wisdom[math.random(table.getn(Wisdom))].. "'") --//Choose random in Wisdom Table
end

--//For Statement
function Statement(curUser)
Wisewords = {
"Give a man a fire, and he will keep warm the whole day.  Set the man on fire, and he will keep warm for the rest of his life.",
"There are 10 types of people in the world... those who understand binary and those who don't.",
"Fire fighters , fight fires. but do Freedom fighters ,, fight freedom?",
"Learning curve - The bend on the leadpipe you get from hitting newbies on the head. ",
"A technician friend of mine says that high-tech devices run on smoke. He says that everything works fine until a malfunction lets the smoke out, and after that the device doesn't work anymore.",
"If you can read this unaided, You probably dont need glasses.",
"Where does the white go, when snow melts?",
"There Are No Stupid Questions, But There Are A Lot Of Inquisitive Idiots.",
"When You Earnestly Believe You Can Compensate For A Lack Of Skill By Doubling Your Efforts, There's No End To What You Can't Do.",
"Trying Is The First Step Towards Failure",
"Deja Moo: The feeling you've heard this bullshit before.",
"90% of being smart is knowing what you're dumb at.",
"None Of Us Is As Dumb As All Of Us.",
"If You're Not A Part Of The Solution, There's Good Money To Made In Prolonging The Problem.",
"Why do bullies always ask 'what?s your problem' when they're obviously not going to solve it? ",
"Aren't the 'good things that come to those who wait' just the leftovers from the people that got there first?",
"Who was the first person to look at a cow and say, 'I think I'll squeeze these dangly things here and drink what comes out'?",
"Isn't Disney World just a people trap operated by a mouse?",
"If electricity comes from electrons, does morality come from morons?",
"Why is it that if something says, 'do not eat' on the packaging it becomes extra tempting to eat?",
"Isn't it funny how the word 'politics' is made up of the words 'poli' meaning 'many' in Latin, and 'tics' as in 'bloodsucking creatures??",
"Why is there that little space inside strawberries, as if it was meant for a pit, and then the seeds are on the outside?",
"Why is it when we talk to God we are praying, but when God talks to us we are put into the loony bin?",
"How important does a person have to be before they are considered assassinated instead of just murdered?",
"Why does a round pizza come in a square box?",
"If ignorance is bliss, why aren?t more people happy?",
"Isn't it scary that the word 'therapist' is the same as the words 'the' and 'rapist' put together?",
"When pigs fart, does it smell like bacon?",
"Do you need a silencer if you are going to shoot a mime?",
"Do infants enjoy infancy as much as adults enjoy adultery?",
"If olive oil comes from olives, where does baby oil come from?",
"If one synchronized swimmer drowns, do the rest have to drown too?",
"If you spend your day doing nothing, how do you know when you're done?",
"Support bacteria - they're the only culture some people have.",
"I bought some powdered water, but I don't know what to add to it.",
"Did you know that coconuts kill more people than shark attacks?",
"Beer is made by fermentation cause by bacteria feeding on yeast cells and then defecating. In other words, it's a nice tall glass of bacteria doo-doo.",
"Researchers in Denmark found that beer tastes best when drunk to the accompaniment of a certain musical tone. The optimal frequency is different for each beer, they reported. The correct harmonious tone for Carlsberg Lager, for example, is 510-520 cycles per second.",
"if a fly lost its wings, would it be called a walk?",
"The future is like a baboons ass: Colourful and full of shit.",
"All generalizations are bad.",
"It's Prttey fnuny how we can raed tihs einrte snetnece wtih all tehse ltters all out of palce, and we can cnotniue to keep raednig and sitll mekas snece of waht we are raeding. No mttar how mnay tmies you raed tihs oevr and oevr you can sitll mkae snece of it.",
"War is god's method of teaching americans Geography",
"PA?Researchers at the University of Temple announced yesterday that they had finally discovered a cure for nicotine addicts: smoking cigarettes. 'The only way to effectively fight the cravings associated with the highly-addictive drug, nicotine, is to give your body its supply of desired nicotine, via smoking another cigarette. Smoking allows the nicotine found in cigarettes to travel to your brain in just seven seconds, effectively satisfying the craving.'",
"They say if you play a Microsoft CD backwards, you hear satanic messages. Thats nothing, cause if you play it forwards, it installs Windows.",
"Science can be confusing, for example, If you mix Blue and Yellow , do you call it Blellow or Yellue?",
"Communism is like Spandex. Good idea, but then real people started using it. Things got real ugly from there.",
"I saw a funeral hearse with 'BBL' on the reg plate today. It was funny in a macabre sort of way.",
"Never argue with an idiot. They drag you down to their level, then beat you with experience.",
"The general rule on about people chatting online seems to be 'Attractive, single, mentally stable: choose two'",
"In a perfect world... spammers would get caught, go to jail, and share a cell with many men who have enlarged their penisses, taken Viagra and are looking for a new relationship.",

}
SendToAll(Bot, "The Guru says '" ..Wisewords[math.random(table.getn(Wisewords))].. "'") --//Choose random in Wisewords Table
end

--//For Father Jack
function FatherJack(curUser)
Jack = {
"GOBSHITE!",
"DRINK!",
"ARSE!",
"GURLS!",
"DRINK!!!",
"FECK!",
"That would be an eccumenical question.",
"YES!",
}
SendToAll("FatherJack", "" ..Jack[math.random(table.getn(Jack))].. "" ) --//Choose random in Jack Table , notice it will post as FatherJack
end


Title:
Post by: Madman on 21 September, 2005, 10:33:41
if string.sub(data, 1, 1) == "<" then

That linte is not needed anymore.... =)
Script looks good... =)