PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: mmx on 11 December, 2003, 18:13:48

Title: simple # command
Post by: mmx on 11 December, 2003, 18:13:48
hi

i just would like to get/have/ simple script code that would let someone who was in my hub or me even to type say "#help" and then then it to load text stored in a text file say "help.txt" can anyone help me out here?

thankyou
Title:
Post by: mmx on 11 December, 2003, 19:50:11
please can i get a little help? it would be really really appreciated. from the likes of phatty etc

thankyou!
Title:
Post by: IceCoder on 11 December, 2003, 20:09:47
here is a script


sBotName = "HELP-O-BOT"
sRulesFileName = "help.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 = "help" 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
Title:
Post by: mmx on 11 December, 2003, 20:31:39
Syntax Error: `then' expected;
  last token read: `=' at line 24 in string "sBotName = "HELP-O-BOT"
..."
Title:
Post by: plop on 11 December, 2003, 21:08:37
change this
 if cmd = "help" then
for this
 if cmd == "help" then


plop
Title:
Post by: mmx on 11 December, 2003, 21:31:51
Syntax Error: `then' expected;
  last token read: `user' at line 42 in string "sBotName = "hbot"
..."
Title:
Post by: mmx on 11 December, 2003, 21:37:20
sBotName = "hbot"
sRulesFileName = "help.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 == "help" 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

------------------------------------------------------
Syntax Error: `then' expected;
  last token read: `user' at line 42 in string "sBotName = "hbot"
..."
Title:
Post by: mmx on 11 December, 2003, 21:41:03
didn't u test this?

all i want is to type #help

and get help.txt to open

in a PM window to who ever types it.


-------------------------------------------------------
 i didn't think it would be OTT considering some of the scripts u see on the forum.

as always thankyou v.much appreciated
Title:
Post by: IceCoder on 11 December, 2003, 22:05:11
Damn :/
Title:
Post by: mmx on 11 December, 2003, 22:37:28
lol i got it to be fixed. sigh your soo useless. joke  :rolleyes:
Title:
Post by: mmx on 11 December, 2003, 22:38:49
sBotName = "hbot"
sRulesFileName = "help.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 == "help" 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 then
user:SendPM(sBotName,"Nothing found in "..sRulesFileName)
return 1
else
user:SendPM(sBotName,"Error "..sError)
end
readfrom()
end
end
end
end


----------------------------
and it works!!! - all i want now is to get it to open up in a Pm window :P
Title:
Post by: IceCoder on 11 December, 2003, 22:47:18
haha it is in a window "SendPM"
Title:
Post by: mmx on 11 December, 2003, 23:05:29
it does i'm so stupid
Title:
Post by: mmx on 11 December, 2003, 23:19:19
and ideas on how to get it to do another command like #network without having to write the same code time and time again?

cheers.
Title:
Post by: mmx on 11 December, 2003, 23:41:29
Bot = "Helper"

textArray = {}
QWarray = {}
antall = 0


function Main()

frmHub:RegBot(Bot)
loadText()
getLine()
end

function OnTimer()
getLine()
end

-- Triggers

TriggerPrivate = {
- ["+newbie"]="newbie.txt",
- ["+rules"]="rules.txt",
}

function DataArrival(curUser, sData)

if( strsub(sData, 1, 1) == "<" ) then
-- get the msg only using regular expression
s,e,msg = strfind(sData, "%b<> ([ -z]*)")
if (msg == "+rules") then
local text1 = ""
readfrom("rules.txt.txt")
while 1 do
local line = read()
if (line == nil) then
break
else
text1 = text1..line.."\r\n"
end
end
readfrom()
local text2 = ""
readfrom("newbie.txt")
while 1 do
local line = read()
if (line == nil) then
break
else
text2 = text2..line.."\r\n"
end
end
readfrom()

end
end
if( strsub(sData, 1, 1) == "<" ) or ( strsub(sData, 1, 4) == "$To:") then
s,e,msg = strfind(sData, "%b<> ([ -z]*)")
for key, value in TriggerPrivate do
if( strfind( strlower(msg), key) ) then
answer, x = gsub(value, "%b[]", curUser.sName)
local text = ""
readfrom(answer)
while 1 do
local line = read()
if (line == nil) then
break
else
text = text..line.."\r\n"
end
end
SendPmToNick(curUser.sName, Bot, text)

end
readfrom()
end

