egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

voice for nick with non Cap 1st letter

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Draknon
Voice


Joined: 01 Apr 2018
Posts: 30

PostPosted: Sun Apr 01, 2018 8:29 am    Post subject: voice for nick with non Cap 1st letter Reply with quote

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:

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
  }
}
Back to top
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3459
Location: Area 51

PostPosted: Mon Apr 02, 2018 12:54 am    Post subject: Reply with quote

Code:

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.
_________________
You may say anything about me, but at least don't misspell my name. xD
Back to top
View user's profile Send private message
Draknon
Voice


Joined: 01 Apr 2018
Posts: 30

PostPosted: Tue Apr 03, 2018 6:26 am    Post subject: you are awesome Reply with quote

but, unfortunately it doesn't work at all Sad

I am trying to learn, but it isn't easy for me so I'm not sure where the issue is.
Back to top
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3459
Location: Area 51

PostPosted: Wed Apr 04, 2018 1:42 am    Post subject: Reply with quote

Here's the updated and tested code.
Code:

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:

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:

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:

set match [string equal [string index $newnick 0] [string index [string totitle $newnick] 0]]

could be:
Code:

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:

% 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

_________________
You may say anything about me, but at least don't misspell my name. xD
Back to top
View user's profile Send private message
Draknon
Voice


Joined: 01 Apr 2018
Posts: 30

PostPosted: Wed Apr 04, 2018 9:56 pm    Post subject: Reply with quote

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:
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.
Back to top
View user's profile Send private message
Draknon
Voice


Joined: 01 Apr 2018
Posts: 30

PostPosted: Sun Apr 08, 2018 3:41 am    Post subject: Reply with quote

ok, new information ...

Code:
#
#  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 ..
Quote:
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??
Back to top
View user's profile Send private message
Draknon
Voice


Joined: 01 Apr 2018
Posts: 30

PostPosted: Mon Apr 09, 2018 1:55 am    Post subject: Reply with quote

got this all set and working .. thanks for all the help
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
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


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber