PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: dvxjunkie on 20 October, 2003, 07:15:47

Title: RulesBot
Post by: dvxjunkie on 20 October, 2003, 07:15:47
with this little script the user can mistype the rules command in your hub and still recieve the hub rules.
I recommend entering you own  hub rules in this one :P

rulzbot by dvxjunkie

botname = "Rulezbot"
trigs = {["+rules"]=1,["!rules"]=2,["#rules"]=3}

function Main()
frmHub:RegBot(botname)
end


function DataArrival(Curuser, data)
 
if (( strsub(data, 1, 1) == "<" ) or ( strsub(data, 1, 4) == "$To:" )) then
for key,a in trigs do
if( strfind( strlower(data), strlower(key),1,1) ) then

 
Curuser:SendPM(botname, " Welcome to our hub and Thank you for checking the rules.  share all your personal home movies. give your social security number to ops upon entry and give us your first born child.")

end
end
end
end

 
Title:
Post by: pHaTTy on 20 October, 2003, 07:20:38
good but on the other hand you cud just use



Bot = "Keiko"


function DataArrival(user,data)
if strfind(data, "rules",1,1) then
readfrom("rules.txt")
while 1 do
line = read()
if line == nil then break end
user:SendData(Bot,line)
end
readfrom()
end
end


l8rr,,

-phatty
Title:
Post by: servaks on 20 October, 2003, 08:00:59
This one send rules in PM...


botname = "Rulesbot"

function Main()
frmHub:RegBot(botname)
end

function DataArrival(user,data)
if strfind(data, "rules",1,1) then
readfrom("rules.txt")
while 1 do
line = read()
if line == nil then break end
user:SendPM(botname,line)
end
readfrom()
end
end



/shipis
Title:
Post by: pHaTTy on 20 October, 2003, 08:13:07
lol no difference all done is changed the user:SendData to user:SendPM lol

might as well have just stated the line ;)

l8rr,,

-phatty
Title:
Post by: servaks on 20 October, 2003, 08:18:18
Yep...
But he is a NOOB, he maby dont know LUA  :D

/shipis
Title:
Post by: servaks on 20 October, 2003, 08:29:47

botname = "Rulesbot"
file = "rules.txt"
trigger = "rules"

function Main()
frmHub:RegBot(botname)
end

function DataArrival(user,data)
if strfind(data, trigger,1,1) then
readfrom(file)
while 1 do
line = read()
if line == nil then break end
user:SendPM(botname,line)
end
readfrom()
end
end


Title:
Post by: Skrollster on 20 October, 2003, 08:46:33
i have to say

1.
if strfind(data, "rules",1,1) then

can make life hard to regulars in the hub

if they say any thing with rules in it they will get the rules.

2.

why do you use 'while' here??

if you use while you need to use 'break' as well

suggestion:

sBotName = "Rulesbot"
sRulesFileName = "rules.txt"

function Main()
frmHub:RegBot(sBotName)
end

function DataArrival(user,data)
-- remove end pipe
data=strsub(data,1,strlen(data)-1)
--extract command
_,_,cmd=strfind(data, "%b<>%s+(%S+)")
--check if cmd exist
if not cmd then cmd = "0" end
-- make the cmd caseinsensitive
cmd = strlower(cmd)

if cmd = "!rules" then
readfrom(sRulesFileName)
local sLine = read()
local sFileContent = ""
if sLine then
sFileContent = sLine
while 1 do
sLine = read()
if not sLine then
break
else
sFileContent = sFileContent..sLine.."\r\n"
end
end
readfrom() -- close filehandle
user:SendPM(sBotName,sFileContent)
return 1
else
user:SendPM(sBotName,"Nothing in \"rules.txt\" or no \"rules.txt\"")
return 1
end
readfrom()
end
end

*edit*
there might also be an idea to check if it realy is a chat message first before doing any thing else
Title:
Post by: servaks on 20 October, 2003, 09:04:26
Nice one...

/shipis
Title:
Post by: Skrollster on 20 October, 2003, 09:15:27
ok an even better solution would be this:

sBotName = "Rulesbot"
sRulesFileName = "rules.txt"

function Main()
frmHub:RegBot(sBotName)
end

function DataArrival(user,data)
if (strsub(data, 1, 1) == "<" ) then
-- remove end pipe
data=strsub(data,1,strlen(data)-1)
--extract command
_,_,cmd=strfind(data, "%b<>%s+(%S+)")
--check if cmd exist
if not cmd then cmd = "0" end
-- make the cmd caseinsensitive
cmd = strlower(cmd)

