PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: gizmo on 08 February, 2004, 21:31:38

Title: error regbot
Post by: gizmo on 08 February, 2004, 21:31:38
can someone please tell me wht this error mean when i drive this script =(


Syntax error: attempt to call field `AddRegUser' (a nil value)
stack traceback:
   1:  function `RegUser' at line 52 [file `...lone grejer1\Potax clone 4\scripts\regboten.lua']
   2:  function `DataArrival' at line 97 [file `...lone grejer1\Potax clone 4\scripts\regboten.lua


botname = "Regbot"
kb = 1024
mb = kb*kb
gb = kb*kb*kb
tb = kb*kb*kb*kb
pb = kb*kb*kb*kb*kb
bot_name = "Regbot"
bot_email = "here@hub"
bot_speed = "T3"
bot_descr = "[Imperial]"
bot_share_size = 0 * mb


function Main()
frmHub:RegBot(botname)
end

function NewUserConnected(curUser)
curUser:SendData( my_info_string )

end

function OpConnected(curUser)
curUser:SendData( my_info_string )

end

hubaddress="clone4.myftp.org"


-------------------------------------------------------------------------
--DO NOT EDIT BELOW THIS TEXT!
-------------------------------------------------------------------------

function Get1Arg(data)
s,e,cmd,arg = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )
return arg
end

function Get2Arg(data)
s,e,cmd,arg,arg2 = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s+(.+)" )
return arg, arg2
end

function RegUser(user,data)
Get1Arg(data)
if arg==nil then
user:SendPM(botname, "You have to provide a password!")
end
if not arg==nil then
if not user.bOperator then
frmHub:AddRegUser(user.sName, arg, "0")
user:SendPM(botname, "You are now registered at "..frmHub:GetHubName().."!")
user:SendPM(botname, "Add this hub to your favourites (if you haven?t done so already),")
user:SendPM(botname, "and be sure to write down your account-information and password:")
user:SendPM(botname, "HubName:\t"..frmHub:GetHubName().." Address:\t"..hubaddress.."")
user:SendPM(botname, "Your Nick:\t"..user.sName.."")
user:SendPM(botname, "Your Password:\t"..arg.."")
end
if user.bOperator then
user:SendPM(botname, "Feel the need to deop yourself? ;)")
user:SendPM(botname, "If you want to register a useraccount use < +newuser Name Pwd >")
end
end
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+)")
if not cmd==nil then
if (cmd=="+regme") then
user:SendPM(botname,"It is not wise to display your password in the mainchat!")
user:SendPM(botname,"Send a pm to me and try again. ")
return 1
end
if (cmd=="+reg") or (cmd=="+reghelp") then
user:SendPM(botname,"Yes! It?s true! Now you can register an account with us!")
user:SendPM(botname,"To register:")
user:SendPM(botname,"Send a pm to "..botname.." and type < +regme ThePasswordYouWant >. Done!")
end
end
end


if ( strsub(data, 1, 5) == "$To: " ) then
s,e,whoTo,from=strfind(data, "$To:%s+(%S+)%s+From:%s+(%S+)")
if whoTo==botname then
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if (cmd=="+reg") or (cmd=="+reghelp") then
user:SendPM(botname,"Yes! It?s true! Now you can register an account with us!")
user:SendPM(botname,"To register:")
user:SendPM(botname,"Send a pm to "..botname.." and type < +regme ThePasswordYouWant >. Done!")
end
if (cmd=="+regme") then
RegUser(user,data)
end
if user.bOperator then
if (cmd=="+reguser") then
Get2Arg(data)
frmHub:AddRegUser(arg,arg2,"0")
user:SendPM(botname, "As you wish my master!")
user:SendPM(botname, "The user "..arg.." with the password "..arg2.." is now")
user:SendPM(botname, "registered at "..frmHub:GetHubName().." / "..hubaddress.."")
end
end
end
end
end







Title:
Post by: nErBoS on 08 February, 2004, 22:13:15
Hi,

Try this..

botname = "Regbot"
kb = 1024
mb = kb*kb
gb = kb*kb*kb
tb = kb*kb*kb*kb
pb = kb*kb*kb*kb*kb
bot_name = "Regbot"
bot_email = "here@hub"
bot_speed = "T3"
bot_descr = "[Imperial]"
bot_share_size = 0 * mb


function Main()
frmHub:RegBot(botname)
end

function NewUserConnected(curUser)
curUser:SendData( my_info_string )

end

function OpConnected(curUser)
curUser:SendData( my_info_string )

end

hubaddress="clone4.myftp.org"


-------------------------------------------------------------------------
--DO NOT EDIT BELOW THIS TEXT!
-------------------------------------------------------------------------

function Get1Arg(data)
s,e,cmd,arg = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )
return arg
end

function Get2Arg(data)
s,e,cmd,arg,arg2 = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s+(.+)" )
return arg, arg2
end

