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 

ban duration convert from: y-m-w-d-h to minute
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Mon Jan 17, 2022 4:53 pm    Post subject: ban duration convert from: y-m-w-d-h to minute Reply with quote

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:

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.
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Mon Jan 17, 2022 5:23 pm    Post subject: Reply with quote

How do you intend to format the duration ?
something like 1y2m ? or +7d ?
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Mon Jan 17, 2022 5:28 pm    Post subject: Reply with quote

For example lets say we wanne set:

!addbl *!*@some.host.here 1y2m some-reason
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Mon Jan 17, 2022 5:47 pm    Post subject: Reply with quote

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
.
Back to top
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Mon Jan 17, 2022 6:25 pm    Post subject: Reply with quote

oh thats true forgot about that Spike^^ lets say we use days and weeks to counter that
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Mon Jan 17, 2022 7:21 pm    Post subject: Reply with quote

Short proc, not tested in situ:
Code:
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
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Tue Jan 18, 2022 3:11 am    Post subject: Reply with quote

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

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
.
Back to top
View user's profile Send private message Visit poster's website
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Tue Jan 18, 2022 3:24 am    Post subject: Reply with quote

Why not just modify my regex to allow minutes:
Code:
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:
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
}

_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.


Last edited by CrazyCat on Tue Jan 18, 2022 3:56 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Tue Jan 18, 2022 3:38 am    Post subject: Reply with quote

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 ...
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Tue Jan 18, 2022 4:00 am    Post subject: Reply with quote

This may correct the two bugs (nick and improper set)
Code:
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
}

_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.


Last edited by CrazyCat on Tue Jan 18, 2022 5:12 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Tue Jan 18, 2022 4:28 am    Post subject: Reply with quote

tried your last post cc:

Tcl error [sticky_bans]: can't read "time": no such variable
Back to top
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Tue Jan 18, 2022 4:36 am    Post subject: Reply with quote

your posted code seems to work well thanks Spike^^
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Tue Jan 18, 2022 5:12 am    Post subject: Reply with quote

My code is corrected (forget to replace time with delay in proc)
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Wed Jan 19, 2022 12:48 am    Post subject: Reply with quote

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:

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 "*"
Back to top
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Wed Jan 19, 2022 12:56 am    Post subject: Reply with quote

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


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

i get

Quote:
Tcl error [permanent_ban]: bogus expire time
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 -> Scripting Help All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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