Syntax Error: `end' expected (to close `if' at line 68);
  last token read: `' at line 89 in string "-- Defines the name of the bot
..."

Bot = "Helper"


textArray = {}
QWarray = {}
antall = 0


function Main()

frmHub:RegBot(Bot)
loadText()
getLine()
end

function OnTimer()
getLine()
end

-- Triggers

TriggerPrivate = {
- ["+newbie"]="newbie.txt",
- ["+rules"]="rules.txt",
}

function DataArrival(curUser, sData)

if( strsub(sData, 1, 1) == "<" ) then
-- get the msg only using regular expression
s,e,msg = strfind(sData, "%b<> ([ -z]*)")
if (msg == "+rules") then
local text1 = ""
readfrom("rules.txt.txt")
while 1 do
local line = read()
if (line == nil) then
break
else
text1 = text1..line.."\r\n"
end
end
readfrom()
local text2 = ""
readfrom("newbie.txt")
while 1 do
local line = read()
if (line == nil) then
break
else
text2 = text2..line.."\r\n"
end
end
readfrom()

end
end
if( strsub(sData, 1, 1) == "<" ) or ( strsub(sData, 1, 4) == "$To:") then
s,e,msg = strfind(sData, "%b<> ([ -z]*)")
for key, value in TriggerPrivate do
if( strfind( strlower(msg), key) ) then
answer, x = gsub(value, "%b[]", curUser.sName)
local text = ""
readfrom(answer)
while 1 do
local line = read()
if (line == nil) then
break
else
text = text..line.."\r\n"
end
end
SendPmToNick(curUser.sName, Bot, text)

end
readfrom()
end

Syntax Error: `end' expected (to close `if' at line 68);
  last token read: `' at line 89 in string "-- Defines the name of the bot
..."
Title:
Post by: mmx on 11 December, 2003, 23:43:02
can u help me fix that?

thanx to sha_dow
Title:
Post by: plop on 12 December, 2003, 00:35:45
rewriten the whole thing.
make a folder named text, place in that all text files you want this bot 2 be able 2 show.
if the file is called rules.txt you can trigger it with !rules/+rules/#rules/Arules.
doesn't mather what prefix a user uses as long as it's 1 character and the file excists it works.
-- texter bot by plop
-- shows text files from a folder named text.
-- doesn't mather what prefix it used.
-- if the file excist it shows.

Bot = "something"

function Main()
   frmHub:RegBot(Bot)
end

function DataArrival(user, data)
   data=strsub(data,1,strlen(data)-1)
   if( strsub(data, 1, 1) == "<" ) then
      s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      cmd = strsub(cmd, 2,strlen(cmd))
      if readfrom("text/"..cmd..".txt") then
         showtext(user, cmd)
         return 1
      end
   elseif(strsub(data, 1, 4) == "$To:") then
      s,e,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
      cmd = strsub(cmd, 2,strlen(cmd))
      if readfrom("text/"..cmd..".txt") then
         showtext(user, cmd)
         return 1
      end
   end
end


function showtext(user, cmd)
   lines = "\r\n\r\n"
   readfrom("text/"..cmd..".txt")
   while 1 do
      local line = read()
      if line == nil then
         readfrom()
         break
      end
      lines = lines..line.."\r\n"
   end
   user:SendPM(Bot, lines.." |")
end
plop
Title:
Post by: pHaTTy on 12 December, 2003, 00:56:11
on the other hand you cud have went to this thread

i wrote a long time ago............


http://board.univ-angers.fr/thread.php?threadid=46&boardid=12&styleid=1&sid=6fac38ac3b3103906d8ee71e4ec1b27c (http://board.univ-angers.fr/thread.php?threadid=46&boardid=12&styleid=1&sid=6fac38ac3b3103906d8ee71e4ec1b27c)

l8rr,,

-phatty
Title:
Post by: plop on 12 December, 2003, 01:19:52
QuoteOriginally posted by (uk-kingdom)pH?tt?
on the other hand you cud have went to this thread

i wrote a long time ago............


http://board.univ-angers.fr/thread.php?threadid=46&boardid=12&styleid=1&sid=6fac38ac3b3103906d8ee71e4ec1b27c (http://board.univ-angers.fr/thread.php?threadid=46&boardid=12&styleid=1&sid=6fac38ac3b3103906d8ee71e4ec1b27c)

l8rr,,

-phatty
lol would have been a way easyer thing indeed.
next time pls tell me before i write something.  lol

plop
Title:
Post by: pHaTTy on 12 December, 2003, 01:21:09
lol oooops  8o
Title:
Post by: mmx on 12 December, 2003, 12:17:11
cheers PLOP (what a name).
Title:
Post by: mmx on 12 December, 2003, 12:20:14
thanx to phatty. only thing about ur bots though there OTT they always have to go the extra mile and i preferr the simpl'er version by plop . . . like the black listing thing.
Title:
Post by: IceCoder on 12 December, 2003, 12:39:19
i can post a script later
Title:
Post by: plop on 12 December, 2003, 12:49:07
QuoteOriginally posted by mmx
cheers PLOP (what a name).
yw.
my name isn't so weird if you are from the netherlands (http://www.kabouterplop.nl) / belgium (http://www.studio100.be/plop/default.asp)

plop