PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Whipshock on 11 November, 2003, 22:56:26

Title: Request Bot modifications
Post by: Whipshock on 11 November, 2003, 22:56:26
hello i have a request script here... and i would like

- to have it private message newly connecting users with the LAST 5 requests that were added to the list

- to know how i can change the script to accept commands sent to the main chat, rather than only private message

if someone could help me rework the code and outline what i need to change i would be extremely grateful!
thanks in advance :)


--//Request Board Bot
--//(Mr420)
--//A Simple Request Board For The Hub
--//Version 3.0

botname = "RequestBot?"
bot_email = ""
bot_speed = "Who knows?"
bot_descr = "Request Bot"
bot_share_size = 0
my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email


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

end

function NewUserConnected(curUser)
curUser:SendData( my_info_string )
end

function OpConnected(curUser)
curUser:SendData( my_info_string )
end

function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end

function GetArgs(data)
s,e,whoTo,from,cmd,arg,arg2 = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
return arg,arg2
end

function DataArrival(user, data)
if(strsub(data, 1, 4) == "$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == botname) then
s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")

if (cmd=="!newrequest") then
arg= GetArgs(data)
SendToAll("***New Request Available: "..arg.." (submitted by: "..user.sName..")")
local handle=openfile("request.dat","a")
write(handle,"("..user.sName..") added :"..arg.."?")
user:SendPM(botname,"New request has been added!")
closefile(handle)
end

if (cmd=="!view") then
handle2=openfile("request.dat","r")
if (handle2==nil) then
else
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(botname,linearray[i])
end
closefile(handle2)
end

end
end
end
end


Title:
Post by: kepp on 11 November, 2003, 23:15:51
--//Request Board Bot
--//(Mr420)
--//A Simple Request Board For The Hub
--//Version 3.0

botname = "RequestBot?"
bot_email = ""
bot_speed = "Who knows?"
bot_descr = "Request Bot"
bot_share_size = 0
my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email


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

end

function NewUserConnected(curUser)
curUser:SendData( my_info_string )
end

function OpConnected(curUser)
curUser:SendData( my_info_string )
end

function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end

function GetArgs(data)
s,e,whoTo,from,cmd,arg,arg2 = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
return arg,arg2
end

function DataArrival(user, data)
if(strsub(data, 1, 4) == "$To:") or strsub(data,1,1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == botname) then
s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")

if (cmd=="!newrequest") then
arg= GetArgs(data)
SendToAll("***New Request Available: "..arg.." (submitted by: "..user.sName..")")
local handle=openfile("request.dat","a")
write(handle,"("..user.sName..") added :"..arg.."?")
user:SendPM(botname,"New request has been added!")
closefile(handle)
end

elseif (cmd=="!view") then
handle2=openfile("request.dat","r")
if (handle2==nil) then
else
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(botname,linearray[i])
end
closefile(handle2)
end

end
end
end
end

Title:
Post by: Whipshock on 12 November, 2003, 01:11:28
kepp >> um.. did you not change anything lol or can i just not see it?
Title:
Post by: Whipshock on 17 November, 2003, 07:25:59
can anyone help me with what im trying to do here?

accept triggers from main chat and/or PM's
and show the last 5 requests only, rather than all ?
Title:
Post by: kepp on 17 November, 2003, 10:22:00
if strsub(data,1,4) == "$To:") or strsub(data,1,1) == "<")
I don't know if it works but you should be able to send it in mainchat now aswell
Title:
Post by: plop on 17 November, 2003, 14:38:07
QuoteOriginally posted by Whipshock
can anyone help me with what im trying to do here?

accept triggers from main chat and/or PM's
and show the last 5 requests only, rather than all ?
try this 1, haven't tested it so i hope it works.
should do all you requested.
--//Request Board Bot
--//(Mr420)
--//A Simple Request Board For The Hub
--//added support for commands send in mainchat (hope it works, not tested) by plop
--//should show the last 5 requests on entry (yes not tested) by plop
--//fixed error if no arguments are given on !newrequest by plop
--//Version 3.1

botname = "RequestBot?"
bot_email = ""
bot_speed = "Who knows?"
bot_descr = "Request Bot"
bot_share_size = 0
my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email


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

function NewUserConnected(curUser)
   curUser:SendData( my_info_string )
   Welcome(curUser)
end

function OpConnected(curUser)
   curUser:SendData( my_info_string )
   Welcome(curUser)
end

function tokenize (inString,token)
   _WORDS = {}
   local matcher = "([^?"..token.."]+)"
   gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
   return _WORDS
