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.

Snotice shun

Help for those learning Tcl or writing their own scripts.
b
bwkzb
Voice
Posts: 16
Joined: Sun Mar 12, 2017 4:26 am

Snotice shun

Post by bwkzb »

bind raw - *Shun added for* NOTICE snotice
proc snotice {from keyword arg} {
if {![string match -nocase "*shun added for:*" $arg]} { return }
set nick [lindex [lindex [split $arg :] 1] 0]
putserv "privmsg #shuned $arg"
}


bind pub o !shun pub:shun
proc pub:shun {nick host hand chan text} {
global botnick channels
if {[llength $text] < 1} { putserv "privmsg $channels $nick: Used !shun nick +tiempo razón"
return 0
}
set channels "#shuned"
set target [lindex $text 0]
set tiempo [lindex $text 1]
set reason [lrange $text 2 end]
if {($target != "")} {
putquick "shun $target $tiempo $reason"
} else {
if {($target == "")} {
putquick "shun $target $tiempo $reason"

return 0
}
return 0
}
}


<user1> !shun user2 +1h test

the code is fine but the SNOTICE message does not appear on the channel when the command !shun nick time reason is used

I would like it to stay like this

<user1> !shun user2 +1h test
<botnick> -NOTICE- *** Shun added for *@host.de on Fri Aug 5 00:33:30 2022 GMT (from botnick!bot@bot.tk to expire at Fri Aug 5 01:33:30 2022 GMT: test)

please help me thank you
s
simo
Revered One
Posts: 1108
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

On which ircd version did you use this so i can test it to figure whats wrong with the code as i run several test ircds myself
b
bwkzb
Voice
Posts: 16
Joined: Sun Mar 12, 2017 4:26 am

Post by bwkzb »

I use it in unrealircd 5.2.4

thanks for answer :D
s
simo
Revered One
Posts: 1108
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

tested this seems to work for me:

Code: Select all

bind raw - notice shun-snotice

proc shun-snotice {from keyword arg} {
 if {![string match -nocase "*shun added*" $arg]} { return }
   set shun [lrange $arg 1 end]
   putserv "privmsg #shuned :$shun"
}


bind pub o !shun pub:shun

proc pub:shun {nick host hand chan text} {
global botnick 
   if {[llength $text] < 1} { putserv "privmsg $channels $nick: Used !shun nick +tiempo razón"
  return 0
}
  set target [lindex $text 0]
  set tiempo [lindex $text 1]
  set reason [lrange $text 2 end]
 if {($target != "")} { 
   putquick "shun $target $tiempo $reason"
} else {
 putquick "shun $target :$tiempo $reason"
  return 0
}
}

Last edited by simo on Fri Aug 05, 2022 5:08 am, edited 2 times in total.
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Really strange:

