View previous topic :: View next topic |
Author |
Message |
Dizmo Voice
Joined: 01 Apr 2016 Posts: 6
|
Posted: Sat Apr 14, 2018 9:03 am Post subject: Voice/Devoice on Nick Change With Multiple 'Variables'? |
|
|
Hi, back in 2016 I posted a thread asking for help with a script that voices/devoices users depending on their nick. Rather than spam this thread with the one I created in 2016, I'll just post a link: Voice/Devoice on Nickname Change mIRC to TCL
I'd like to first start by thanking, once again , the following people that helped me get the script up and running:
simo, caesar and willyw, cheers for your help. P.S, I think you pretty much wrote the script with very little to no input from me (so I can't really take any credit for doing anything what so ever).
Below is the script (after some modifications, no doubt that they are poor ones at that) that I'm currently using and I would like to make it a little bit more advanced, allowing me to add multiple 'inputs'/'criteria' and the ability to 'blacklist' specific nicks.
Code: |
bind join * * case:joined
bind nick * * case:nick
proc case:joined {nick uhost hand chan} {
# we trigger our special function to do the testing when someone just joined the channel
case:action $chan $nick
}
proc case:nick {nick uhost hand chan newnick} {
# we trigger our special function to do the testing when someone just changed his nick to a new one
case:action $chan $newnick
}
proc case:action {chan nick} {
# check if bot is the one that joined the channel and then check if he's a channel operator (has @)
if {[isbotnick $nick] || ![botisop $chan]} return
# we split the nick in sepatate elements (let's call them letters) and grab only the first one
set letter [lindex [split $nick ""] 0]
# we test if the letter we previously grabbed is in uppercase (result will be 1) or lowercase (result will be 0)
set test [string is upper $letter]
if {![string compare -length 4 "User" $nick]} {
set test 0
}
# if the result is 1 then proceed to the next step
if {$test} {
# test if the nick isn't already voiced
if {![isvoice $nick $chan]} {
# nick isn't already voiced so give him voice (+v)
pushmode $chan +v $nick
}
# the previous test failed thus we do something else in return
} else {
# test if nick has voice (+v) on the channel
if {[isvoice $nick $chan]} {
# and now we actually remove his voice (+v) status
pushmode $chan -v $nick
}
}
}
|
At the moment the bot voices any user that has a nick starting with a Capital letter (f.ex 'Dizmo') and then devoices any nick that have lowercase first letters (f.ex 'dizmo'). The bot also ignores anyone with a nick that starts with 'User' (f.ex 'User392823'), ignoring the capital letter and by not voicing said users.
I'd like to make it possible to add more 'variables', such as:
Code: |
if {![string compare -length 5 "Guest" $nick]} {
if {![string compare -length 6 "Andro|" $nick]} {
|
I've tried adding the above to the script (not just like that however the bot seems to only pick up on 'User' nicks).
Also I'd like to be able to blacklist specific users (just by adding the nicks manually to the script, it doesn't need to be anything fancy like a channel/msg command). This function will, hopefully, get the bot to ignore said user so that if they change their nick to uppercase, it won't voice them.
I would appreciate anyone’s expertise on this one, like before, I am extremely grateful for any help that anyone can offer.
Regards,
Dizmo. |
|
Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3690 Location: Mint Factory
|
Posted: Sat Apr 14, 2018 12:18 pm Post subject: |
|
|
1. Your string compare -length 4 "User" $nick doesn't seem to be working as you would expect:
Code: |
% set nick "User123"
User123
% string compare -length 4 "User" $nick
0
% set nick foo
foo
% string compare -length 4 "User" $nick
-1
|
so, instead should use something like:
Code: |
set test [string equal "User" [string range $nick 0 3]]
|
and results are:
Code: |
% string equal "User" [string range $nick 0 3]
1
% set nick foo
foo
% string equal "User" [string range $nick 0 3]
0
|
2. This code:
Code: |
if {![string compare -length 5 "Guest" $nick]} {
if {![string compare -length 6 "Andro|" $nick]} {
|
doesn't reach Andro part because it doesn't get past the first if check.
3. Grabbing the first "letter" from a nick means that nicks like "|Something" won't get voiced because the | is grabbed first, so instead of:
Code: |
set letter [lindex [split $nick ""] 0]
set test [string is upper $letter]
|
would be safer to go with:
Code: |
set test [regexp -all {[A-Z]} $nick]
|
If you got let's say a list of names that you want to check, for example User, Guest and Andro|, then something like this should do the job you are looking for:
Code: |
set match 0
foreach n [split $myList] {
set len [string length $n]
if {[string equal $n [string range $nick 0 [expr $len - 1]]]} {
incr match
break
}
}
|
Thus your code becomes:
Code: |
proc case:action {chan nick} {
if {[isbotnick $nick] || ![botisop $chan]} return
set match 0
set myList "User Guest Andro|"
foreach n [split $myList] {
set len [string length $n]
if {[string equal $n [string range $nick 0 [expr $len - 1]]]} {
incr match
break
}
}
if {$match} return
set test [regexp -all {[A-Z]} $nick]
if {$test} {
if {![isvoice $nick $chan]} {
pushmode $chan +v $nick
}
} else {
if {[isvoice $nick $chan]} {
pushmode $chan -v $nick
}
}
}
|
Haven't tested much so let me know if something is wrong.
Edit: As for a blacklist:
Code: |
set blacklist "Someone Something Another"
if {[lsearch -nocase $blacklist $nick]} return
|
before the set match 0 line should do the trick. _________________ Once the game is over, the king and the pawn go back in the same box. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|