PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: DorianG on 23 March, 2004, 00:46:44

Title: Help me
Post by: DorianG on 23 March, 2004, 00:46:44
I have edit a script but doesnt work.
Please help me..
Thank you

sPasswdFile      = "../RegisteredUsers.dat";

function DataArrival(user, data)
if (strsub(data,1,1) == "<") then
data = strsub(data,1,strlen(data)-1)
local s,e,cmd = nil
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if cmd == "!getuserpass" then
GetPasswordCmd(user, data)
end
end
end

function GetPasswordCmd(user, data)
_, _, cmd, str = strfind(data, "%b<>%s+(%S+)%s*([^%|]*)%|$");
if str ~= nil then
local sPasswd = GetPassword(str);
if (sPasswd) then
user:SendData(BotName, "L'utente "..str.." ? un utente registrato e la sua password ?: "..sPasswd.."");
else
user:SendData(BotName, "L'utente "..str.." non ? registrato!");
end
else
user:SendData(BotName, "Non ci posso credere ma allora nn sai leggere? cavolo non ? possibile che ancora tu non abbia imparato, devi digitare: !getpass ");
end
return 1;
end

function GetPassword(From)
local flPasswdFile = openfile(sPasswdFile, "r");
local line = "";
From = strlower(From);
if (flPasswdFile) then
line = read(flPasswdFile);
while (line) do
_, _, sNick, sPasswd = strfind(line, "^(%S+)|(%S+)|");
if (strlower(sNick) == From) then
return sPasswd;
end
line = read(flPasswdFile);
end
closefile(flPasswdFile);
end
return nil;
end
Title:
Post by: DorianG on 23 March, 2004, 14:38:54
Nobody can help me?
Title:
Post by: plop on 23 March, 2004, 17:21:28
QuoteOriginally posted by DorianG
Nobody can help me?
1st of all, allways give a description of what goes wrong and as precise as posible.
next check this part.
local s,e,cmd = nil

s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if you make this into 1 line it's gone work.

plop
Title:
Post by: DorianG on 24 March, 2004, 15:15:03
Sorry Plop.. This is the original script. But i have edit it as the first post.. I'm sorry

-- simple standalone get-password-by-nick-bot by bonki 09/06/03

sBotName         = "PasswdBot";
sGetPasswdPhrase = "!getpasswd";
sPasswdFile      = "../RegisteredUsers.dat";

function DataArrival(curUser, sData)
  local _, _, cmd, args = strfind(sData, "%b<>%s+(%S+)%s*([^%|]*)%|$");

  if(cmd == nil) then
    return 0; end

  cmd = strlower(cmd);

  if (cmd == sGetPasswdPhrase) then
    curUser:SendData(sData);

    if (curUser.bOperator) then
      if (strlen(args) > 0) then
        local sPasswd = GetPassword(args);
        if (sPasswd) then
          curUser:SendData(sBotName, args.."'s password is: '"..sPasswd.."'");
        else
          curUser:SendData(sBotName, "User "..args.." doesn't exist!");
        end
      else
        curUser:SendData(sBotName, "Syntax: "..sGetPasswdPhrase.." ");
      end
    else
      curUser:SendData(sBotName, "You don't have sufficient rights to run that command!");
    end
    return 1;
  end

  return 0;
end

function GetPassword(sFrom)
  local flPasswdFile = openfile(sPasswdFile, "r");
  local line         = "";

  sFrom = strlower(sFrom);

  if (flPasswdFile) then
    line = read(flPasswdFile);
    while (line) do
      _, _, sNick, sPasswd = strfind(line, "^(%S+)|(%S+)|");
      if (strlower(sNick) == sFrom) then
        return sPasswd;
      end
      line = read(flPasswdFile);
    end
    closefile(flPasswdFile);
  end

  return nil;
end

Title:
Post by: DorianG on 24 March, 2004, 15:17:55
Why if i put this:

local s,e,cmd = nil
s,e,cmd = strfind(data, "%b<>%s(%S+)")

The script dont work?