Code: Select all

 if {($target != "")} {
   putquick "shun $target $tiempo $reason"
} else {
 if {($target == "")} {

 putquick "shun $target :$tiempo $reason"
}
Simplification:

Code: Select all

 if {($target != "")} {
   putquick "shun $target $tiempo $reason"
} else {
   putquick "shun $target :$tiempo $reason"
}
When in the else ($target is empty), $tiempo and $reason are empty too (as $target is the first element of $text), and the shun will alway fail.
BTW, $target can never be empty as the first check is to ensure that $text has at least 1 element.
s
simo
Revered One
Posts: 1108
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

Thanks for pointing that out CrazyCat
s
simo
Revered One
Posts: 1108
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

slightly revised in the case of nicks with chars like {} in it and added protection for channel admins / ops and those with bot flag o and with pre filled reason and ban duration if not given

Code: Select all


bind raw - notice shun-snotice

proc shun-snotice {from keyword arg} {
 if {![string match -nocase "*shun added*" $arg]} { return }
   set shun [lrange $arg 1 end]
   putserv "privmsg #shuned :$shun"
}


bind pub o !shun pub:shun

proc pub:shun {nick host hand chan text} {
  set text [regsub -all -- {\s{2,}} [string trim [stripcodes * $text]] { }]
  set text [split $text] 
  set target [lindex $text 0]
  set tiempo [lindex $text 1]
  set reason [lrange $text 2 end]
  set items [split $text]
   if {[llength $items] < 1} { putnow "NOTICE $nick :Syntax\: !shun nick" ; return }

  if {$tiempo eq ""} { set tiempo "1h"  }
  if {$reason eq ""} { set reason "$tiempo shun for abuse/behaviour"  }


if {![onchan $target $chan]} {
                putnow "NOTICE $nick $target is not on $chan"
  }  else {
    if {![isbotnick $target] && ![isbotnick $target] && ![isop $target $chan] && ![ishalfop $target $chan] && ![matchattr [nick2hand $target $chan] o|o $chan]} { 
    putquick "shun $target $tiempo $reason" 
     }
   }
}

 
s
simo
Revered One
Posts: 1108
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

anyway we can determine if $tiempo is in the syntax of 12h 1d 1m 1y

and $reason to be in alpha/numeric in my last posted code ?


because now when used like !shun nick some reason it wont work proper
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

!shun nick duration reason

Post by SpiKe^^ »

Code: Select all

bind raw - notice shun-snotice

proc shun-snotice {from keyword arg} {
 if {![string match -nocase "*shun added*" $arg]} { return }
   set shun [lrange $arg 1 end]
   putserv "privmsg #shuned :$shun"
}


bind pub o !shun pub:shun

proc pub:shun {nick host hand chan text} {
  set text [regsub -all -- {\s{2,}} [string trim [stripcodes * $text]] { }]
  set text [split $text]
  if {![llength $text]} { putnow "NOTICE $nick :Syntax\: !shun nick" ; return 0 }

  set target [lindex $text 0]
  if {![onchan $target $chan]} { putnow "NOTICE $nick :$target is not on $chan" ; return 0 }

  if {[isbotnick $target] || [isop $target $chan] || [ishalfop $target $chan]} { return 0 }
  if {[matchattr [nick2hand $target $chan] o|o $chan]} { return 0 }

  set tiempo [lindex $text 1]
  set reason [join [lrange $text 2 end]]

  if {$tiempo ne "" && ![regexp -nocase {^[1-9][0-9]*[hdmy]$} $tiempo]} {
    set reason [string trim "$tiempo $reason"]
    set tiempo ""
  }

  if {$tiempo eq ""} { set tiempo "1h"  }
  if {$reason eq ""} { set reason "$tiempo shun for abuse/behaviour"  }

  putquick "shun $target $tiempo $reason"
  return 0
}

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
s
simo
Revered One
Posts: 1108
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanks SpiKe^^ i tried your posted code with like:
!shun Finn 10s
wich resulted in :
*** Shun added for *@184.178.172.25 on Sun Aug 7 00:08:38 2022 GMT (from &Falcon!F@127.0.0.1 to expire at Sun Aug 7 01:08:38 2022 GMT: 10s)
so the reason wasnt filled in only the targetnick and duration but still the default duration of 1 hour was used while we filled 10 seconds in and the default reason wasnt used since it wasnt filled in not sure why
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

You didn't specify #s in your example....
$tiempo is in the syntax of 12h 1d 1m 1y
Adjust the regexp to cover what you see as all the choices...

Code: Select all

{^[1-9][0-9]*[hdmy]$}
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
s
simo
Revered One
Posts: 1108
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

oh thanks SpiKe^^ i overlooked that part after consulting help file for shun on the ircd i found the actual syntax that is used by the ircd and i inserted that in the below code thanks again SpiKe^^.

Final code is :

Code: Select all


bind raw - notice shun-snotice

proc shun-snotice {from keyword arg} {
 if {![string match -nocase "*shun added*" $arg]} { return }
   set shun [lrange $arg 1 end]
   putserv "privmsg #shuned :$shun"
}


bind pub o !shun pub:shun

proc pub:shun {nick host hand chan text} {
  set text [regsub -all -- {\s{2,}} [string trim [stripcodes * $text]] { }]
  set text [split $text]
  if {![llength $text]} { putnow "NOTICE $nick :Syntax\: !shun nick" ; return 0 }

  set target [lindex $text 0]
  if {![onchan $target $chan]} { putnow "NOTICE $nick :$target is not on $chan" ; return 0 }

  if {[isbotnick $target] || [isop $target $chan] || [ishalfop $target $chan]} { return 0 }
  if {[matchattr [nick2hand $target $chan] o|o $chan]} { return 0 }

  set tiempo [lindex $text 1]
  set reason [join [lrange $text 2 end]]

  if {$tiempo ne "" && ![regexp -nocase {^[1-9][0-9]*[dhms]$} $tiempo]} {
    set reason [string trim "$tiempo $reason"]
    set tiempo ""
  }

  if {$tiempo eq ""} { set tiempo "1h"  }
  if {$reason eq ""} { set reason "$tiempo shun for abuse/behaviour"  }

  putquick "shun $target $tiempo $reason"
  return 0
}
s
simo
Revered One
Posts: 1108
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

oh 1 last thing since shun command also provides option to set a permanent shun but that is set with durarion of just 0 without any additional param anyway we can incorporate that ?
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Replace this line in the code...

Code: Select all

  if {$tiempo ne "" && ![regexp -nocase {^[1-9][0-9]*[dhms]$} $tiempo]} {
With something more like this...

Code: Select all

  if {$tiempo ne "" && ![regexp -nocase {^[1-9][0-9]*[dhms]$} $tiempo] && $tiempo != 0} {
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
s
simo
Revered One
Posts: 1108
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanks SpiKe^^ that seems to do it

final code for those that need it :

Code: Select all

bind raw - notice shun-snotice

proc shun-snotice {from keyword arg} {
 if {![string match -nocase "*shun added*" $arg]} { return }
   set shun [lrange $arg 1 end]
   putserv "privmsg #shuned :$shun"
}


bind pub o !shun pub:shun

proc pub:shun {nick host hand chan text} {
  set text [regsub -all -- {\s{2,}} [string trim [stripcodes * $text]] { }]
  set text [split $text]
  if {![llength $text]} { putnow "NOTICE $nick :Syntax\: !shun nick" ; return 0 }

  set target [lindex $text 0]
  if {![onchan $target $chan]} { putnow "NOTICE $nick :$target is not on $chan" ; return 0 }

  if {[isbotnick $target] || [isop $target $chan] || [ishalfop $target $chan]} { return 0 }
  if {[matchattr [nick2hand $target $chan] o|o $chan]} { return 0 }

  set tiempo [lindex $text 1]
  set reason [join [lrange $text 2 end]]

  if {$tiempo ne "" && ![regexp -nocase {^[1-9][0-9]*[dhms]$} $tiempo] && $tiempo != 0} {
    set reason [string trim "$tiempo $reason"]
    set tiempo ""
  }

  if {$tiempo eq ""} { set tiempo "1h"  }
  if {$reason eq ""} { set reason "$tiempo shun for abuse/behaviour"  }

  putquick "shun $target $tiempo $reason"
  return 0
}
Post Reply