This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Voice/Devoice on Nick Change With Multiple 'Variables'?

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
D
Dizmo
Voice
Posts: 6
Joined: Fri Apr 01, 2016 2:18 pm

Voice/Devoice on Nick Change With Multiple 'Variables'?

Post by Dizmo »

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: Select all

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: Select all

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.
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

1. Your string compare -length 4 "User" $nick doesn't seem to be working as you would expect:

Code: Select all

% 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: Select all

set test [string equal "User" [string range $nick 0 3]]
and results are:

Code: Select all

% 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: Select all

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: Select all

set letter [lindex [split $nick ""] 0]
set test [string is upper $letter] 
would be safer to go with:

Code: Select all

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: Select all

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: Select all

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: Select all

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.
Post Reply