function RegUser(user,data)
Get1Arg(data)
if arg==nil then
user:SendPM(botname, "You have to provide a password!")
end
if not arg==nil then
if not user.bOperator then
AddRegUser(user.sName, arg, "0") --edit
user:SendPM(botname, "You are now registered at "..frmHub:GetHubName().."!")
user:SendPM(botname, "Add this hub to your favourites (if you haven?t done so already),")
user:SendPM(botname, "and be sure to write down your account-information and password:")
user:SendPM(botname, "HubName:\t"..frmHub:GetHubName().." Address:\t"..hubaddress.."")
user:SendPM(botname, "Your Nick:\t"..user.sName.."")
user:SendPM(botname, "Your Password:\t"..arg.."")
end
if user.bOperator then
user:SendPM(botname, "Feel the need to deop yourself? ;)")
user:SendPM(botname, "If you want to register a useraccount use < +newuser Name Pwd >")
end
end
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+)")
if not cmd==nil then
if (cmd=="+regme") then
user:SendPM(botname,"It is not wise to display your password in the mainchat!")
user:SendPM(botname,"Send a pm to me and try again. ")
return 1
end
if (cmd=="+reg") or (cmd=="+reghelp") then
user:SendPM(botname,"Yes! It?s true! Now you can register an account with us!")
user:SendPM(botname,"To register:")
user:SendPM(botname,"Send a pm to "..botname.." and type < +regme ThePasswordYouWant >. Done!")
end
end
end


if ( strsub(data, 1, 5) == "$To: " ) then
s,e,whoTo,from=strfind(data, "$To:%s+(%S+)%s+From:%s+(%S+)")
if whoTo==botname then
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if (cmd=="+reg") or (cmd=="+reghelp") then
user:SendPM(botname,"Yes! It?s true! Now you can register an account with us!")
user:SendPM(botname,"To register:")
user:SendPM(botname,"Send a pm to "..botname.." and type < +regme ThePasswordYouWant >. Done!")
end
if (cmd=="+regme") then
RegUser(user,data)
end
if user.bOperator then
if (cmd=="+reguser") then
Get2Arg(data)
AddRegUser(arg,arg2,"0") --edit
user:SendPM(botname, "As you wish my master!")
user:SendPM(botname, "The user "..arg.." with the password "..arg2.." is now")
user:SendPM(botname, "registered at "..frmHub:GetHubName().." / "..hubaddress.."")
end
end
end
end
end

It works with me !!

Best regards, nErBoS
Title:
Post by: Snooze on 08 March, 2004, 19:27:47
Any chance of adding these commands to this script:


+userpassword
-diplays a regged users password.

+changeuserpassword
 changes a regged users password.
Title:
Post by: nErBoS on 08 March, 2004, 20:18:38
Hi,

Made only the changepass...

botname = "Regbot"
kb = 1024
mb = kb*kb
gb = kb*kb*kb
tb = kb*kb*kb*kb
pb = kb*kb*kb*kb*kb
bot_name = "Regbot"
bot_email = "here@hub"
bot_speed = "T3"
bot_descr = "[Imperial]"
bot_share_size = 0 * mb


function Main()
frmHub:RegBot(botname)
end

function NewUserConnected(curUser)
curUser:SendData( my_info_string )

end

function OpConnected(curUser)
curUser:SendData( my_info_string )

end

hubaddress="clone4.myftp.org"


-------------------------------------------------------------------------
--DO NOT EDIT BELOW THIS TEXT!
-------------------------------------------------------------------------

function Get1Arg(data)
s,e,cmd,arg = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )
return arg
end

function Get2Arg(data)
s,e,cmd,arg,arg2 = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s+(.+)" )
return arg, arg2
end

function ChangePass(user, data)
Get2Arg(data)
if (arg == nil or arg2 == nil) then
user:SendPM(botname, "Syntax error, +changeuserpassword , musdt have a nick and a new pass.")
else
if (DelRegUser(arg) == -1) then
user:SendPM(botname, "The user "..arg.." is not registerd in the Hub.")
else
DelRegUser(arg)
AddRegUser(arg, arg2, "0")
user:SendPM(botname, "The user "..arg.." has been register with a new pass: "..arg2)
end
end
end

function RegUser(user,data)
Get1Arg(data)
if arg==nil then
user:SendPM(botname, "You have to provide a password!")
end
if not arg==nil then
if not user.bOperator then
AddRegUser(user.sName, arg, "0") --edit
user:SendPM(botname, "You are now registered at "..frmHub:GetHubName().."!")
user:SendPM(botname, "Add this hub to your favourites (if you haven?t done so already),")
user:SendPM(botname, "and be sure to write down your account-information and password:")
user:SendPM(botname, "HubName:\t"..frmHub:GetHubName().." Address:\t"..hubaddress.."")
user:SendPM(botname, "Your Nick:\t"..user.sName.."")
user:SendPM(botname, "Your Password:\t"..arg.."")
end
if user.bOperator then
user:SendPM(botname, "Feel the need to deop yourself? ;)")
user:SendPM(botname, "If you want to register a useraccount use < +newuser Name Pwd >")
end
end
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+)")
if not cmd==nil then
if (cmd=="+regme") then
user:SendPM(botname,"It is not wise to display your password in the mainchat!")
user:SendPM(botname,"Send a pm to me and try again. ")
return 1
end
if (cmd=="+reg") or (cmd=="+reghelp") then
user:SendPM(botname,"Yes! It?s true! Now you can register an account with us!")
user:SendPM(botname,"To register:")
user:SendPM(botname,"Send a pm to "..botname.." and type < +regme ThePasswordYouWant >. Done!")
end
end
end


