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.

ban duration convert from: y-m-w-d-h to minute

Help for those learning Tcl or writing their own scripts.
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

ban duration convert from: y-m-w-d-h to minute

Post by simo »

greetz gents,

i was wondering how to edit the $time part as that has always to be in minutes using it with newchanban from what i understood to convert it
from year / month / week / day / hour to minutes

Code: Select all

bind pub o|o !addbl permanent_ban


proc permanent_ban {nick host hand chan text} {
    set text [stripcodes * $text]
    set target [lindex [split $text] 0]
    set time [lindex [split $text] 1]
    set reason [join [lrange [split $text] 2 end]]
    set items [split $text]
      if {[llength $items] < 3} { putnow "notice $nick :Syntax !addbl \<target\> \<banduration\> \<reason\>" ; return }
      if {![string is digit -strict $time]} { putnow "notice $nick :banduration must be in minutes digits 10 is 10 minutes and so on" ; return }
      if {$reason eq ""} { set reason "default reason"  }
     if {![string match -nocase $target $::botname]} {
     newchanban "$chan" "$target" "$nick" "$reason" $time sticky
 }
}
thanks in advance.
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

How do you intend to format the duration ?
something like 1y2m ? or +7d ?
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

For example lets say we wanne set:

!addbl *!*@some.host.here 1y2m some-reason
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

How many minutes in a month?
28 to 31 days:)
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: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

oh thats true forgot about that Spike^^ lets say we use days and weeks to counter that
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Short proc, not tested in situ:

Code: Select all

proc delay2min {delay} {
	regexp {((\d{1,})y)?((\d{1,})w)?((\d{1,})d)?((\d{1,})h)?} $delay - iy by iw bw id bd ih bh
	set min 0
	incr min [expr 365*24*60*$by]
	incr min [expr 7*24*60*$bw]
	incr min [expr 24*60*$bd]
	incr min [expr 60*$bh]
	return $min
}
The param must follow the order 1y2w3d4h (every values are optional), so you can use delay2min 1y17h or delay2min 52w1d but you CAN NOT do delay2min 1d2w
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Combined and cleaned up that might look something like...

Code: Select all

bind pub o|o !addbl permanent_ban

proc permanent_ban {nick host hand chan text} {
  set text [regsub -all -- {\s{2,}} [string trim [stripcodes * $text]] { }]
  set items [split $text]
  if {[llength $items] < 3} {
    putnow "notice $nick :Syntax !addbl <target> <banduration> <reason>" ;  return 0
  }

  set reason [join [lassign $items target time]]
  #if {$reason eq ""} {  set reason "default reason"  } ;# reason cant be empty:) #

  if {[matchaddr $target $::botname]} { return 0 }

  if {[matchstr permanent $time] || [matchstr perm $time] || [matchstr p $time]} {  set min 0
  } elseif {[string is digit -strict $time]} {  set min $time

  ### Thanks CrazyCat ###
  } else {  set min 0
    regexp {((\d{1,})y)?((\d{1,})w)?((\d{1,})d)?((\d{1,})h)?} $time - iy by iw bw id bd ih bh
    catch { incr min [expr {365*24*60*$by}] }
    catch { incr min [expr {7*24*60*$bw}] }
    catch { incr min [expr {24*60*$bd}] }
    catch { incr min [expr {60*$bh}] }
  }

  newchanban $chan $target $nick $reason $min sticky

  if {$min == 0} {  set dur "forever"
  } else {  set dur [duration [expr {60*$min}]]  }

  putnow "notice $nick :Added new sticky ban to the Eggdrop user file (duration: $dur)."
  return 0
}

<banduration> can be done in several ways:
a) 1y26w |or| 1d12h |or| other variations of 1y2w3d4h (in that order)(every values are optional)
b) any integer number (of minutes). example: 150 (= 150 minutes or 2 and a half hours)
c) perm |or| p |or| permanent |or| 0 (= a forever permanent ban)
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Why not just modify my regex to allow minutes:

Code: Select all

proc delay2min {delay} {
regexp {((\d{1,})y)?((\d{1,})w)?((\d{1,})d)?((\d{1,})h)?(\d{1,})?} $time - iy by iw bw id bd ih bh bm
set min 0
   incr min [expr 365*24*60*$by]
   incr min [expr 7*24*60*$bw]
   incr min [expr 24*60*$bd]
   incr min [expr 60*$bh]
   incr min [expr 1*$bm]
   return $min
}
If argument is only an integer, it's minutes.

So, new code is:

Code: Select all

bind pub o|o !addbl permanent_ban