if cmd = "!rules" then
fFileHandle, sError = readfrom(sRulesFileName)
local sLine = read()
local sFileContent = ""
if sLine then
sFileContent = sLine
while 1 do
sLine = read()
if not sLine then
break
else
sFileContent = sFileContent..sLine.."\r\n"
end
end
readfrom() -- close filehandle
user:SendPM(sBotName,sFileContent)
return 1
elseif fFileHandle
user:SendPM(sBotName,"Nothing found in "..sRulesFileName)
return 1
else
user:SendPM(sBotName,"Error "..sError)
end
readfrom()
end
end
end
Title:
Post by: MrZ on 20 October, 2003, 12:59:35
Hia :))

Nice script and nice to have ya back too Skrollster :))

Any shance we have nback the nice trad about Glory ??

Z ya
Title:
Post by: Skrollster on 20 October, 2003, 13:12:58
glory isn't any priority right now, at least not for me..

but i can start a new thread and release a beta of 1.9 i want to implement a few other things before the final 1.9 release, but if ppl want bug fixes for 1.8.3 then it can be aranged
Title:
Post by: c h i l l a on 20 October, 2003, 13:13:06
why not use this instead of read from line.

local handle = openfile(sRulesFileName, "r")
if handle then
local contents = gsub(read(handle, "*a"), strchar(10), "\r\n")
closefile (handle)
user:SendPM(sBotName,contents)
end
Title:
Post by: Skrollster on 20 October, 2003, 13:49:50
because i didn't remember the exact syntax for read all
read("*a")...
Title:
Post by: pHaTTy on 20 October, 2003, 16:33:12
rules, if you read back up we were talkinfg about if they mistype rules ;)
Title:
Post by: servaks on 20 October, 2003, 16:55:46
nice scripts :)
/shipis
Title:
Post by: pHaTTy on 20 October, 2003, 16:58:18
yep yep still nice script skrollker :o)
Title:
Post by: Skrollster on 21 October, 2003, 21:29:21
QuoteOriginally posted by (uk-kingdom)pH?tt?
rules, if you read back up we were talkinfg about if they mistype rules ;)

sorry missed that part, here you go:

sBotName = "Rulesbot"
sRulesFileName = "rules.txt"

function Main()
frmHub:RegBot(sBotName)
end

function DataArrival(user,data)
if (strsub(data, 1, 1) == "<" ) then
-- remove end pipe
data=strsub(data,1,strlen(data)-1)
--extract command
_,_,cmd=strfind(data, "%b<>%s+(%S+)")
--check if cmd exist
if not cmd then cmd = "0" end
-- make the cmd caseinsensitive
cmd = strlower(cmd)
-- get the command prefix
cmdprefix = strsub(cmd, 1,1)
-- check if the cmd prefix is !,+,# or ?
if cmdprefix == "!" or cmdprefix == "+" or cmdprefix == "#" or cmdprefix == "?" then
-- Remove the prefix and check the command
cmd = strsub(cmd, 2,strlen(cmd))
if cmd = "rules" then
fFileHandle, sError = readfrom(sRulesFileName)
local sLine = read()
local sFileContent = ""
if sLine then
sFileContent = sLine
while 1 do
sLine = read()
if not sLine then
break
else
sFileContent = sFileContent..sLine.."\r\n"
end
end
readfrom() -- close filehandle
user:SendPM(sBotName,sFileContent)
return 1
elseif fFileHandle
user:SendPM(sBotName,"Nothing found in "..sRulesFileName)
return 1
else
user:SendPM(sBotName,"Error "..sError)
end
readfrom()
end
end
end
end

i haven't tested it and not 100% sure about the strlen()
but i think it should work
Title:
Post by: pHaTTy on 22 October, 2003, 05:57:51
hehehe thats great ;)
Title: forgive
Post by: Mulciber on 04 November, 2003, 15:44:33
forgive the n00b, I just started to get in to this scripting tonight. Is there any way to insert this script (barrowed from servaks) in to Channel_Bot 4.3? I changed it a little to suit my needs, which is a configureable help file.

trigger = "?help"
helper = "helper.txt"

function HelpRequest(user,data)
if strfind(data, trigger,1,1) then
readfrom(helper)
while 1 do
line = read()
if line == nil then break end
user:SendPM(botname,line)
end
readfrom()
end
end
Title:
Post by: dvxjunkie on 31 December, 2003, 00:26:27
Nice goin skrollster I've been away but as I read thru the thread i was waiting for somone to notice that part about the mistyping thing. (prefix) I like the additional common prefix's you added too as well as the case insensitivity thing :)
  I was wondering though, why the change? is there  an efficiency issue the way i had it or possibly a memory waste I had going on there? Frankly I was already wondering if it might be more resouce intensive than it needed to be but I'm only so far in my lua journey.. :P

 
Title:
Post by: Snooze on 14 February, 2004, 16:45:44
When checking syntax on the script by Skrollster im getting this error

Syntax Error: `then' expected;
  last token read: `=' at line 24 in string "sBotName = "Rulesbot"
..."

No what am i doing wrong

Please advice..

/Snooze