if ( strsub(data, 1, 5) == "$To: " ) then
s,e,whoTo,from=strfind(data, "$To:%s+(%S+)%s+From:%s+(%S+)")
if whoTo==botname then
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if (cmd=="+reg") or (cmd=="+reghelp") then
user:SendPM(botname,"Yes! It?s true! Now you can register an account with us!")
user:SendPM(botname,"To register:")
user:SendPM(botname,"Send a pm to "..botname.." and type < +regme ThePasswordYouWant >. Done!")
end
if (cmd=="+regme") then
RegUser(user,data)
end
if user.bOperator then
if (cmd=="+reguser") then
Get2Arg(data)
AddRegUser(arg,arg2,"0") --edit
user:SendPM(botname, "As you wish my master!")
user:SendPM(botname, "The user "..arg.." with the password "..arg2.." is now")
user:SendPM(botname, "registered at "..frmHub:GetHubName().." / "..hubaddress.."")
elseif (cmd=="+changeuserpassword") then
ChangePass(user, data)
end
end
end
end
end

Its no good to work with the RegisterUser.dat the only to have access to the pass should be the person who is runnig the hub.. if someone forget his pass just use the other command you have requested.

Best regards, nErBoS
Title:
Post by: Snooze on 09 March, 2004, 00:56:42
Thanks for the reply :)

Though, when i try to change the password of a user NOT regged in the hub, that username will be registered as a Master ?


Quoteif someone forget his pass just use the other command you have requested.

I cant seem to find that piece of code in your script ?

**Snooze

**EDIT**

Got it :) - Then just change the password.

Sorry ;)
Title:
Post by: Snooze on 09 March, 2004, 01:10:35
Oops !

More testing showed that all users that get their password changed will be "upgraded" to Masters ;)

How do we prevent that ?


**Snooze
Title:
Post by: Snooze on 09 March, 2004, 14:51:02
Hmm.. looks like i was too tired to read last night

AddRegUser(arg, arg2, "0")

As i understand it, all users who has their password changed will end up with status = "0"

What i should have asked is:

How do I make sure that the user will keep the current level ?

I hope you can help :)

**Snooze
Title:
Post by: plop on 09 March, 2004, 16:39:22
cleaned it up a lot and added +changepassword so every1 can change there own password.
hope the +changeuserpassword now also works for every level (unless the user 2 be changed has a higher level then the user trying 2 change it).
get ready for bug's, it's up 2 you 2 find them.
botname = "Regbot"
kb = 1024
mb = kb*kb
gb = kb*kb*kb
tb = kb*kb*kb*kb
pb = kb*kb*kb*kb*kb
bot_name = "Regbot"
bot_email = "here@hub"
bot_speed = "T3"
bot_descr = "[Imperial]"
bot_share_size = 0 * mb


function Main()
   frmHub:RegBot(botname)
end

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

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

hubaddress="clone4.myftp.org"


------------------------------------------------------------------------
--DO NOT EDIT BELOW THIS TEXT!
-------------------------------------------------------------------------

function Get1Arg(data)
   s,e,cmd,arg = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )
   return arg
end

function Get2Arg(data)
   s,e,cmd,arg,arg2 = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s+(.+)" )
   return arg, arg2
end

function GetProfileOffline(nick)
   ret = nil
   for a,b in GetProfiles() do
      for c,d in GetUsersByProfile(b) do
         if d == nick then
            ret = b
            break
         end
      end
   end
   return ret
end

function ChangePass(user, data)
   local arg, arg2 = Get2Arg(data)
   if (arg == nil or arg2 == nil) then
      user:SendPM(botname, "Syntax error, +changeuserpassword , must have a nick and a new pass.")
   else
      local tmp = GetProfileOffline(arg)
      if tmp == nil then
         user:SendPM(botname, "The user "..arg.." is not registerd in the Hub.")
      elseif tmp <= user.iProfile then
         user:SendPM(botname, "The user "..arg.." has the same or higher level then you.")
      else
         DelRegUser(arg)
         AddRegUser(arg, arg2, tmp)
         user:SendPM(botname, "The user "..arg.." has been register with a new pass: "..arg2)
      end
   end
end

