Author Topic: Strfind?  (Read 4459 times)

0 Members and 1 Guest are viewing this topic.

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
Strfind?
« 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?

PtokaX forum

Strfind?
« on: 08 January, 2004, 20:40:29 »

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #1 on: 08 January, 2004, 20:50:19 »
then don't allow those signs... :-) simple... hehe
//NL

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #2 on: 08 January, 2004, 21:03:22 »
s,e,cmd,victim = strfind(data, "%b<>%s+(%S+)%s+([^%S]+)")
wild gues  hope it works

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #3 on: 08 January, 2004, 21:15:21 »
while in to this...

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


what does [^ do have never dealt with it so much... exept P/C :-)
//NL

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #4 on: 08 January, 2004, 21:32:58 »
Going to test it, thx Plop

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #5 on: 08 January, 2004, 21:38:33 »
Nope it ain't working at the moment, it gives a nil error

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #6 on: 08 January, 2004, 21:38:51 »
s,e,cmd,victim = strfind(data, "%b<>%s+(%S+)%s+([^%s]+)")
should be a small s.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #7 on: 08 January, 2004, 21:49:53 »
shitss, almost the same

Syntax error: bad argument #1 to `write' (string expected, got nil)

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #8 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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #9 on: 08 January, 2004, 22:52:35 »
Quote
Originally 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
« Last Edit: 08 January, 2004, 22:55:47 by plop »
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #10 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

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #11 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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #12 on: 08 January, 2004, 23:12:36 »
ok gone test again, thx  ;)

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #13 on: 08 January, 2004, 23:26:11 »
mm, still the same result... it's for a offline message

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #14 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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #15 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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #16 on: 09 January, 2004, 18:35:28 »
Will post results here? almost there

Thx to the Ploperarot  ;)

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #17 on: 09 January, 2004, 20:40:21 »
Quote
Originally 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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #18 on: 09 January, 2004, 21:27:08 »
Here is the Result!  lol Ploperator

Code: [Select]
-- 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


PtokaX forum

(No subject)
« Reply #18 on: 09 January, 2004, 21:27:08 »