end

function DataArrival(user, data)
   if(strsub(data, 1, 4) == "$To:") then
      data=strsub(data,1,strlen(data)-1)
      s,e,whoTo = strfind(data,"$To:%s+(%S+)")
      if (whoTo == botname) then
         s,e,data = strfind(data, "$(%b<>.+)") -- converting PM data 2 be the same as mainchat
         Commands(curUser, data)
      end
   elseif strsub(data,1,1) == "<" then
      data=strsub(data,1,strlen(data)-1)
      Commands(curUser, data)
   end
end

function Commands(curUser, data)
   s,e,cmd = strfind(data,"%b<>%s+(%S+)")
   if (cmd=="!newrequest") then
      s,e,arg = strfind(data, "%b<>%s+%S+%s+(.+)")
      if arg ~= nil then
         SendToAll("***New Request Available: "..arg.." (submitted by: "..curUser.sName..")")
         local handle=openfile("request.dat","a")
         write(handle,"("..curUser.sName..") added :"..arg.."?")
         curUser:SendPM(botname,"New request has been added!")
         closefile(handle)
      else
         curUser:SendPM(botname,"How can i add a new request if you don't tell me what you want?")
      end
   elseif (cmd=="!view") then
      handle2=openfile("request.dat","r")
      if handle2~=nil then
         line = read(handle2,"*a")
         line=strsub(line,1,strlen(line)-1)
         linearray=tokenize(line,"?")
         for i=1,linearray.n do
            curUser:SendPM(botname,linearray[i])
         end
         closefile(handle2)
      end
   end
end

function Welcome(curUser)
   handle2=openfile("request.dat","r")
   if handle2~=nil then
      line = read(handle2,"*a")
      line=strsub(line,1,strlen(line)-1)
      linearray=tokenize(line,"?")
      for i=(linearray.n-5),linearray.n do
         curUser:SendPM(botname,linearray[i])
      end
      closefile(handle2)
   end
end

you were close kepp, just pm lines are different then mainchat.
what i done is alter the pm data 2 be the same as mainchat (that line has a comment).
had 2 change the rest a little bit so i could use the main chat way.

plop
Title:
Post by: kepp on 17 November, 2003, 15:48:43
Oh i see!! :)

I learn something new everyday!

I think it's time for tables :)

By the way plop, if you're not to busy, can you check out
My "Project" when im about done?
Just to comment my misstakes
Title:
Post by: plop on 17 November, 2003, 17:03:35
QuoteOriginally posted by kepp
Oh i see!! :)
I learn something new everyday!
I think it's time for tables :)
By the way plop, if you're not to busy, can you check out
My "Project" when im about done?
Just to comment my misstakes
done + a new excersize.
not tables, something else 1st.

plop
Title:
Post by: DarkElf on 18 November, 2003, 06:51:53
Hi, i have this RequestBoard....it run with 0.3.3.0 but he has a problem for !view command..


--//Request Board Bot
--//(Mr420)
--//A Simple Request Board For The Hub
--//Version 3.0

botname = "[?]YuNa?"
bot_email = "elfo0scuro@hotmail.com"
bot_speed = "GanjaLan(ThC)"
bot_descr = "Type #request In PM To Me."
bot_share_size = 420.01 * 1024 *1024 *1024
my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email
TimeSpanInMinutes = 120 --//You May Change This

function Main()
frmHub:RegBot(botname)
my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email..
"$"..bot_share_size.."$"
SetTimer(TimeSpanInMinutes*33000)
StartTimer()
end

function NewUserConnected(curUser)
curUser:SendData( my_info_string )
end

function OpConnected(curUser)
curUser:SendData( my_info_string )
end

function OnTimer()

--//Note that a "|" denotes a break in the line

SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
SendToAll("    HI THERE!!!!, I'm The Request_Board.")
SendToAll("    Do You Need A Specific File???")
SendToAll("    REQUEST IT!!!")
SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
SendToAll("  To Request A File, Simply Send #request As A Private Message")
SendToAll("  To [?]YuNa?.  Please Be As Specific As You Can.")
SendToAll("  Remember To Check Back To See If Someone Has Obtained Your File.")
SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")

end

function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end

function GetArgs(data)
s,e,whoTo,from,cmd,arg,arg2 = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
return arg,arg2
end

