Author Topic: some quick help with magic/alpha numeric chars  (Read 3931 times)

0 Members and 1 Guest are viewing this topic.

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
some quick help with magic/alpha numeric chars
« on: 23 February, 2005, 00:10:36 »
If I want to use magic characters to look for one single alpha numeric character in for example a search, what combination should I use?

Here is a few example I thought off, but to be honest. I'm pretty bad when it comes to magic characters :P =

alphaNum = [*(%s)]
alphaNum = [*(%p)]
alphaNum = [*(%w)]

And if I want to search for a word with a space infront of it, would this magic char combination be good? =

word = (*(%s)b<>)


PtokaX forum

some quick help with magic/alpha numeric chars
« on: 23 February, 2005, 00:10:36 »

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 752
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #1 on: 23 February, 2005, 00:20:51 »
%w for alphanum char

for a word with single space:

Code: [Select]
" %S+"
if there can be more:

Code: [Select]
"%s+%S+"

was quick but had 2 hurry :)
Everything could have been anything else and it would have just as much meaning.

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #2 on: 23 February, 2005, 00:32:09 »
Quote
Originally posted by bastya_elvtars
%w for alphanum char
Is this the same... =
alphaNum= ("%w+")

...as for example this one (ofcourse %w represent many chars,but this is just an example) =
alphaNum= "."
« Last Edit: 23 February, 2005, 00:32:58 by blackwings »


Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 752
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #3 on: 23 February, 2005, 01:21:03 »
nope %w is for a-z and 0-9

. represents ANY char.
Everything could have been anything else and it would have just as much meaning.

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #4 on: 23 February, 2005, 01:25:13 »
click

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 blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #5 on: 23 February, 2005, 01:26:12 »
Quote
Originally posted by bastya_elvtars
nope %w is for a-z and 0-9

. represents ANY char.
lol, so which magic chars should I use if I want to find chars like these =>
Code: [Select]
"." , "_" , "-" , "+" , "?" , "&" , "*" , "=" , "!" , "#" , "|" , "?" , "?" , "?" , "?" , "@" , "$" , "%" , "^"


Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #6 on: 23 February, 2005, 01:27:39 »
Quote
Originally posted by plop
click

plop
plop, I have checked that, but I don't understand it to well, totally bad when it comes to magic chars :P


Offline VidFamne

  • Triple Ace
  • **
  • Posts: 173
  • Karma: +2/-0
(No subject)
« Reply #7 on: 23 February, 2005, 01:54:13 »
Quote
%c - represents all control characters
Quote
x - (where x is any magic characters ^$()%.[]*+-?) - represents the character x itself.
Read all about it here

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 752
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #8 on: 23 February, 2005, 01:56:03 »
regexps:

finding alphanumeric: %w , 1 or more: %w+ (goes for all)
finding a number: %d

magic chars:

finding the ^: %^
finding anything but the ^: [^%^]

finding any of these 3 letters: [BLU]
finding anything but any of B,L and U: [^BLU]

finding the %: %%
finding spaces: %s

"reverse" regexps (uppercase):

finding anything but space: %S
finding anything but alphanum: %W
finding anything but number: %D

-- // edit

ask exact questions about what you want to find
« Last Edit: 23 February, 2005, 01:56:56 by bastya_elvtars »
Everything could have been anything else and it would have just as much meaning.

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #9 on: 23 February, 2005, 02:17:01 »
Quote
Originally posted by bastya_elvtars
ask exact questions about what you want to find
well, I want to search for characters like these inside messages sent by users = "." , "_" , "-" , "+" , "?" , "&" , "*" , "=" , "!" , "#" , "|" , "?" , "?" , "?" , "?" , "@" , "$" , "%" , "^"

Reason for why I want to do that is because I have a new idea for my anti-advertise script.

EDIT:Like this for example =
Code: [Select]
vStart = " %S+"
tSigns = "%p"

advDetect = vStart..tSigns..tPart01..tSigns..tPart02
but just " %S+" doesn't seem to work, do need to strfind or something else like that to make it work?
« Last Edit: 23 February, 2005, 04:43:22 by blackwings »


Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 752
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #10 on: 24 February, 2005, 19:11:57 »
To find a non-space char chain in your script:

Code: [Select]
local s,e,string=strfind(text,"(%S+)")
s and e are values that demonstrate where the desired string starts and where it ends inside the text. string is the string value you wanna find. It must be between parentheses in order to grab it.

In a DC++ main chat line:

Code: [Select]
local s,e,cmd=strfind(data,"%b<>%s+(%S+).*")
which means:

in data find the string that is non-space (%S+) and comes after a string between < and > (%b<>) and 1 or more spaces (%s+), and can be followed by anything, incl. nothing (.*).

