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 for nick with non Cap 1st letter

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
D
Draknon
Voice
Posts: 30
Joined: Sun Apr 01, 2018 8:24 am

voice for nick with non Cap 1st letter

Post by Draknon »

I currently have this for an mIRC bot.. would like to have it for eggdrop bot so need it in tlc. any help would be appreciated..

Code: Select all

alias -l _c return #The-Dungeon
alias startwithupper {
  if ( $1 ) {
    return $isupper($left($regsubex($$1,/\W+/g,$null),1))
  }
  else return $false
}

on @*:JOIN:#The-Dungeon:{
  if ( $startwithupper($nick) == $false ) {
    mode $_c +v $nick
  }
}

on @*:NICK:{
  if ( ( $startwithupper($newnick) == $false ) && ( $newnick !isvoice $_c ) ) {
    ; New nick is with upper case and previous is unvoiced
    mode $_c +v $newnick
  }
  if ( ( $startwithupper($newnick) == $true ) && ( $newnick isvoice $_c ) ) {
    ; New nick is with lower case and previous is voiced
    mode $_c -v $newnick
  }
}
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

namespace eval NickCase {

	set channel "#The-Dungeon"

	bind join - * [namespace current]::joined
	bind nick - * [namespace current]::nick

	proc joined {nick uhost hand chan} {
		if {[isbotnick $nick] || [botisop $chan]} return
		variable channel
		if {![string match -nocase $chan $channel]} return
		if {![string equal $nick [string totitle $nick]]} {
			pushmode $chan +v $nick
		}
	}
	
	proc nick {nick uhost hand chan newnick} {
		if {[isbotnick $nick] || [botisop $chan]} return
		variable channel
		if {![string match -nocase $chan $channel]} return
		if {[isvoice $newnick $chan]} {
			if {[string equal $newnick [string totitle $newnick]]} {
				pushmode $chan -v $newnick
			}
		} else {
			if {![string equal $newnick [string totitle $newnick]]} {
				pushmode $chan +v $newnick
			}
		}
	}
}
Haven't tested anything so let me know if doesn't work.
Once the game is over, the king and the pawn go back in the same box.
D
Draknon
Voice
Posts: 30
Joined: Sun Apr 01, 2018 8:24 am

you are awesome

Post by Draknon »

but, unfortunately it doesn't work at all :(

I am trying to learn, but it isn't easy for me so I'm not sure where the issue is.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Here's the updated and tested code.

Code: Select all

namespace eval NickCase {
	
	set channel "#The-Dungeon"
	bind join - * [namespace current]::joined
	bind nick - * [namespace current]::nick

	proc joined {nick uhost hand chan} {
		if {[isbotnick $nick] || ![botisop $chan]} return
		variable channel
		if {![string match -nocase $chan $channel]} return
		if {![string equal $nick [string totitle $nick]]} {
			pushmode $chan +v $nick
		}
	}
   
	proc nick {nick uhost hand chan newnick} {
		if {[isbotnick $nick] || ![botisop $chan]} return
		variable channel
		if {![string match -nocase $chan $channel]} return
		set match [string equal [string index $newnick 0] [string index [string totitle $newnick] 0]]
		if {[isvoice $nick $chan]} {
			if {$match} {
				pushmode $chan -v $newnick
			}
		} else {
			if {!$match} {
				pushmode $chan +v $newnick
			}
		}
	}
}
The main issue was because of botisop part in:

Code: Select all

if {[isbotnick $nick] || [botisop $chan]} return
that basically means if the bot is channel operator then it would stop executing anything past this line, when in fact wanted to stop the execution only if the bot wasn't channel operator, hence the ! in front of the [botisop $chan] in above "updated" code.

The second issue I've discovered is that string totitle on it's own wasn't enough because it turns SomeNick into Somenick and the previous test:

Code: Select all

if {[string equal $newnick [string totitle $newnick]]} { 
basically will test if SomeNick is now equal with Somenick and will fail. So, instead I now take the first letter of the new nick and compare it with the first letter from string totitle result.

An alternative to:

Code: Select all

set match [string equal [string index $newnick 0] [string index [string totitle $newnick] 0]] 
could be:

Code: Select all

set match [expr [regexp -all {[A-Z]} $newnick]]
but in a 1000 iterations test the string equal one seems slightly faster, even if it's ugly.

Code: Select all

% time {for {set i 0} {$i < 1000} {incr i} { append mylist [regexp -all {[A-Z]} $newnick] }}
1731 microseconds per iteration
% time {for {set i 0} {$i < 1000} {incr i} { append mylist [string equal [string index $newnick 0] [string index [string totitle $newnick] 0]] }}
1425 microseconds per iteration
Once the game is over, the king and the pawn go back in the same box.
D
Draknon
Voice
Posts: 30
Joined: Sun Apr 01, 2018 8:24 am

Post by Draknon »

ok, I copy and pasted the new and it is still not working..

I think I kinda understand what some things are supposed to do..

can we just get rid of the ...

Code: Select all

if {[isbotnick $nick] || ![botisop $chan]} return
and just expect that the bot is an op, because it is.

and sorry, I didn't explain what the original actually does...

if someone comes into channel and the nick first letter is lowercase then that person gets the +v and if they have a Capped nick then nothing and if a nick changes the upper/lower case of the first letter than either +v or -v depending on which they do.. and if nick starts with a non alpha like { or [ or some such then it looks for the first actual alpha character and works from that.
D
Draknon
Voice
Posts: 30
Joined: Sun Apr 01, 2018 8:24 am

Post by Draknon »

ok, new information ...

Code: Select all

#
#  Script: sub voice
#


namespace eval NickCase {
   
   set channel "#The-Dungeon"
   bind join - * [namespace current]::joined
   bind nick - * [namespace current]::nick_chk

   proc joined {nick uhost hand chan} {
      variable channel
      if {![string match -nocase $chan $channel]} return
      if {![string equal $nick [string totitle $nick]]} {
         pushmode $chan +v $nick
      }
   }
   
   proc nick_chk {nick uhost hand chan newnick} {
      variable channel
      if {![string match -nocase $chan $channel]} return
       set match {expr [regexp -all {[A-Z]} $newnick]}
      if {[isvoice $nick $chan]} {
         if {$match} {
            pushmode $chan -v $newnick
         }
      } else {
         if {!$match} {
            pushmode $chan +v $newnick
         }
      }
   }
} 


putlog "sub voice loaded"
Error msg is ..
Tcl error [::NickCase::nick_chk]: expected boolean value but got "expr [regexp -all {[A-Z]} $newnick]"
on top of fixing this can someone please explain to me what the error means??
D
Draknon
Voice
Posts: 30
Joined: Sun Apr 01, 2018 8:24 am

Post by Draknon »

got this all set and working .. thanks for all the help
Post Reply