function ChangeMyPass(user, data)
   if user.iProfile ~= -1 then
      local arg2 = Get1Arg(data)
      if arg2 ~= nil then
         DelRegUser(user.sName)
         AddRegUser(user.sName, arg2, user.iProfile)
         user:SendPM(botname, "The user "..arg.." has been register with a new pass: "..arg2)
      else
         user:SendPM(botname, "how about telling me the new password?|")
      end
   else
      user:SendPM(botname, "there is no password 2 change as you are not registered!|")
   end
end

function RegUser(user,data)
   local arg = Get1Arg(data)
   if arg==nil then
      user:SendPM(botname, "You have to provide a password!")
   end
   if arg ~= nil then
      if user.iProfile == -1 then
         AddRegUser(user.sName, arg, "3") --edit
         user:SendPM(botname, "You are now registered at "..frmHub:GetHubName().."!")
         user:SendPM(botname, "Add this hub to your favourites (if you haven?t done so already),")
         user:SendPM(botname, "and be sure to write down your account-information and password:")
         user:SendPM(botname, "HubName:\t"..frmHub:GetHubName().." Address:\t"..hubaddress.."")
         user:SendPM(botname, "Your Nick:\t"..user.sName.."")
         user:SendPM(botname, "Your Password:\t"..arg.."")
      else
         user:SendPM(botname, "why try 2 register yourself when you allready are? ;)")
         user:SendPM(botname, "If you want to register a useraccount use < +newuser Name Pwd >")
      end
   end
end


function DataArrival(user, data)
   data=strsub(data,1,strlen(data)-1)
   if ( strsub(data, 1, 1) == "<" ) then
      local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      if cmd ~= nil then
         if (cmd=="+regme") then
            user:SendPM(botname,"It is not wise to display your password in the mainchat!")
            user:SendPM(botname,"Send a pm to me and try again. ")
            return 1
         elseif (cmd=="+reg") or (cmd=="+reghelp") then
            user:SendPM(botname,"Yes! It?s true! Now you can register an account with us!")
            user:SendPM(botname,"To register:")
            user:SendPM(botname,"Send a pm to "..botname.." and type < +regme ThePasswordYouWant >. Done!")
            return 1
         end
      end
   elseif ( strsub(data, 1, 5) == "$To: " ) then
      local s,e,whoTo,from=strfind(data, "$To:%s+(%S+)%s+From:%s+(%S+)")
      if whoTo==botname then
         local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
         if (cmd=="+reg") or (cmd=="+reghelp") then
            user:SendPM(botname,"Yes! It?s true! Now you can register an account with us!")
            user:SendPM(botname,"To register:")
            user:SendPM(botname,"Send a pm to "..botname.." and type < +regme ThePasswordYouWant >. Done!")
         elseif (cmd=="+regme") then
            RegUser(user,data)
         elseif (cmd == "+changepassword") then
            ChangeMyPass(user, data)
         elseif user.bOperator then
            if (cmd=="+reguser") then
               local arg, arg2 =Get2Arg(data)
               AddRegUser(arg,arg2,"3") --edit
               user:SendPM(botname, "As you wish my master!")
               user:SendPM(botname, "The user "..arg.." with the password "..arg2.." is now")
               user:SendPM(botname, "registered at "..frmHub:GetHubName().." / "..hubaddress.."")
            elseif (cmd=="+changeuserpassword") then
               ChangePass(user, data)
            end
         end
      end
   end
end
plop

* edit forgot 2 say that you were adding all registered users with the level number 0.
on testdrive+ these are masters.
check the docs for more info.
Title:
Post by: nErBoS on 09 March, 2004, 16:46:39
Hi,

Well just make a conditons, something like this..

function ChangePass(user, data)
Get2Arg(data)
if (arg == nil or arg2 == nil) then
user:SendPM(botname, "Syntax error, +changeuserpassword , musdt have a nick and a new pass.")
else
if (DelRegUser(arg) == -1) then
user:SendPM(botname, "The user "..arg.." is not registerd in the Hub.")
else
local profile = GetUsersByProfile(GetProfileName(3)) ---To keep the user a REG
for i=1, getn(profile) do
if (ptofile[i] == arg) then
DelRegUser(arg)
AddRegUser(arg, arg2, "3")
user:SendPM(botname, "The user "..arg.." has been register with a new pass: "..arg2)
end
end
local profile2 = GetUsersByProfile(GetProfileName(2)) ---To keep the user a VIP
for i=1, getn(profile2) do
if (profile2[i] == arg) then
DelRegUser(arg)
AddRegUser(arg, arg2, "2")
user:SendPM(botname, "The user "..arg.." has been register with a new pass: "..arg2)
end
end
end
end
end

Best regards, nErBoS
Title:
Post by: Snooze on 10 March, 2004, 04:26:35
I can't make this part work..

if (DelRegUser(arg) == -1) then
user:SendPM(botname, "The user "..arg.." is not registerd in the Hub.")
else


I have it running like this:


