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<>)
%w for alphanum char
for a word with single space:
" %S+"
if there can be more:
"%s+%S+"
was quick but had 2 hurry :)
QuoteOriginally 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= "."
nope %w is for a-z and 0-9
. represents ANY char.
click (http://www.plop.nl/howto/pattern_matching.php)
plop
QuoteOriginally 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 =>
"." , "_" , "-" , "+" , "?" , "&" , "*" , "=" , "!" , "#" , "|" , "?" , "?" , "?" , "?" , "@" , "$" , "%" , "^"
QuoteOriginally posted by plop
click (http://www.plop.nl/howto/pattern_matching.php)
plop
plop, I have checked that, but I don't understand it to well, totally bad when it comes to magic chars :P
Quote%c - represents all control characters
Quotex - (where x is any magic characters ^$()%.[]*+-?) - represents the character x itself.
Read all about it here (http://www.lua.org/manual/4.0/manual.html#6.2)
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
QuoteOriginally 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 =
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?
To find a non-space char chain in your script:
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:
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.
QuoteOriginally posted by bastya_elvtars
To find a non-space char chain in your script:
local s,e,string=strfind(text,"(%S+)")
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)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 = --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
nosafeAdver={
"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"}
nosafeAdver={
"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(nosafeAdver) do
safeAdv = (strlower(nosafeAdver[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
text is nil. use data instead. Voil?! :D
QuoteOriginally 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 =
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) =
if vDNS == advDetect then
Here is the code again(the only change is that I replaced text with data) =
--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
nosafeAdver={
"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"}
nosafeAdver={
"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(nosafeAdver) do
safeAdv = (strlower(nosafeAdver[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