Hope i was clear.
Everything could have been anything else and it would have just as much meaning.

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #11 on: 24 February, 2005, 20:44:22 »
Quote
Originally posted by bastya_elvtars
To find a non-space char chain in your script:

Code: [Select]
local s,e,string=strfind(text,"(%S+)")
Code: [Select]
local s,e,cmd=strfind(data,"%b<>%s+(%S+).*")
After reading on how to search for text/signs in messsages by searching with magic chars, I experimented some, but it didn't go so well :P Could you help me fix it if you have the time please bastya?  Here is a error I get =
(i really try to learn, therefore I do these experiment, because there is no ptokax lua tutorial)
Code: [Select]
Syntax error: bad argument #1 to `strfind' (string expected, got nil)
stack traceback:
   1:  function `strfind' [C]
   2:  function `DataArrival' at line 76 [file `C:\ptokax-testing\scripts\AdvertiseCrusher-Test01.lua']
And here is the script I experiment with =
Code: [Select]
--Advertise Crusher Testing
--v1.0
------------------------------------------------------------------------
--++++++++++++++++++++++ START OF CONFIGURATION ++++++++++++++++++++++--
------------------------------------------------------------------------
Bot = "#AdverTEST"

-- (1)Shall be tempbanned/banned / (0) this profile shouldn't be effected.
SetToWho = {
[0] = 0, -- Masters
[1] = 0, -- Operators
[2] = 1, -- Vips
[3] = 1, -- Regs
[4] = 0, -- Moderator
[5] = 0, -- NetFounder
[-1] = 1, -- Users
}

-- How many times a user gets tempbanned before getting a permban
adverKill = 3
-- If the "kill" messages should be shown to everyone in main chat
ShowAllinMain = 1

theSafeAdver={
"test1.no-ip.com","test2.no-ip.com","test3.no-ip.com","test4.no-ip.com",
}

DNS01={
"no-ip","mine","sytes","dynip","dyndns","gotdns","kicks-ass","d2g","serveftp",
"servehttp","servehalflife","servequake","servecounterstrike","xs4all","myftp",
"servebeer","zapto","tropico","lysekil","udgnet","dnsalias","dynalias","ath","homeip",
"servemp3","hopto","servegame","staticip","orgdns","myftpsite","ipactive","idlegames",
"homeunix","homelinux","flamenap","dns2go","clanpimp","bounceme","ip","uni","is-a-geek","isa-geek"
}

DNS02={"com","net","org","nu","se","cx","us","it","co.uk","info","biz","cc","de","tv","nl"}

theSafeAdver={
"test1.no-ip.com","test2.no-ip.com","test3.no-ip.com","test4.no-ip.com",
}
------------------------------------------------------------------------
--+++++++++++++++++++++++ END OF CONFIGURATION +++++++++++++++++++++++--
------------------------------------------------------------------------
adverCounter = 0

function Main()
end

function adverSmashing(user)
if SetToWho[user.iProfile]==1 then
adverCounter = adverCounter + 1
tmpBanLeft = adverKill - adverCounter
if adverCounter < adverKill then
user:SendData(Bot, "You are tempbanned because of advertiseing.")
user:SendData(Bot, "Number of tempban before permban = "..tmpBanLeft)
-- user:TempBan()
SendPmToOps(Bot, "User <"..user.sName.."> was tempbanned for advertising, wrote = "..advDetect)
if ShowAllinMain == 1 then
SendToAll(Bot, "User <"..user.sName.."> was tempbanned for advertising")
end
elseif adverCounter == adverKill then
user:SendData(Bot, "You are PERMBANNED because of advertiseing")
-- user:Ban()
SendPmToOps(Bot, "User <"..user.sName.."> was PERMBANNED for advertising, wrote = "..advDetect)
if ShowAllinMain == 1 then
SendToAll(Bot, "User <"..user.sName.."> was PERMBANNED for advertising")
end
adverCounter = 0
end
end
end


function DataArrival(user,data,text)
if (strsub(data, 1, 1) == "<") or  (strsub(data, 1, 4) == "$To:") then
local s,e,vDNS = strfind(text,"%b<>%s+(^%S+%p)(%S+)(^%p%S+)$")
local s,e,vStart = strfind(text," (%S+)")
local s,e,vSigns = strfind(text,"%p")
if vDNS then
for e=1,getn(DNS01) do
tPart01 = (strlower(DNS01[e]))
end
for f=1,getn(DNS02) do
tPart02 = (strlower(DNS02[f]))
end
for g=1,getn(theSafeAdver) do
safeAdv = (strlower(theSafeAdver[g]))
end
--
advDetect = vSigns..tPart01..vSigns..tPart02
--
if vDNS == advDetect then
if( strfind(data, safeAdv,1,1))  then
return nil
end
return adverSmashing(user)
end
end