function DelUser(user, data)
Get1Arg(data)
if (DelRegUser(arg) == -1) then
user:SendPM(botname, "The User "..arg.." is not registerd in the Hub.")
appendto(sOplog)
write("\r\n", "The non existing user "..arg.." was attempted deleted by: "..user.sName.." on "..GetTime())
writeto()
else
if (arg == nil) then
user:SendPM(Bot, "Syntax error, !deluser .")
else
DelRegUser(arg)
user:SendPM(Bot, "The User "..arg.." has been deleted. This action was added to log. ")
appendto(sOplog)
write("\r\n", "The User "..arg.." was deleted by: "..user.sName.." on "..GetTime())
writeto()
end
end
end

As i understand it should work just fine like that ???
Im not getting any errors, just the "The User "..arg.." has been deleted. This action was added to log. " msg...

Please help me out once again :-)


The newbie, Snooze :-)
Title:
Post by: nErBoS on 10 March, 2004, 05:17:25
Hi,

Better this way, frist check if arg is nil then see if the arg is registered or not.

function DelUser(user, data)
Get1Arg(data)
if (arg == nil) then
user:SendPM(Bot, "Syntax error, !deluser .")
else
if (DelRegUser(arg) == -1) then
user:SendPM(botname, "The User "..arg.." is not registerd in the Hub.")
appendto(sOplog)
write("\r\n", "The non existing user "..arg.." was attempted deleted by: "..user.sName.." on "..GetTime())
writeto()
else
DelRegUser(arg)
user:SendPM(Bot, "The User "..arg.." has been deleted. This action was added to log. ")
appendto(sOplog)
write("\r\n", "The User "..arg.." was deleted by: "..user.sName.." on "..GetTime())
writeto()
end
end
end

Best regards, nErBoS
Title:
Post by: Snooze on 10 March, 2004, 07:22:32
I must be missing some vital part of the script as it's still not doing the check :(


This is the code im using:

arg:
function Get1Arg(data)
s,e,cmd,arg = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )
return arg
end

function:

function DelUser(user, data)
Get1Arg(data)
if (arg == nil) then
user:SendPM(Bot, "Syntax error, !deleteuser .")
else
if (DelRegUser(arg) == -1) then
user:SendPM(botname, "The User "..arg.." is not registerd in the Hub.")
appendto(sOplog)
write("\r\n", "The non existing user "..arg.." was attempted deleted by: "..user.sName.." on "..GetTime())
writeto()
else
DelRegUser(arg)
user:SendPM(Bot, "The User "..arg.." has been deleted. This action was added to log. ")
appendto(sOplog)
write("\r\n", "The User "..arg.." was deleted by: "..user.sName.." on "..GetTime())
writeto()
end
end
end

I apologize for all my dumb questions, but i gotta learn somehow ...


**Snooze
Title:
Post by: nErBoS on 10 March, 2004, 18:26:38
Hi,

I have tested also and the functions is always returning 1, maybe a bug on this function. Lets see if anyone can explian.

Best regards, nErBoS
Title:
Post by: Snooze on 11 March, 2004, 01:55:47
QuoteHi,

I have tested also and the functions is always returning 1, maybe a bug on this function. Lets see if anyone can explian.

Thanks for testing it nErBoS :-)
Title:
Post by: Snooze on 11 March, 2004, 02:43:29
I started to play with plop's version of the

function ChangePass(user, data)

But when the script runs this part:

     elseif tmp <= user.iProfile then
         user:SendPM(botname, "The user "..arg.." has the same or higher level then you.")

i get this error:

Syntax Error: attempt to compare string with number


Should there be a part that changed "Master" to "0" or did i messup the script ?


**Snooze
Title:
Post by: plop on 11 March, 2004, 03:26:19
told you there were bugs. lol
never tested it.
function GetProfileOffline(nick)
   ret = nil
   for a,b in GetProfiles() do
      for c,d in GetUsersByProfile(b) do
         if d == nick then
            ret = GetProfileIdx(b)
            break
         end
      end
   end
   return ret
end
plop
Title:
Post by: Snooze on 11 March, 2004, 03:41:56
lol - your right .. well.. its gonna be tested now ;)

Your fix worked perfectly - Thanks :)


Isnt this part missing too ?
my_info_string = "$MyINFO $ALL "..bot_name.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email.."$"..bot_share_size.."$"



**Snooze
Title:
Post by: Snooze on 11 March, 2004, 04:33:45
hehe - i thought i were getting the hang of this, so i dived into a small mod ;)

This is what i came up with:

added a new getarg:

function Get3Arg(data)
s,e,cmd,arg,arg2,arg3 = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s+(%S+)%s+(.+)" )
return arg, arg2,arg3
end

and added the arg3 to the "mix":

function RegUser(user,data)
   local arg, arg2, arg3 = Get3Arg(user, data)
   if (arg==nil or arg2 == nil or arg3 == nil) then
      user:SendPM(botname, "Syntax error, !register , must have a nick and a new pass and level.")
   else
      local tmp = GetProfileOffline(arg)
      if tmp ~= nil then
         user:SendPM(Bot, "The user "..arg.." is already registerd in the Hub.")
      elseif tmp <= user.iProfile then
         user:SendPM(Bot, "The user "..arg.." has the same or higher level then you. You can only register a user with lower level than yourself.")
      else
         AddRegUser(arg, arg2, arg3)
         user:SendPM(Bot, "The user "..arg.." has been register with a new pass: "..arg2)
      end
   end