function DataArrival(user, data)
if(strsub(data, 1, 4) == "$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == botname) then
s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")

if (cmd=="#request") then
user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
user:SendPM(botname,"    This is the Request_Board!")
user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
user:SendPM(botname," Type #request To View This Help Menu.")
user:SendPM(botname," Type !request To Request A File.")
user:SendPM(botname," Type !view To View The Posted Requests/Updates.")
user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
user:SendPM(botname," Please Be As Specific As You Can.")
user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
end

if (cmd=="!request") then
SendToAll("***New Request Added***")
arg= GetArgs(data)
local handle=openfile("request.dat","a")
write(handle,"("..user.sName..") requested :"..arg.."?")
user:SendPM(botname,"Request entry saved ....")
closefile(handle)
end

if (cmd=="!view") then
handle2=openfile("request.dat","r")
if (handle2==nil) then
else
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(botname,linearray[i])
end
closefile(handle2)
end

end
end
end
end


I have a blank request.dat file, but ptokax say:

Syntax error: `for' limit must be a number
stack traceback:
   1:  function `DataArrival' at line 93 [file `....dbg\0.330.b15.18.dbg\scripts\RequestBot3.0.lua']
Title:
Post by: DarkElf on 18 November, 2003, 09:53:40
Anyone can help me??? :(
Title:
Post by: kepp on 18 November, 2003, 17:51:38
Did you make that file yourself?
Because the script will make one for you...
Title: hi
Post by: Janyn on 19 November, 2003, 09:10:09
DarkElf

that works fine i PtokaX DC Hub 0.3.2.4 IceCube III Fix3

// Janyn   :))
Title:
Post by: DarkElf on 19 November, 2003, 17:49:35
Kepp:

--//Request Board Bot
--//(Mr420)
--//A Simple Request Board For The Hub
--//Version 3.0


I have only canghed the name,e-mail etc..

Janyn:
LOL!!! i have 0.3.3.0 beta
Title:
Post by: kepp on 19 November, 2003, 18:01:07
May i suggest that you use elseif?
Title:
Post by: kepp on 19 November, 2003, 18:03:24
--//Request Board Bot
--//(Mr420)
--//A Simple Request Board For The Hub
--//Version 3.0

botname = "[?]YuNa?"
bot_email = "elfo0scuro@hotmail.com"
bot_speed = "GanjaLan(ThC)"
bot_descr = "Type #request In PM To Me."
bot_share_size = 420.01 * 1024 *1024 *1024
my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email
TimeSpanInMinutes = 120 --//You May Change This

function Main()
frmHub:RegBot(botname)
my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email..
"$"..bot_share_size.."$"
SetTimer(TimeSpanInMinutes*33000)
StartTimer()
end

function NewUserConnected(curUser)
curUser:SendData( my_info_string )
end

function OpConnected(curUser)
curUser:SendData( my_info_string )
end

function OnTimer()

--//Note that a "|" denotes a break in the line

SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
SendToAll("    HI THERE!!!!, I'm The Request_Board.")
SendToAll("    Do You Need A Specific File???")
SendToAll("    REQUEST IT!!!")
SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
SendToAll("  To Request A File, Simply Send #request As A Private Message")
SendToAll("  To [?]YuNa?.  Please Be As Specific As You Can.")
SendToAll("  Remember To Check Back To See If Someone Has Obtained Your File.")
SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")

end

function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end

function GetArgs(data)
s,e,whoTo,from,cmd,arg,arg2 = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
return arg,arg2
end

function DataArrival(user, data)
if(strsub(data, 1, 4) == "$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == botname) then
s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")

if (cmd=="#request") then
user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
user:SendPM(botname,"    This is the Request_Board!")
user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
user:SendPM(botname," Type #request To View This Help Menu.")
user:SendPM(botname," Type !request To Request A File.")
user:SendPM(botname," Type !view To View The Posted Requests/Updates.")
user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
user:SendPM(botname," Please Be As Specific As You Can.")
user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")


elseif (cmd=="!request") then
SendToAll("***New Request Added***")
arg= GetArgs(data)
local handle=openfile("request.dat","a")
write(handle,"("..user.sName..") requested :"..arg.."?")
user:SendPM(botname,"Request entry saved ....")
closefile(handle)


elseif (cmd=="!view") then
handle2=openfile("request.dat","r")
if (handle2==nil) then
else
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(botname,linearray[i])
end
closefile(handle2)
end

end
end
end
end
Title:
Post by: DarkElf on 19 November, 2003, 18:05:36
no, i have this bot in my hd, i have only change the name,e-mail,desc,tag and share
Title:
Post by: Whipshock on 25 November, 2003, 07:46:01
ahh thanks guys you are soo helpful!