end
end
« Last Edit: 24 February, 2005, 20:47:29 by blackwings »


Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 752
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #12 on: 24 February, 2005, 20:52:06 »
text is nil. use data instead. Voil?! :D
Everything could have been anything else and it would have just as much meaning.

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #13 on: 24 February, 2005, 23:13:48 »
Quote
Originally posted by bastya_elvtars
text is nil. use data instead. Voil?! :D
I don't get any error messages, but it still won't work. I think it has to do with this line =
Code: [Select]
local s,e,vDNS = strfind(data,"%b<>%s+(^%S+%p)(%S+)(^%p%S+)$")And maybe also this line (maybe it's not possible to compare them that way + trigger the script to do it's purpose) =
Code: [Select]
if vDNS == advDetect thenHere is the code again(the only change is that I replaced text with data) =
Code: [Select]
--Advertise Crusher Testing
--v1.0
------------------------------------------------------------------------
--++++++++++++++++++++++ START OF CONFIGURATION ++++++++++++++++++++++--
------------------------------------------------------------------------
Bot = "#AdverTEST"

-- (1)Shall be tempbanned/banned / (0) this profile shouldn't be effected.
SetToWho = {
[0] = 0, -- Masters
[1] = 0, -- Operators
[2] = 1, -- Vips
[3] = 1, -- Regs
[4] = 0, -- Moderator
[5] = 0, -- NetFounder
[-1] = 1, -- Users
}

-- How many times a user gets tempbanned before getting a permban
adverKill = 3
-- If the "kill" messages should be shown to everyone in main chat
ShowAllinMain = 1

theSafeAdver={
"test1.no-ip.com","test2.no-ip.com","test3.no-ip.com","test4.no-ip.com",
}

DNS01={
"no-ip","mine","sytes","dynip","dyndns","gotdns","kicks-ass","d2g","serveftp",
"servehttp","servehalflife","servequake","servecounterstrike","xs4all","myftp",
"servebeer","zapto","tropico","lysekil","udgnet","dnsalias","dynalias","ath","homeip",
"servemp3","hopto","servegame","staticip","orgdns","myftpsite","ipactive","idlegames",
"homeunix","homelinux","flamenap","dns2go","clanpimp","bounceme","ip","uni","is-a-geek","isa-geek"
}

DNS02={"com","net","org","nu","se","cx","us","it","co.uk","info","biz","cc","de","tv","nl"}

theSafeAdver={
"test1.no-ip.com","test2.no-ip.com","test3.no-ip.com","test4.no-ip.com",
}
------------------------------------------------------------------------
--+++++++++++++++++++++++ END OF CONFIGURATION +++++++++++++++++++++++--
------------------------------------------------------------------------
adverCounter = 0

function Main()
end

function adverSmashing(user)
if SetToWho[user.iProfile]==1 then
adverCounter = adverCounter + 1
tmpBanLeft = adverKill - adverCounter
if adverCounter < adverKill then
user:SendData(Bot, "You are tempbanned because of advertiseing.")
user:SendData(Bot, "Number of tempban before permban = "..tmpBanLeft)
-- user:TempBan()
SendPmToOps(Bot, "User <"..user.sName.."> was tempbanned for advertising, wrote = "..advDetect)
if ShowAllinMain == 1 then
SendToAll(Bot, "User <"..user.sName.."> was tempbanned for advertising")
end
elseif adverCounter == adverKill then
user:SendData(Bot, "You are PERMBANNED because of advertiseing")
-- user:Ban()
SendPmToOps(Bot, "User <"..user.sName.."> was PERMBANNED for advertising, wrote = "..advDetect)
if ShowAllinMain == 1 then
SendToAll(Bot, "User <"..user.sName.."> was PERMBANNED for advertising")
end
adverCounter = 0
end
end
end


function DataArrival(user,data)
if (strsub(data, 1, 1) == "<") or  (strsub(data, 1, 4) == "$To:") then
local s,e,vDNS = strfind(data,"%b<>%s+(^%S+%p)(%S+)(^%p%S+)$")
local s,e,vStart = strfind(data," (%S+)")
local s,e,vSigns = strfind(data,"%p")
if vDNS then
for e=1,getn(DNS01) do
tPart01 = (strlower(DNS01[e]))
end
for f=1,getn(DNS02) do
tPart02 = (strlower(DNS02[f]))
end
for g=1,getn(theSafeAdver) do
safeAdv = (strlower(theSafeAdver[g]))
end
--
advDetect = vSigns..tPart01..vSigns..tPart02
--
if vDNS == advDetect then
if( strfind(data, safeAdv,1,1))  then
return nil
end
return adverSmashing(user)
end
end

end
end


PtokaX forum

(No subject)
« Reply #13 on: 24 February, 2005, 23:13:48 »