end

Though as your trained eye might see, im having some problems

As you can see, i were trying to add level to the script but all i get is this error:

Syntax Error: bad argument #1 to `strfind' (string expected, got table)

and i have NO idea about what that mean

Please help me work this out ..


**Snooze
-the lua newbie
Title:
Post by: plop on 11 March, 2004, 10:37:04
here's a hint.
check on how you call the function Get3Arg in the function RegUser.

plop
Title:
Post by: Snooze on 11 March, 2004, 16:29:17
Thanks plop :)

just the hint i needed ;)

function RegUser(user,data)
   local arg, arg2, arg3 = Get3Arg[B](data)[/B]  
   if (arg==nil or arg2 == nil or arg3 == nil) then
      user:SendPM(botname, "Syntax error, !register , must have a nick and a new pass and level.")
   else
      local tmp = GetProfileOffline(arg)
      if tmp ~= nil then
         user:SendPM(Bot, "The user "..arg.." is already registerd in the Hub.")
      elseif tmp <= user.iProfile then
         user:SendPM(Bot, "The user "..arg.." has the same or higher level then you. You can only register a user with lower level than yourself.")
      else
         AddRegUser(arg, arg2, arg3)
         user:SendPM(Bot, "The user "..arg.." has been register with a new pass: "..arg2)
      end
   end
end
Title:
Post by: Snooze on 11 March, 2004, 17:06:04
Umm ... solved one problem - created another ....

When comparing  the regged users level with arg3 im getting another error:

Syntax Error: attempt to compare string with number

This is the part:

     elseif arg3 <= user.iProfile then
         user:SendPM(Bot, "The user "..arg.." has the same or higher level then you. You can only register a user with lower level than yourself.")
      else


I replaced the tmp with my new arg3 as i cant do a lookup on a user that dont exist.. ;) - I hope thats the way to do it ..

Well.. Do anyone have another "hint" for me


**Snooze
-still learning :D
Title:
Post by: nErBoS on 11 March, 2004, 17:38:23
Hi,

Your error say every think you are comparing a string (arg3) with a number (user.iPrfile)..

just make this..

"tonumber(arg3) <= user.iProfile" will pass the string to number if the string had a number otherwise you will get error.

Best regards, nErBoS
Title:
Post by: Snooze on 12 March, 2004, 00:22:57
That solved the error part :)
Though its not comparing the arg3 with user.iProfile or not doing it correctly.

No matter what combo of arg3 and user.iProfile i try, it still returns a negative result :(

I assume that lua is looking at 2 being higher than 1 so i would have to reverse the  (">=" and not "<=") right ?

Any hints to that ?

**Snooze
- going mad over this function
Title:
Post by: nErBoS on 12 March, 2004, 02:55:28
Hi,

What does the arg3 sends ??? a number i soppose.

Best regards, nErBoS
Title:
Post by: Snooze on 12 March, 2004, 03:45:58
Get3Arg:

function Get3Arg(data)
s,e,cmd,arg,arg2,arg3 = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s+(%S+)%s+(.+)" )
return arg, arg2,arg3
end  


The function:

function RegUser(user,data)
   local arg, arg2, arg3 = Get3Arg(data)  
   if (arg==nil or arg2 == nil or arg3 == nil) then
      user:SendPM(Bot, "Syntax error, !register , must have a nick and a new pass and level.")
   else
      local tmp = GetProfileOffline(arg)
      if tmp ~= nil then
         user:SendPM(Bot, "The user "..arg.." is already registerd in the Hub.")
      elseif "tonumber(arg3) <= user.iProfile" then
         user:SendPM(Bot, "The user "..arg.." has the same or higher level then you. You can only register a user with lower level than yourself.")
      else
         AddRegUser(arg, arg2, arg3)
         user:SendPM(Bot, "The new user "..arg.." has been register with pass: "..arg2.." and profile: "..GetProfileName(arg3))
appendto(sOplog)
write("\r\n", "The User "..arg.." was regged by: "..user.sName.." with level: "..GetProfileName(arg3).." on "..GetTime())
writeto()
      end
    end
end


arg3 is the userlevel..


**Snooze
Title:
Post by: nErBoS on 12 March, 2004, 04:34:25
Hi,

The function seems alright to me. The error must be from another think, can you post here the script ??

Best regards, nErBoS
Title:
Post by: Snooze on 12 March, 2004, 05:40:12
Umm... its about 1200 lines of code so im gonna cut it down to only the part that im working on.

--Sk-BoT Created for the Snooze's Keep Hub by Snooze [URL]http://www.snooze.no-ip.com/sk/[/URL]
--Credit goes to all the friendly people at The LUA Script Board [URL]http://board.univ-angers.fr[/URL]
--Special thanks to:
--(uk-kingdom)pH?tt? for his 9step lua manual and the Mail code
--plop for helping me figure out the mail code
--nErBoS for help on read/write/delete .txt files
--And to DamionNH for ever getting me started ;-)

