PtokaX forum

Development Section => Your Developing Problems => Topic started by: Optimus on 08 January, 2004, 20:40:29

Title: Strfind?
Post by: Optimus on 08 January, 2004, 20:40:29
Hi guys have a little problem?

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

I use above example to get the nick of a user, but when i use it whit this nick :T??:.test

I get errors because of strange signs

Any ideas?
Title:
Post by: NightLitch on 08 January, 2004, 20:50:19
then don't allow those signs... :-) simple... hehe
Title:
Post by: plop on 08 January, 2004, 21:03:22
s,e,cmd,victim = strfind(data, "%b<>%s+(%S+)%s+([^%S]+)")
wild gues  hope it works

plop
Title:
Post by: NightLitch on 08 January, 2004, 21:15:21
while in to this...

Quotes,e,cmd,victim = strfind(data, "%b<>%s+(%S+)%s+([^%S]+)")

what does [^ do have never dealt with it so much... exept P/C :-)
Title:
Post by: Optimus on 08 January, 2004, 21:32:58
Going to test it, thx Plop
Title:
Post by: Optimus on 08 January, 2004, 21:38:33
Nope it ain't working at the moment, it gives a nil error
Title:
Post by: plop on 08 January, 2004, 21:38:51
s,e,cmd,victim = strfind(data, "%b<>%s+(%S+)%s+([^%s]+)")
should be a small s.

plop
Title:
Post by: Optimus on 08 January, 2004, 21:49:53
shitss, almost the same

Syntax error: bad argument #1 to `write' (string expected, got nil)
Title:
Post by: plop on 08 January, 2004, 22:50:18
s,e,cmd,victim = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s+")
also search for whats behind victim seems 2 work here.
it gets stuck on the . for example
s,e,cmd,victim = strfind(data, "%b<>%s+(%S+)%s+(%S+)%.+")
returns  :T??:

plop
Title:
Post by: plop on 08 January, 2004, 22:52:35
QuoteOriginally posted by NightLitch
while in to this...
what does [^ do have never dealt with it so much... exept P/C :-)
you can make your own ranges 2 search for or single things.
in this case it was a longer way 2 search for anything beside a space.
[^0-6]  would return anything beside 0 to 6.
[^a-f]  would return anything beside a to f
[^a]    would return anything beside a
[a]    returns only a
etc....

plop
Title:
Post by: Optimus on 08 January, 2004, 22:56:11
Yups your right there is something else wrong?

strfind was ok.

local handle=openfile("logs/online/"..victim..".txt","a")
            write(handle, user.sName.."\r\n")
            closefile(handle)


This is the problem when it writes to disk it don't regonize the signs *lol* - and that
s true offcourse Forgot all about it.

mm, now i have todesign some other construction
Title:
Post by: plop on 08 January, 2004, 23:06:25
victim = gsub(victim, "%.", "$")
and your done. lol
on loading saving you change the . for something else.
they can't use the $ in there nick, so it should be save.

plop
Title:
Post by: Optimus on 08 January, 2004, 23:12:36
ok gone test again, thx  ;)
Title:
Post by: Optimus on 08 January, 2004, 23:26:11
mm, still the same result... it's for a offline message
Title:
Post by: plop on 08 January, 2004, 23:37:11
sleeping here.
( ) . % + - * ? [ ^ $ are all magic things  so you need 2 escape it on loading.
changing it back on loading would be
victim = gsub(victim, "%$", ".")
if it still doesn't work can you give me those parts of the code so i can try it here.??

plop
Title:
Post by: plop on 09 January, 2004, 01:52:12
think i found the full problem.
if so optimus should respond here happy 2morrow. lol
strfind got lost on the . and saving loading got lost on the :
this i used 2 find the victem:
s,e,cmd,victim = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*$")
and this i used 2 solve the : problem:
temp = gsub(user, ":", "$")
loading and saving, strfind now all seem 2 work.
lets wait for the final answer from optimus.

plop
Title:
Post by: Optimus on 09 January, 2004, 18:35:28
Will post results here? almost there

Thx to the Ploperarot  ;)
Title:
Post by: plop on 09 January, 2004, 20:40:21
QuoteOriginally posted by Optimus
Will post results here? almost there

Thx to the Ploperarot  ;)
check pm.
[20:36] *** Online check to user <:T??:.Test> has been set!
[20:36] Private message from Online_Demo: *** User <:T??:.Test> went online at: 01/09/04 20:30:17 - His IP:

plop
Title:
Post by: Optimus on 09 January, 2004, 21:27:08
Here is the Result!  lol Ploperator

-- Online Check Demo - by Opti
-- Modded by Plop to work with Strange Signs in username
-- Added other strfind & gsub handling Plop
-- Fixed small Buggs Plop

sBot = "Online_Demo"

timedate = date()
prefix = "!"

function Main()
frmHub:RegBot(sBot)
end

function NewUserConnected(user)
   OnlineConnect(user, data)
end

OpConnected = NewUserConnected

function DataArrival(user, data)
   if( strsub(data, 1, 1) == "<" ) then
      data=strsub(data,1,strlen(data)-1)
      s,e,cmd,victim = strfind(data, "%b<>%s+(%S+)")
      if (cmd == prefix.."online") then
         s,e,cmd,victim = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*$")
         if victim == nil then user:SendData(sBot, "*** Enter a username!") return 1 end
         victim2 = gsub(victim, ":", "$")
         local handle=openfile(victim2..".txt","a")
         write(handle, user.sName.."\r\n")
         closefile(handle)
         user:SendData(sBot, "*** Online check to user <"..victim.."> has been set!")
         return 1
      end
   end
end

--// Online Check
function OnlineConnect(user, data)
   temp = gsub(user.sName, ":", "$")
   readfrom(temp..".txt")
   while 1 do
      SendUser = read()
      if SendUser == nil then
         break
      end
      SendPmToNick(SendUser, sBot, "*** User <"..user.sName.."> went online at: "..timedate.." - His IP: "..user.sIP)
   end
   readfrom()
   a,b=remove(temp..".txt")
end