PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Reefa on 22 March, 2005, 02:30:14

Title: Info bot no longer works...
Post by: Reefa on 22 March, 2005, 02:30:14
Hi peeps,

We had a small 'info bot' in our hub which worked fine before changing over to the new ptoka and robo, it was converted to lua5 but it doesn't seem to work anymore...

Can anyone shed any light on the matter?

Quotebotname = "-=Info-Bot=-"
bot_descr = "? Type !goactive and !forbidden ?"
bot_speed = "Sonic"
bot_email = "hiphophub@hotmail.com"
bot_share_size = 0

my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..string.char( 1 ).."$"..bot_email

v1 = "Information"

file1 = "info/active_info.txt"
file2 = "info/forbidden.txt"
file3 = "info/cleaner_help.txt"
file4 = "info/bantime.txt"

function Main()
frmHub:RegBot(botname)
my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..string.char( 1 ).."$"..bot_email.."$"..bot_share_size.."$"
SendToAll( my_info_string )
end

function DataArrival(user, data)
if (string.sub(data, 1, 1) == "<" ) then
data=string.sub(data,1,string.len(data)-1)
_,_,cmd=string.find(data, "%b<>%s+(%S+)")

if (cmd=="!goactive") then
ReadGoActive(user, data, cmd)
return 1
elseif (cmd=="!forbidden") then
ReadForbidText(user, data, cmd)
return 1
elseif user.bOperator then
if (cmd=="!cleaner") then
ReadCleanerHelp(user, data, cmd)
return 1
elseif (cmd=="!time") then
ReadBanTime(user, data, cmd)
return 1
end
end
end
end

--------------------------------------------------------------------------
function ReadGoActive(user, data, cmd)
local release = ""
readfrom(file1)
while 1 do

if (line == nil) then
break
else
release = release..""..line.."\r\n"
end
end
user:SendPM(botname, "\r\n\r\n"..release)
readfrom()
end
--------------------------------------------------------------------------
function ReadForbidText(user, data, cmd)
local release = ""
readfrom(file2)
while 1 do

if (line == nil) then
break
else
release = release..""..line.."\r\n"
end
end
user:SendPM(botname, "\r\n\r\n"..release)
readfrom()
end
--------------------------------------------------------------------------
function ReadCleanerHelp(user, data, cmd)
local release = ""
readfrom(file3)
while 1 do

if (line == nil) then
break
else
release = release..""..line.."\r\n"
end
end
user:SendPM(botname, "\r\n\r\n"..release)
readfrom()
end
--------------------------------------------------------------------------
function ReadBanTime(user, data, cmd)
local release = ""
readfrom(file4)
while 1 do

if (line == nil) then
break
else
release = release..""..line.."\r\n"
end
end
user:SendPM(botname, "\r\n\r\n"..release)
readfrom()
end

Many thanks!
Title:
Post by: Herodes on 22 March, 2005, 02:57:50
try this.. --- conv to Lua5 by Herodes

botname = "-=Info-Bot=-"
bot_descr = "Type !goactive and !forbidden"
bot_email = "hiphophub@hotmail.com"

function Main()
frmHub:RegBot(botname, 1, bot_descr, bot_email)
end

function ChatArrival(user, data)
local _,_,cmd=string.find(data, "%b<>%s+(%S+)|")
if (cmd=="!goactive") then
user:SendPM(botname, ReadFile("info/active_info.txt"))
return 1
elseif (cmd=="!forbidden") then
user:SendPM(botname, ReadFile( "info/forbidden.txt"))
return 1
elseif user.bOperator then
if (cmd=="!cleaner") then
user:SendPM(botname, ReadFile( "info/cleaner_help.txt"))
return 1
elseif (cmd=="!time") then
SendToAll(botname, ReadFile( "time.txt"))
return 1
end
end
end

function ReadFile(filename)
local file, msg = io.open(filename, "r"), ""
if file then
for line in file:lines() do msg = msg..line.."\n" end
file:close()
return msg
else
return filename.." doesnt exist"
end
end
[*edit*] My friends tell I should shoot scripts at night ...
[*edit*] My friends dont know that I need to be 35% wake to script...
[*edit*] My friends worry no more .. those bugs had nothing to do with my bed...
Title:
Post by: jiten on 22 March, 2005, 09:24:56
Herodes, shouldn't it be:

function DataArrival(user, data)
replaced with this:

function ChatArrival(user, data)
so, all the code would be like this:

--- conv to Lua5 by Herodes

botname = "-=Info-Bot=-"
bot_descr = "? Type !goactive and !forbidden ?"
bot_email = "hiphophub@hotmail.com"

function Main()
frmHub:RegBot(botname, 1, bot_descr, bot_email)
end