Bot = "?SK-BoT?"
descr = "...::: Snooze's Keep Internal Network :::..."   -- Set Description
mb = 1 * 1024              -- Bot Share ( 0 share )
speed = "SnoozeSpeed"                       -- set speed here
size = 1 * 1024 * mb
email = "bot@bot.com"            -- Set Email addy
info = "$MyINFO $ALL "..Bot.." "..descr.."$ $"..speed..strchar( 1 ).."$"..email.."$"..size.."$"


sOplog = "skbot/sktxtfiles/oplog.txt" -- In script/txtfiles/ folder
sBigshare = "skbot/sktxtfiles/invite.txt" -- Msg to bigshare users ..


prefix = "!"
trigger = "skbot"
BigShare = 50 -- In GB
SendC = SendToAll
SendP = SendPmToAll


function Main()
frmHub:RegBot(Bot)
end

function GetTime()
s = date("%S")
h = date("%H")
m = date("%M")
d = date("%d")
mm = date("%m")
y = date("%y")
Date = "Day: "..d.."/"..mm.."/20"..y.." Hour: "..h..":"..m..":"..s
return Date
end

function NewUserConnected(user)
    if not(GetProfileName(user.iProfile) == "Reg" or GetProfileName(user.iProfile) == "Vip") then
s,e,share = strfind(user.sMyInfoString, "$MyINFO $ALL [^$]+$ $[^$]*$[^$]*$([^$]+)")
share = share / (1024*1024*1024)
if (share >= BigShare) then
Readtextfile(user, sBigshare)
end
    end
  SendToAll( info )
end

function OpConnected(user)
  SendC( info )
end

function DataArrival(user,data)
if strsub(data, 1, 1) == "<" or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
local data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
 if cmd == (trigger) then
   user:SendPM(Bot, "Welcome to SK-BoT. Type !skhelp too see commands available to you.")
 elseif cmd == prefix.."changeuserpass" then
   ChangePass(user, data)
 elseif cmd == prefix.."reg" then
   RegUser(user, data)
 elseif cmd == prefix.."deleteuser" then
   DelUser(user, data)
 elseif cmd == prefix.."showlogs" then
   ShowLogs(user, data)
 elseif cmd == prefix.."clearlogs" then
   ClearLogs(user, data)
 elseif cmd == prefix.."changeuserpass" then
   ChangePass(user, data)
 end
    end
end

---------------Reg Del Users------------

function Get1Arg(data)
   s,e,cmd,arg = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )
   return arg
end

function Get2Arg(data)
   s,e,cmd,arg,arg2 = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s+(.+)" )
   return arg, arg2
end


function Get3Arg(data)
   s,e,cmd,arg,arg2,arg3 = strfind( data, "%b<>%s+(%S+)%s+(%S+)%s+(%S+)%s+(.+)" )
   return arg, arg2,arg3
end  

function GetProfileOffline(nick)
   ret = nil
   for a,b in GetProfiles() do
      for c,d in GetUsersByProfile(b) do
         if d == nick then
            ret = GetProfileIdx(b)
            break
         end
      end
   end
   return ret
end

function RegUser(user,data)
   local arg, arg2, arg3 = Get3Arg(data)  
   if (arg==nil or arg2 == nil or arg3 == nil) then
      user:SendPM(Bot, "Syntax error, !register , must have a nick and a new pass and level.")
   else
      local tmp = GetProfileOffline(arg)
      if tmp ~= nil then
         user:SendPM(Bot, "The user "..arg.." is already registerd in the Hub.")
      elseif "tonumber(arg3) <= user.iProfile" then
         user:SendPM(Bot, "The user '"..arg.."' has the same or higher level then you. You can only register a user with lower level than yourself.")
appendto(sOplog)
write("\r\n", "*"..user.sName.." tryed register '"..arg.."' with level a higher level than themself. (Level: "..GetProfileName(arg3)..") on "..GetTime())
writeto()
      else
         AddRegUser(arg, arg2, arg3)
         user:SendPM(Bot, "The new user '"..arg.."' has been register with pass: '"..arg2.."' and profile: "..GetProfileName(arg3))
appendto(sOplog)
write("\r\n", "*"..user.sName.." registered '"..arg.."' with password:'"..arg2.."' and level: "..GetProfileName(arg3).." on "..GetTime())
writeto()
      end
    end
end

function ChangePass(user, data)
   local arg, arg2 = Get2Arg(data)  
   if (arg == nil or arg2 == nil) then
      user:SendPM(Bot, "Syntax error, !changeuserpass , must have a nick and a new pass.")
   else
      local tmp = GetProfileOffline(arg)
      if tmp == nil then
         user:SendPM(Bot, "The user '"..arg.."' is not registerd in the Hub.")
      elseif tmp <= user.iProfile then
         user:SendPM(Bot, "The user '"..arg.."' has the same or higher level then you. You can only change password on a user with lower level than yourself.")
