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
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
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
lol no difference all done is changed the user:SendData to user:SendPM lol
might as well have just stated the line ;)
l8rr,,
-phatty
Yep...
But he is a NOOB, he maby dont know LUA :D
/shipis
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
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
Nice one...
/shipis
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
Hia :))
Nice script and nice to have ya back too Skrollster :))
Any shance we have nback the nice trad about Glory ??
Z ya
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
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
because i didn't remember the exact syntax for read all
read("*a")...
rules, if you read back up we were talkinfg about if they mistype rules ;)
nice scripts :)
/shipis
yep yep still nice script skrollker :o)
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
hehehe thats great ;)
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
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
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