| View previous topic :: View next topic |
| Author |
Message |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Sun May 05, 2019 2:45 pm Post subject: count total score of duplicate characters in nick |
|
|
could this msl code be translated into tcl
| Code: |
if ($regex($nick,/(.)\1+/g) > 3) { kick $chan $nick counts $regex($nick,/(.)\1+/g) duplicate characters } |
it matches any duplicate char of any kind and counts as one and adds a total and if exceeded 3 matching duplicates it executes kick
| Quote: |
Join : aabbccddeeff ~Mibbit@Amigo.Premium.net
aabbccddeeff Kicked from #tcl-test By +simo <> ( counts 6 duplicate characters ) |
possibly for nick change as well |
|
| Back to top |
|
 |
heartbroken Op

Joined: 23 Jun 2011 Posts: 106 Location: somewhere out there
|
Posted: Sun May 05, 2019 3:46 pm Post subject: |
|
|
| Code: | | if {[set dup [regexp -all {(.)\1} $nick]] >= 3} { putkick $chan $nick "counts $dup duplicate characters" } |
_________________ Life iS Just a dReaM oN tHE wAy to DeaTh
Last edited by heartbroken on Sun May 05, 2019 5:53 pm; edited 2 times in total |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Sun May 05, 2019 5:44 pm Post subject: |
|
|
thnx for the response heartbroken
i tried this:
| Code: |
bind join - * join:nickcheck
bind nick - * nick:nickcheck
proc nick:nickcheck {nick uhost hand chan newnick} {
join:nickcheck $newnick $uhost $hand $chan
}
proc join:nickcheck {nick uhost hand chan} {
global botnick
if {[string tolower $nick] != [string tolower $botnick]} {
if {[botisop $chan]} {
if {[set dup [regexp -all {(.)\1} $nick]] >= 3} {
putkick $chan $nick "counts $dup duplicate characters"
}
}
}
}
|
and with a nick like hhhgggfffdddd it should detect 4 duplicate chars but instead it says it detected 5 not sure why ? |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Sun May 05, 2019 5:51 pm Post subject: |
|
|
| i think i see why it counts repeated chars twice or more like gggg it counts as 2 while its repeats from 1 char and should count as 1 |
|
| Back to top |
|
 |
heartbroken Op

Joined: 23 Jun 2011 Posts: 106 Location: somewhere out there
|
Posted: Sun May 05, 2019 6:00 pm Post subject: |
|
|
(.) -> matches any char, with \1 matches 2 same characters. if you want to match 3 same chars -> (.)\1\1 …
and regexp's -all option, gives how many matches in given string. >= checking if counted matches equal or bigger than 3 … do the job... _________________ Life iS Just a dReaM oN tHE wAy to DeaTh |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Sun May 05, 2019 6:21 pm Post subject: |
|
|
tnx for the clarfication
also could it be done that repeat chars more than one of a char counts as 1 so hhhhhhhhh counts as 1 and gg counts as 1 and ggg counts as 1 and so on |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Mon May 06, 2019 10:38 am Post subject: |
|
|
for example:
gghhhhkkkkkwwwwww will have total count of 4 |
|
| Back to top |
|
 |
heartbroken Op

Joined: 23 Jun 2011 Posts: 106 Location: somewhere out there
|
Posted: Mon May 06, 2019 4:48 pm Post subject: |
|
|
(.)\1+ will do what you want .
it matches two and more same chars in string. _________________ Life iS Just a dReaM oN tHE wAy to DeaTh |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Mon May 06, 2019 6:12 pm Post subject: |
|
|
| excellent thanx heartbroken |
|
| Back to top |
|
 |
|