appendto(sOplog)
write("\r\n", "*"..user.sName.." tryed to change a higher ranking users ("..arg..") password to:'"..arg2.."' and level: "..GetProfileName(arg3).." on "..GetTime())
writeto()
      else
         DelRegUser(arg)
         AddRegUser(arg, arg2, tmp)
         user:SendPM(Bot, "The user "..arg.."'s password has been changed to: "..arg2)
appendto(sOplog)
write("\r\n", "*"..user.sName.." changed "..arg.."'s password to:'"..arg2.."' on "..GetTime())
writeto()
      end
   end
end


function DelUser(user, data)
Get1Arg(data)
if (arg == nil) then
user:SendPM(Bot, "Syntax error, !deleteuser .")
else
if (DelRegUser(arg) == -1) then
user:SendPM(botname, "The User '"..arg.."' is not registerd in the Hub.")
appendto(sOplog)
write("\r\n", "The non existing user "..arg.." was attempted deleted by: "..user.sName.." on "..GetTime())
writeto()
else
DelRegUser(arg)
user:SendPM(Bot, "The User '"..arg.."' has been deleted. This action was added to log. ")
appendto(sOplog)
write("\r\n", "*"..user.sName.." deleted the User '"..arg.."' on "..GetTime())
writeto()
end
end
end
-------------Start Logs---------------
function ShowLogs(user, data)
if not user.bOperator then
SendC(Bot, "Only Ops can use this function.")
return 1
end
readfrom(sOplog)
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
appendto(sOplog)
write("\r\n", "*"..user.sName.." viewed the OpsLogs on "..GetTime())
writeto()
readfrom() -- close filehandle
user:SendPM(Bot,sFileContent)
return 1
else
SendC(Bot,"Nothing in \"oplog.txt\" or no \"oplog.txt\"")
return 1
end
readfrom()
end

function ClearLogs(user, data)
if (GetProfileName(user.iProfile) == "Master") then
writeto(sOplog) -- goes to the file wanted
write("") --- will write nothing in the file and everthing that was on him will disappeare
writeto() -- to write on the file
appendto(sOplog)
write("\r\n", "The Operator '"..user.sName.."' deleted the OpsLogs on "..GetTime())
writeto()
user:SendPM(Bot, "Done.. The OpsLogs has been deleted!")
return 1
else
SendC(Bot, "Only Ops with the profile Master can use this function.")
return 1
end
end




I hope this helps clear it up :-)

**Snooze
- still trying ...
Title:
Post by: nErBoS on 12 March, 2004, 14:56:44
Hi,

Well your reg is not working because you have diferent names the function name..

"function RegUser(user,data)"

The function called in the command !reg..

"RegOps(user, data)"

Try to correct that and you will see that will work.

Best regards, nErBoS
Title:
Post by: Snooze on 12 March, 2004, 15:12:47
Opps :(

Pasted the wrong command in here .. It's corrected in the script above..

Sorry nErBoS !



**Snooze
Title:
Post by: nErBoS on 12 March, 2004, 16:57:46
Hi,

Have i tried your script and worked ok, if you know when happens the error it would helps to see whats wrong.

Best regards, nErBoS
Title:
Post by: Snooze on 12 March, 2004, 18:32:10
Hmm... thats odd..

When i try to register a user i get the error:

The user has the same or higher level then you. You can only register a user with lower level than yourself.

I get that no matter what level i enter.. ?


**Snooze
Title:
Post by: nErBoS on 12 March, 2004, 19:24:27
Hi,

Modified this...
      elseif "tonumber(arg3) <= user.iProfile" then
to this..
      elseif (tonumber(arg3) <= user.iProfile) then

I have tried and got no error he lets me register the one i can and don?t let the own that i can?t

Best regards, nErBoS
Title:
Post by: Snooze on 12 March, 2004, 22:01:15
Thanks nErBoS :))

That worked just like we entended !!


**Snooze
- 4ever greatfull
Title:
Post by: Snooze on 16 March, 2004, 11:05:36
After working a "few" days on this script to my Ops, i feel like i need to thank you both again for all the help you have given me !!

A _H U G E_ 'Thank You' goes to nErBoS & plop !!!!



**Snooze
- the greatfull
Title:
Post by: plop on 16 March, 2004, 16:14:09
QuoteOriginally posted by Snooze
After working a "few" days on this script to my Ops, i feel like i need to thank you both again for all the help you have given me !!

A _H U G E_ 'Thank You' goes to nErBoS & plop !!!!



**Snooze
- the greatfull
yw.

plop
Title:
Post by: nErBoS on 16 March, 2004, 16:32:35
Hi,

Your welcome, we are here to help on at we can :)

Best regards, nErBoS