proc permanent_ban {nick host hand chan text} {
  set text [regsub -all -- {\s{2,}} [string trim [stripcodes * $text]] { }]
  set items [split $text]
  if {[llength $items] < 3} {
    putnow "notice $nick :Syntax !addbl <target> <banduration> <reason>" ;  return 0
  }

  set reason [join [lassign $items target time]]
  #if {$reason eq ""} {  set reason "default reason"  } ;# reason cant be empty:) #

  if {[matchaddr $target $::botname]} { return 0 }

  if {[matchstr permanent $time] || [matchstr perm $time] || [matchstr p $time]} {
     set min 0
  } elseif {
     set min [delay2min $time]
  }
  if {![string is digit -strict $min]} {
     putnow "NOTICE $nick :Sorry, can't calculate delay"
     return
  }
 
  newchanban $chan $target $nick $reason $min sticky

  if {$min == 0} {  set dur "forever"
  } else {  set dur [duration [expr {60*$min}]]  }

  putnow "notice $nick :Added new sticky ban to the Eggdrop user file (duration: $dur)."
  return 0
}

proc delay2min {delay} {
regexp {((\d{1,})y)?((\d{1,})w)?((\d{1,})d)?((\d{1,})h)?(\d{1,})?} $time - iy by iw bw id bd ih bh bm
set min 0
   incr min [expr 365*24*60*$by]
   incr min [expr 7*24*60*$bw]
   incr min [expr 24*60*$bd]
   incr min [expr 60*$bh]
   incr min [expr 1*$bm]
   return $min
}
Last edited by CrazyCat on Tue Jan 18, 2022 3:56 am, edited 1 time in total.
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

tried your version Spike^^ but setting bans on nicks like [nick] doesnt seem to work proper it sets it as {[nick]}


tested your version as well CC same issue and gettin error:


08:51:55 <Hawk> [08:51:55] Tcl error [sticky_bansx]: invalid bareword "set"
08:51:55 <Hawk> in expression "
08:51:55 <Hawk> set min [delay2min $time]...";
08:51:55 <Hawk> should be "$set" or "{set}" or "set(...)" or ...
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

This may correct the two bugs (nick and improper set)

Code: Select all

bind pub o|o !addbl permanent_ban

proc permanent_ban {nick host hand chan text} {
	set text [regsub -all -- {\s{2,}} [string trim [stripcodes * $text]] { }]
	set items [split $text]
	if {[llength $items] < 3} {
		putnow "notice $nick :Syntax !addbl <target> <banduration> <reason>" ;  return 0
	}
	set reason [join [lassign $items target time]]
	#if {$reason eq ""} {  set reason "default reason"  } ;# reason cant be empty:) #
	if {[matchaddr $target $::botname]} { return 0 }
	if {[matchstr permanent $time] || [matchstr perm $time] || [matchstr p $time]} {
		set min 0
	} else {
		set min [delay2min $time]
	}
	if {![string is digit -strict $min]} {
		putnow "NOTICE $nick :Sorry, can't calculate delay"
		return
	}
	newchanban $chan [join $target] $nick [join $reason] $min sticky
	if {$min == 0} {
            set dur "forever"
	} else {
            set dur $min
	}
	putnow "notice $nick :Added new sticky ban to the Eggdrop user file (duration: $dur)."
	return 0
}

proc delay2min {delay} {
	regexp {((\d{1,})y)?((\d{1,})w)?((\d{1,})d)?((\d{1,})h)?(\d{1,})?} $delay - iy by iw bw id bd ih bh bm
	set min 0
	incr min [expr 365*24*60*$by]
	incr min [expr 7*24*60*$bw]
	incr min [expr 24*60*$bd]
	incr min [expr 60*$bh]
	incr min [expr 1*$bm]
	return $min
}
Last edited by CrazyCat on Tue Jan 18, 2022 5:12 am, edited 1 time in total.
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

tried your last post cc:

Tcl error [sticky_bans]: can't read "time": no such variable
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

your posted code seems to work well thanks Spike^^
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

My code is corrected (forget to replace time with delay in proc)
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

tested your latest code CC and got:

Tcl error [sticky_bansx]: missing operand at _@_
in expression "365*24*60*_@_"



ive edited it like this but it didnt seem to help as i still got error




Code: Select all

proc delay2min {delay} {
   regexp {((\d{1,})y)?((\d{1,})w)?((\d{1,})d)?((\d{1,})h)?(\d{1,})?} $delay - iy by iw bw id bd ih bh bm
   set min 0
   incr min [expr {365*24*60*$by}]
   incr min [expr {7*24*60*$bw}]
   incr min [expr {24*60*$bd}]
   incr min [expr {60*$bh}]
   incr min [expr {1*$bm}]
   return $min
}

Tcl error [sticky_bansx]: can't use empty string as operand of "*"
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i did some more testing with your code Spike^^ and found bug


when i do like : !addbl *!*@*.RU 1w uit testen

i get
Tcl error [permanent_ban]: bogus expire time
Post Reply