function ChatArrival(user, data)
if (string.sub(data, 1, 1) == "<" ) then
data=string.sub(data,1,string.len(data)-1)
_,_,cmd=string.find(data, "%b<>%s+(%S+)")

if (cmd=="!goactive") then
ReadFile("info/active_info.txt")
return 1
elseif (cmd=="!forbidden") then
ReadFile( "info/forbidden.txt")
return 1
elseif user.bOperator then
if (cmd=="!cleaner") then
ReadFile( "info/cleaner_help.txt")
return 1
elseif (cmd=="!time") then
ReadFile( "info/bantime.txt")
return 1
end
end
end
end

function ReadFile(filename)
local msg = ""
io.input(filename)
for line in io:lines() do
msg = msg..line.."\n"
end
io.input()
return msg
end


Best regards.
Title:
Post by: bastya_elvtars on 22 March, 2005, 09:46:51
Yes, and the red lines should be removed.

[color=#FF0000]if (string.sub(data, 1, 1) == "<" ) then[/color]
data=string.sub(data,1,string.len(data)-1)
_,_,cmd=string.find(data, "%b<>%s+(%S+)")
if (cmd=="!goactive") then
ReadFile("info/active_info.txt")
return 1
elseif (cmd=="!forbidden") then
ReadFile( "info/forbidden.txt")
return 1
elseif user.bOperator then
if (cmd=="!cleaner") then
ReadFile( "info/cleaner_help.txt")
return 1
elseif (cmd=="!time") then
ReadFile( "info/bantime.txt")
return 1
end
[color=#FF0000]end[/color]
end
Title:
Post by: Herodes on 22 March, 2005, 10:35:05
I apologised for the "shoot-out-a-script,before-go-to-bed" attitude I exempled last night :)

its okie now .. 1st post of mine edited ..
Thx a lot guys ..
(no wonder I woke up from a nightmare)
Title:
Post by: Reefa on 22 March, 2005, 12:06:29
Dayam, you guys are quick!

Just tried the script and no joy, still doesn't post the info.

I've scanned over it and everything seems to be in place so I'm not too sure why it's not working  ?(

Any ideas?
Title:
Post by: Herodes on 22 March, 2005, 17:08:28
QuoteOriginally posted by Reefa
Dayam, you guys are quick!

Just tried the script and no joy, still doesn't post the info.

I've scanned over it and everything seems to be in place so I'm not too sure why it's not working  ?(

Any ideas?
Yep .. saw it fixed it.. the ReadIt func was reading the file .. I hadnt told the script to send what it read to the user ... now its done.
1st post of mine on this updated ...
Title:
Post by: Reefa on 23 March, 2005, 02:13:44
Hehe! Still not enough sleep huh? ;)

Just tried it again and no luck, everyone was wondering why I was typing !forbidden so many times, and then !shit, !shit, !shit.

Have you managed to get it working with a test text file?
Title:
Post by: jiten on 23 March, 2005, 08:18:58
QuoteOriginally posted by Reefa
Hehe! Still not enough sleep huh? ;)

Just tried it again and no luck, everyone was wondering why I was typing !forbidden so many times, and then !shit, !shit, !shit.

Have you managed to get it working with a test text file?

Try this one:

--- conv to Lua5 by Herodes and debugged by jiten and bastya_elvtars

botname = "-=Info-Bot=-"
bot_descr = "? Type !goactive and !forbidden ?"
bot_email = "hiphophub@hotmail.com"

function Main()
frmHub:RegBot(botname, 1, bot_descr, bot_email)
end

function ChatArrival(user, data)
local data=string.sub(data,1,string.len(data)-1)
local _,_,cmd=string.find(data, "%b<>%s+(%S+)")
if (cmd=="!goactive") then
user:SendPM(botname, ReadFile("info/active_info.txt"))
return 1
elseif (cmd=="!forbidden") then
user:SendPM(botname, ReadFile( "info/forbidden.txt"))
return 1
elseif user.bOperator then
if (cmd=="!cleaner") then
user:SendPM(botname, ReadFile( "info/cleaner_help.txt"))
return 1
elseif (cmd=="!time") then
user:SendPM(botname, ReadFile( "info/bantime.txt"))
return 1
end
end
end

function ReadFile(filename)
local file = io.open(filename, "r") -- "r" read
local msg = ""
for line in file:lines() do
msg = msg..line.."\n"
end
file:close()
return msg
end



Best regards,

jiten
Title:
Post by: Herodes on 23 March, 2005, 08:53:31
done .. cooked and tasted .. sry for the delays .. everyting was caused be an overlooked badly written string.find ...
my 1st post on this updated once more ..
Title:
Post by: Reefa on 24 March, 2005, 12:59:26
Thanks for all your help guys, it works fine now!!!  :]
Title:
Post by: jiten on 24 March, 2005, 14:42:39
yw m8 :]