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 

Need help hacking pkb.tcl by SpiKe^^
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: Sat Feb 05, 2022 6:39 pm    Post subject: Reply with quote

hey there again Spike^^ i tried running this on dalnet but !k and !kick doesnt seem to trigger and i get no error

!b !ban !kb seems to work



Code:

bind pub -|- !kick pub:kick
bind pub -|- !k pub:kick
bind pub -|- .k pub:kick
proc pub:kick {nk uh hn ch tx} {  pub:kickban $nk $uh $hn $ch $tx k  }

bind pub -|- !ban pub:ban
bind pub -|- !b pub:ban
bind pub -|- .b pub:ban
proc pub:ban {nk uh hn ch tx} {  pub:kickban $nk $uh $hn $ch $tx b  }


bind pub -|- !unban pub:unban
bind pub -|- !ub pub:unban
proc pub:unban {nk uh hn ch tx} {  pub:kickban $nk $uh $hn $ch $tx ub  }


bind pub -|- !kickban pub:kickban
bind pub -|- !kban pub:kickban
bind pub -|- !kb pub:kickban
bind pub -|- .kb pub:kickban

proc pub:kickban {nk uh hn ch tx {do kb} } {
  global pkb storehosts

set pkb(kreason)  "Reason\: Requested. Kicked By\: $nk [strftime {[%A %d %b %Y - %I:%M:%S %p %Z]}]"
set pkb(kbreason) "Reason\: Requested. Kicked By\: $nk [strftime {[%A %d %b %Y - %I:%M:%S %p %Z]}]"

 

  if {$uh ne "Timer" && ![is:allowed $nk $hn $ch]} {  return 0  }
 
if {$do eq "k" || $do eq "kb" || $do eq "kick" || $do eq "kickban" || $do eq "kban"} {
    if {[llength [set temp [split $tx]]]>1 && ![matchstr ".*" [lindex $temp 1]]} {
      set tx "[lindex $temp 0] .[join [lrange $temp 1 end]]"
    }
  }


set kxtimestamp [strftime {[%A %d %b %Y - %I:%M:%S %p %Z]}]


  set reason [string trim $pkb(kreason)]
  if {$do eq "kb"} {  set reason [string trim $pkb(kbreason)]  }

  if {[set idx [string first " ." $tx]] > -1} {
    set txls [split [string trim [string range $tx 0 $idx]]]
    set reason "Reason\: [string trim [string range $tx [incr idx 2] end]] --- Kicked By\: $nk --- [strftime {[%A %d %b %Y - %I:%M:%S %p %Z]}]"
    #set reason [string trim [string range $tx [incr idx 2] end]]
  } else {  set txls [split [string trim $tx]]  }

  set mmpre $pkb(mute_maskpre)


  set nickls ""  ;  set tchan ""
  foreach item $txls {
    if {[string match "#*" $item]} {
      if {[lsearch -nocase $tchan $item] == -1} {  lappend tchan $item  }
    } elseif {[string is digit -strict $item]} {  set btime $item

} elseif {[string match {[+%]?*} $item]} {
      lappend nickls [string trimleft $item "+%"]
    } elseif {[string match "@?*" $item] && ![string match {*[.:]*} $item]} {
      lappend nickls [string trimleft $item "@"]

    } elseif {[string match {*[!@]*} $item]} {
      if {[string match u* $do]} {  set orig $item  }

      set item [regsub -all -- {\*{2,}} $item {*}]
      set len [llength [set ils [split $item "!@"]]]

      if {$len == 2} {   incr len ; {  set ils [linsert $ils 0 "*"]  }   }

      if {$len == 3} {   lassign $ils n u h
        if {$n eq $mmpre} {  set n "${n}*"
        } elseif {$n eq ""} {  set n "*"  }
        if {$u eq ""} {  set u "*"  }
        if {$h eq ""} {  set h "*"  }
        set bmask $n!$u@$h
      } else {  set bmask $item  }

      if {![string match u* $do]} {
        if {$len > 3 || $bmask eq "*!*@*" || $bmask eq "$mmpre*!*@*"} {
          putserv "NOTICE $nk :Error: $item is not a valid user mask."
        } else {  lappend nickls $bmask  }
      } else {
        if {$bmask eq $orig} {  lappend nickls $orig
        } else {  lappend nickls "$orig $bmask"  }
      }

    } elseif {$item ne ""} {  lappend nickls $item  }
  }

  if {$tchan ne ""} {

    foreach c $tchan {
      if {![validchan $c]} {
        putserv "NOTICE $nk :Error: $c is not a valid channel."
      } elseif {[lsearch -nocase $pkb(admin_chan) $c] > -1} {
        putserv "NOTICE $nk :Error: You can't target an admin channel: $c."
      } elseif {![is:allowed $nk $hn $c]} {
        putserv "NOTICE $nk :Error: You don't have proper permissions in $c."
      } else {  lappend chlist $c  }
    }

  } elseif {[lsearch -nocase $pkb(admin_chan) $ch] > -1} {

    if {![llength $pkb(main_chan)]} {
      putserv "NOTICE $nk :No default channel set. You must specify a channel."
    } else {
      foreach c $pkb(main_chan) {
        if {![validchan $c]} {
          putserv "NOTICE $nk :Error: $c is not a valid channel."
        } elseif {[lsearch -nocase $pkb(admin_chan) $c] > -1} {
          putserv "NOTICE $nk :Error: (main_chan) can't target an admin channel: $c."
        } else {  lappend chlist $c  }
      }
    }

  } else {  lappend chlist $ch  }


  if {![info exists chlist]} {  return 0  }

  if {![llength $nickls]} {
    putserv "NOTICE $nk :Error: You must specify at least one nick or user mask."
    return 0
  }

  if {[string match u* $do]} {  set plus "-"  } else {  set plus "+"  }

  set seconds 0
  if {[info exists btime]} {
    if {[string match {[bm]} $do] || ($do eq "kb")} {
      set seconds [expr {$btime * 60}]
    }
  } elseif {$do eq "m"} {  set seconds [expr {$pkb(m_mutetime) * 60}]
  } elseif {$do eq "b"} {  set seconds [expr {$pkb(b_bantime) * 60}]
  } elseif {$do eq "kb"} { set seconds [expr {$pkb(kb_bantime) * 60}]  }

  set masktype $pkb(ban_masktype)
  if {[string match *m $do]} {  set masktype $pkb(mute_masktype)  }


  ##  Begin  :  foreach ch $chlist  ####
  foreach ch $chlist {
    if {[info exists userls]} {  unset userls  }
    set bmasks ""  ;  set knicks ""  ;  set dvnicks ""

    foreach nick [lsort -unique -nocase $nickls] {
      set bmask ""

      ############  Begin:  if  [string match {*[!@]*} $nick]  #################
      if {[string match {*[!@]*} $nick]} {
        set bmask $nick  ;  set nick ""

        if {[string match u* $do]} {  set got 0  ;  set bmls [split $bmask]

          foreach bmask $bmls {
            if {($do eq "um") && ![string match $mmpre* $bmask]} {
              set bmask $mmpre$bmask
            }
            if {[ischanban $bmask $ch]} {   incr got
              if {[lsearch -nocase $bmasks $bmask] == -1} {  lappend bmasks $bmask  }
            }
          }

          if {$uh ne "Timer" && $got == 0} {
            putserv "NOTICE $nk :[lindex $bmls 0] is not a current ban on $ch"
          }
          continue
        }


        if {![info exists userls]} {  set clist [chanlist $ch]
          foreach n $clist {
            lappend userls [string tolower $n![getchanhost $n $ch]]
          }
          foreach {aname avalue} [array get storehosts [string tolower *@$ch]] {
            set x [lindex [split $aname @] 0]![string tolower [lindex $avalue 0]]
            if {$x ni $userls} {  lappend userls $x  }
          }
        }

        set m $bmask
        if {$mmpre ne "" && [string match $mmpre* $m]} {
          set m [string range $m [string length $mmpre] end]
        }
        set ok ""  ;  set err ""

        foreach user $userls {
          #set user "[string trimleft $user "@+"]"
          if {[matchaddr $m $user]} {  lassign [split $user !@] n u h
            if {[onchan $n $ch]} {  set hand [nick2hand $n $ch]
              if {[is:exempt $n $hand $ch]} {  set err $n  ;  break  }
              lappend ok $n
            } else {  set aname [string tolower "$n@$ch"]
              if {![info exists storehosts($aname)]} { continue }
              if {[lindex $storehosts($aname) 3] == 1} {  set err $n ;  break  }
              lappend ok $n
            }
          }
        }

        if {$err ne ""} {
          putserv "NOTICE $nk :You can't target an exempt user on $ch: $err ($u@$h)"
          continue
        }

        if {[string match {*[bm]} $do]} {
          if {$do eq "m" || [string match $mmpre* $bmask]} {  set m $mmpre$m  }

          if {[ischanban $m $ch]} {
            putserv "NOTICE $nk :$m is already an active ban on $ch"
          } elseif {[lsearch -nocase $bmasks $m] == -1} {  lappend bmasks $m  }

          if {$do ne "kb"} {
            foreach n $ok {
              if {[isvoice $n $ch] && [lsearch -nocase $dvnicks $n] == -1} {
                lappend dvnicks $n
              }
            }
          }
        }

        if {[string match k* $do]} {
          foreach n $ok {
            if {[onchan $n $ch] && [lsearch -nocase $knicks $n] == -1} {
              lappend knicks $n
            }
          }
        }

        continue
      } ;############  END:  if  [string match {*[!@]*} $nick]  ################
     

      set aname [string tolower "$nick@$ch"]

      if {[onchan $nick $ch]} {
        set chost [getchanhost $nick $ch]
        set hand [nick2hand $nick $ch]
        set exempt [is:exempt $nick $hand $ch]

      } elseif {[info exists storehosts($aname)] && ($do ne "k")} {
        lassign $storehosts($aname) chost expire hand exempt

      } else {  putserv "NOTICE $nk :[bold] \00308,04 $nick [bold][white] is not on channel [bold][cyan] $ch [end]" ;  continue  }

      if {$exempt == 1} {
        putserv "NOTICE $nk :You can't target an exempt user on $ch: $nick ($chost)"
        continue
      }

      if {[string match u* $do]} {  set found 0

        foreach binfols [chanbans $ch] {   set ban [lindex $binfols 0]
          if {$do eq "um" && ![string match $mmpre* $ban]} { continue }
          set m $ban
          if {$mmpre ne "" && [string match $mmpre* $m]} {
            set m [string range $m [string length $mmpre] end]
          }
          if {[matchaddr $m $nick!$chost]} {  incr found
            if {[lsearch -nocase $bmasks $ban] == -1} {  lappend bmasks $ban  }
          }
        }

        if {$found == 0} {
          if {$do eq "um"} {  set x "mutes"  } else {  set x "bans"  }
          putserv "NOTICE $nk :No $x found for $nick on $ch"
        }
        continue
      }

      if {[string match {*[bm]} $do]} {
        set bmask [mask:host $nick $chost $masktype $do]

        if {[ischanban $bmask $ch]} {
          putserv "NOTICE $nk :$bmask \[$nick\] is already a ban on $ch"
        } elseif {[lsearch -nocase $bmasks $bmask] == -1} {  lappend bmasks $bmask  }

        if {($do ne "kb") && [isvoice $nick $ch]} {
          if {[lsearch -nocase $dvnicks $nick] == -1} {  lappend dvnicks $nick  }
        }
      }

      if {[string match k* $do] && [onchan $nick $ch]} {
        if {[lsearch -nocase $knicks $nick] == -1} {  lappend knicks $nick  }
      }
    }


    if {$dvnicks ne ""} {
      while {[set len [llength $dvnicks]] > 0} {
        if {$len > $pkb(maxban)} {
          set mode [string repeat "v" $pkb(maxban)]
          set nicks [join [lrange $dvnicks 0 [expr {$pkb(maxban) - 1}]]]
          set dvnicks [lrange $dvnicks $pkb(maxban) end]
        } else {
          set mode [string repeat "v" $len]
          set nicks [join $dvnicks]
          set dvnicks ""

          if {$pkb(mix_mode) != 0 && $len < $pkb(maxban) && $bmasks ne ""} {
            if {($len + [set blen [llength $bmasks]]) <= $pkb(maxban)} {
              set mode ${mode}+[string repeat "b" $blen]
              set nicks "$nicks [join $bmasks]"
              set bmasks ""
            }
          }

        }
        putnow "MODE $ch -$mode $nicks"
      }
    }
    if {$bmasks ne ""} {

      if {$seconds > 0} {
        utimer $seconds [list pub:kickban $nk Timer $hn $ch [join $bmasks] ub]
      }

 
    if {$knicks ne ""} {
      while {[set len [llength $knicks]] > 0} {
        if {$len > $pkb(maxkick)} {
          set nicks [join [lrange $knicks 0 [expr {$pkb(maxkick) - 1}]] ","]
          set knicks [lrange $knicks $pkb(maxkick) end]
        } else {
          set nicks [join $knicks ","]
          set knicks ""
        }
        if {$reason eq ""} {  putnow "KICK $ch $nicks :$reason"
        } else {  putnow "KICK $ch $nicks :$reason"  }
      }
    }

      while {[set len [llength $bmasks]] > 0} {
        if {$len > $pkb(maxban)} {
          set mode [string repeat "b" $pkb(maxban)]
          set masks [join [lrange $bmasks 0 [expr {$pkb(maxban) - 1}]]]
          set bmasks [lrange $bmasks $pkb(maxban) end]
        } else {
          set mode [string repeat "b" $len]
          set masks [join $bmasks]
          set bmasks ""
        }
        putnow "MODE $ch $plus$mode $masks"
      }
    }

  } ;##  END  :  foreach ch $chlist  ####

}


set pkb(admin_chan) [split [string trim $pkb(admin_chan)] ", "]
set pkb(admin_chan) [lsort -unique -nocase $pkb(admin_chan)]

set pkb(main_chan) [split [string trim $pkb(main_chan)] ", "]
set pkb(main_chan) [lsort -unique -nocase $pkb(main_chan)]


#### code for who is allowed to use the public commands

proc is:allowed {nk hn ch} {
  if {[isop $nk $ch] || [ishalfop $nk $ch] || [matchattr $hn o|o $ch]} { return 1 }

  foreach achan $::pkb(admin_chan) {
    if {[validchan $achan] && [onchan $nk $achan]} { return 1 }
  }
  return 0
}

#### code for who is exempt from the public commands

proc is:exempt {nk hn ch} {
  if {[isop $nk $ch] || [ishalfop $nk $ch]} { return 1 }
  if {[isbotnick $nk] || [matchattr $hn bo|bo $ch]} { return 1 }

  foreach achan $::pkb(admin_chan) {
    if {[validchan $achan] && [onchan $nk $achan]} { return 1 }
  }
  return 0
}


#### protected hosts & mask hosts code

set pkb(phosts) [split [string trim $pkb(phosts)]]

proc mask:host {nick chost masktype do} {
  set bmask [maskhost "$nick!$chost" $masktype]
  foreach phost $::pkb(phosts) {
    if {[string match -nocase $phost $chost]} {
      #set bmask "*![lindex [split $chost @] 0]@*"
      #set bmask "*!*[string trimleft [lindex [split $chost @] 0]@* "~"]"
      set bmask "[string trimleft [lindex [split $chost @] 0] "~"]"
#     set bmask *!*[string tolower [string range $bmask 3 end]]@*
       set bmask *!*[string tolower [string range $bmask 1 end]]@*
      break
    }
  }
  if {[string match *m $do]} { set bmask $::pkb(mute_maskpre)$bmask }
  return $bmask
}


#### stored nicks & uhosts code

if {![string is digit -strict $pkb(store_time)]} {  set pkb(stime) 2
} else {  set pkb(stime) [expr {$pkb(store_time) * 60}]  }

if {$pkb(stime) > 0} {
  bind part - * store:hosts  ;  bind sign - * store:hosts
  bind kick - * store:kick   ;  bind time - * expire:hosts
} elseif {[llength [binds store:hosts]]} {
  unbind part - * store:hosts  ;  unbind sign - * store:hosts
  unbind kick - * store:kick   ;  unbind time - * expire:hosts
  array unset storehosts
}

proc store:hosts {nk uh hn ch msg} {
  set allowed [is:allowed $nk $hn $ch]
  set aname [string tolower $nk@$ch]
  set ::storehosts($aname) [list $uh [expr {[unixtime]+$::pkb(stime)}] $hn $allowed]
}

proc store:kick {nk uh hn ch target reason} {
  set uhost [getchanhost $target $ch]
  set hand [finduser $target!$uhost]
  store:hosts $target $uhost $hand $ch pkb.tcl
}

proc expire:hosts {mn hr da mo yr} {
  global storehosts
  set ut [unixtime]

  foreach {aname avalue} [array get storehosts] {
    if {$ut >= [lindex $avalue 1]} { unset storehosts($aname) }
  }
}

Back to top
View user's profile Send private message
SpiKe^^
Owner


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

PostPosted: Sun Feb 06, 2022 4:43 am    Post subject: Reply with quote

You added quite a bit of code there, I have no idea where you messed up.

If !kb works so should !k

Go back to the original script, and add back your hacks one at a time until you break it.
Then remove the last hack, and don't do that again:)
_________________
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: Sun Feb 06, 2022 9:13 am    Post subject: Reply with quote

Hm ok yea All i edited was add to the custom kick msg and add few more pub binds with the original code i added 1 hack at a time
Back to top
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Sun Feb 06, 2022 10:39 am    Post subject: Reply with quote

Thanks SpiKe^^ for moving the post here i posted it in the wrong place as your original code works fine and bug free
Back to top
View user's profile Send private message
SpiKe^^
Owner


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

PostPosted: Mon Feb 07, 2022 3:34 am    Post subject: pkb.tcl version 1.5 +kick-hack Reply with quote

Here is a clean copy of the pkb script with only the last 3 patches applied.

Give this last patch a fair testing, and load this script on a bot with no other scripts loaded.

Do NOT edit the script code at all prior to testing this modified code.

Use .restart to load the code clean on the bot.


Code:

#####################################################################################
# Public Kick/Ban Script (with stored nick!uhost info & extended mute bans)
#
# pkb.tcl version 1.5 +kick-hack (07Feb2022)
#####################################################################################
# This script saves the nick!uhost of everyone leaving the channel (quit/part/kick).
# The info is saved for 15 minutes & allows for setting a ban on a nick that is gone.
#
# This script will not target any protected nicks. Protected nicks are anyone who:
#   a)  is/was op or halfop in the target channel
#   b)  has a +o or +b access flag in the eggdrop userfile
#   c)  is/was in any one of the admin channels
#
# This script has 6 basic public commands (all 6 can be prefixed with a . or a !)
#   !kb nick     :kick and ban nick from the channel the command was typed in
#   !k nick      :kick nick from the channel the command was typed in
#   !b nick      :set a ban on nick in the command channel (use default ban_masktype)
#   !m nick      :set an extended mute ban on nick (use default mute_masktype)
#   !ub nick     :remove any and all bans/mutes keeping nick from joining/talking
#   !um nick     :remove any and all mutes keeping nick from talking
#
# There are also several command options for all of the public commands
#   !kb nick nick2 nick3     :kick and ban all listed nicks from the command channel
#   .k nick .A new reason    :set a new custom kick reason for this kick command
#   !b nick nick2 10         :set the ban time for these two bans to 10 minutes
#   .m #sumchannel nick      :change the target channel for this mute to #sumchannel
#   !kb #chan #chan2 nick    :kick/ban nick from both #chan and #chan2
#
# You can also set and remove specific ban masks
#   .kb nick!*@ahost.com *!me@*.host.org   :set 2 bans and kick any nicks that match
#   !b bart! @host.org 30    :set bans bart!*@* and *!*@host.org for 30 minutes
#
#####################################################################################


#### Script Settings ####


# set default ban/mute times (in minutes) #
#   0 = this script doesn't remove bans/mutes #
set pkb(kb_bantime) 60
set pkb(b_bantime)  5
set pkb(m_mutetime) 60


# set the default kick reason for the .k and .kb commands #
# note: set empty to not use any defailt kick reason #
set pkb(kreason)  "Stop that."
set pkb(kbreason) "Go away."


# set mask type for bans and mutes #
# https://docs.eggheads.org/mainDocs/tcl-commands.html#maskhost-nick-user-host-masktype #
set pkb(ban_masktype)  2
set pkb(mute_masktype) 4
# set the extended mute ban prefix for your network (set empty for no mute prefix) #
set pkb(mute_maskpre) "~q:"


# max number of bans/devoice to stack in one mode command (1 or more) #
set pkb(maxban) 6

# max number of kicks to stack in one kick command (1 or more) #
set pkb(maxkick) 3


# protected hosts #
# set only username bans on these domains (ex. *!uid123457@*) #
set pkb(phosts) "*.irccloud.com *.mibbit.com *.kiwiirc.com *.8C39393E.IP"


# set one or more admin channels (or leave empty for no admin chan) #
# note: these channels must be limited access! everyone in these channels #
#         will have access to all the commands in this script. #
# note: all pkb commands done in these channels will apply to pkb(main_chan) #
set pkb(admin_chan) ""

# set one or more default target channels (or leave empty for no default chan) #
# note: these apply to all pkb commands done in a pkb(admin_chan) #
set pkb(main_chan) ""


# change the number of minutes to store nick!uhost info (default = 15 minutes) #
# note: leave empty for default 15 min  (set 0 to not store any nick!uhost info) #
set pkb(store_time) ""

# when setting a ban, this script will check if isvoiced nick, and -v if needed #
#   0 = never mix modes -v and +b in the same mode command to the server #
#   1 = when possible, mix modes -v and +b in the same mode command to the server #
set pkb(mix_mode) 1

#############################################################
#####################  END OF SETTINGS  #####################
#############################################################


bind pub -|- !kick pub:kick
bind pub -|- !k pub:kick
bind pub -|- .k pub:kick
proc pub:kick {nk uh hn ch tx} {  pub:kickban $nk $uh $hn $ch $tx k  }

bind pub -|- !ban pub:ban
bind pub -|- !b pub:ban
bind pub -|- .b pub:ban
proc pub:ban {nk uh hn ch tx} {  pub:kickban $nk $uh $hn $ch $tx b  }

#bind pub -|- !m pub:muteban
#bind pub -|- .m pub:muteban
#proc pub:muteban {nk uh hn ch tx} {  pub:kickban $nk $uh $hn $ch $tx m  }

bind pub -|- !unban pub:unban
bind pub -|- !ub pub:unban
bind pub -|- .ub pub:unban
proc pub:unban {nk uh hn ch tx} {  pub:kickban $nk $uh $hn $ch $tx ub  }

#bind pub -|- !um pub:unmute
#bind pub -|- .um pub:unmute
#proc pub:unmute {nk uh hn ch tx} {  pub:kickban $nk $uh $hn $ch $tx um  }

bind pub -|- !kickban pub:kickban
bind pub -|- !kban pub:kickban
bind pub -|- !kb pub:kickban
bind pub -|- .kb pub:kickban

proc pub:kickban {nk uh hn ch tx {do kb} } {
  global pkb storehosts

  if {$uh ne "Timer" && ![is:allowed $nk $hn $ch]} {  return 0  }

  ## added hack to change the way public !k and !kb commands work ##
  ##   !k onenick custom kick reason, no leading . required       ##
  ## http://forum.egghelp.org/viewtopic.php?p=110851&highlight=#110851 ##
  if {$do eq "k" || $do eq "kb"} {
    if {[llength [set temp [split $tx]]]>1 && ![matchstr ".*" [lindex $temp 1]]} {
      set tx "[lindex $temp 0] .[join [lrange $temp 1 end]]"
    }
  }


  set reason [string trim $pkb(kreason)]
  if {$do eq "kb"} {  set reason [string trim $pkb(kbreason)]  }

  if {[set idx [string first " ." $tx]] > -1} {
    set txls [split [string trim [string range $tx 0 $idx]]]
    set reason [string trim [string range $tx [incr idx 2] end]]
  } else {  set txls [split [string trim $tx]]  }

  set mmpre $pkb(mute_maskpre)


  set nickls ""  ;  set tchan ""
  foreach item $txls {
    if {[string match "#*" $item]} {
      if {[lsearch -nocase $tchan $item] == -1} {  lappend tchan $item  }
    } elseif {[string is digit -strict $item]} {  set btime $item

    ## added code to fix bad nicks provided by lame channel ops, from... ##
    ## http://forum.egghelp.org/viewtopic.php?p=110725&highlight=#110725 ##
    } elseif {[string match {[+%]?*} $item]} {
      lappend nickls [string trimleft $item "+%"]
    } elseif {[string match "@?*" $item] && ![string match {*[.:]*} $item]} {
      lappend nickls [string trimleft $item "@"]



    } elseif {[string match {*[!@]*} $item]} {
      if {[string match u* $do]} {  set orig $item  }

      set item [regsub -all -- {\*{2,}} $item {*}]
      set len [llength [set ils [split $item "!@"]]]

      if {$len == 2} {   incr len
        if {[string first "!" $item] > -1} {  lappend ils "*"
        } else {  set ils [linsert $ils 0 "*"]  }
      }

      if {$len == 3} {   lassign $ils n u h
        if {$n eq $mmpre} {  set n "${n}*"
        } elseif {$n eq ""} {  set n "*"  }
        if {$u eq ""} {  set u "*"  }
        if {$h eq ""} {  set h "*"  }
        set bmask $n!$u@$h
      } else {  set bmask $item  }

      if {![string match u* $do]} {
        if {$len > 3 || $bmask eq "*!*@*" || $bmask eq "$mmpre*!*@*"} {
          putserv "NOTICE $nk :Error: $item is not a valid user mask."
        } else {  lappend nickls $bmask  }
      } else {
        if {$bmask eq $orig} {  lappend nickls $orig
        } else {  lappend nickls "$orig $bmask"  }
      }

    } elseif {$item ne ""} {  lappend nickls $item  }
  }

  if {$tchan ne ""} {

    foreach c $tchan {
      if {![validchan $c]} {
        putserv "NOTICE $nk :Error: $c is not a valid channel."
      } elseif {[lsearch -nocase $pkb(admin_chan) $c] > -1} {
        putserv "NOTICE $nk :Error: You can't target an admin channel: $c."
      } elseif {![is:allowed $nk $hn $c]} {
        putserv "NOTICE $nk :Error: You don't have proper permissions in $c."
      } else {  lappend chlist $c  }
    }

  } elseif {[lsearch -nocase $pkb(admin_chan) $ch] > -1} {

    if {![llength $pkb(main_chan)]} {
      putserv "NOTICE $nk :No default channel set. You must specify a channel."
    } else {
      foreach c $pkb(main_chan) {
        if {![validchan $c]} {
          putserv "NOTICE $nk :Error: $c is not a valid channel."
        } elseif {[lsearch -nocase $pkb(admin_chan) $c] > -1} {
          putserv "NOTICE $nk :Error: (main_chan) can't target an admin channel: $c."
        } else {  lappend chlist $c  }
      }
    }

  } else {  lappend chlist $ch  }


  if {![info exists chlist]} {  return 0  }

  if {![llength $nickls]} {
    putserv "NOTICE $nk :Error: You must specify at least one nick or user mask."
    return 0
  }

  if {[string match u* $do]} {  set plus "-"  } else {  set plus "+"  }

  set seconds 0
  if {[info exists btime]} {
    if {[string match {[bm]} $do] || ($do eq "kb")} {
      set seconds [expr {$btime * 60}]
    }
  } elseif {$do eq "m"} {  set seconds [expr {$pkb(m_mutetime) * 60}]
  } elseif {$do eq "b"} {  set seconds [expr {$pkb(b_bantime) * 60}]
  } elseif {$do eq "kb"} { set seconds [expr {$pkb(kb_bantime) * 60}]  }

  set masktype $pkb(ban_masktype)
  if {[string match *m $do]} {  set masktype $pkb(mute_masktype)  }


  ##  Begin  :  foreach ch $chlist  ####
  foreach ch $chlist {
    if {[info exists userls]} {  unset userls  }
    set bmasks ""  ;  set knicks ""  ;  set dvnicks ""

    foreach nick [lsort -unique -nocase $nickls] {
      set bmask ""

      ############  Begin:  if  [string match {*[!@]*} $nick]  #################
      if {[string match {*[!@]*} $nick]} {
        set bmask $nick  ;  set nick ""

        if {[string match u* $do]} {  set got 0  ;  set bmls [split $bmask]

          foreach bmask $bmls {
            if {($do eq "um") && ![string match $mmpre* $bmask]} {
              set bmask $mmpre$bmask
            }
            if {[ischanban $bmask $ch]} {   incr got
              if {[lsearch -nocase $bmasks $bmask] == -1} {  lappend bmasks $bmask  }
            }
          }

          if {$uh ne "Timer" && $got == 0} {
            putserv "NOTICE $nk :[lindex $bmls 0] is not a current ban on $ch"
          }
          continue
        }


        if {![info exists userls]} {  set clist [chanlist $ch]
          foreach n $clist {
            lappend userls [string tolower $n![getchanhost $n $ch]]
          }
          foreach {aname avalue} [array get storehosts [string tolower *@$ch]] {
            set x [lindex [split $aname @] 0]![string tolower [lindex $avalue 0]]
            if {$x ni $userls} {  lappend userls $x  }
          }
        }

        set m $bmask
        if {$mmpre ne "" && [string match $mmpre* $m]} {
          set m [string range $m [string length $mmpre] end]
        }
        set ok ""  ;  set err ""

        foreach user $userls {
          if {[matchaddr $m $user]} {  lassign [split $user !@] n u h
            if {[onchan $n $ch]} {  set hand [nick2hand $n $ch]
              if {[is:exempt $n $hand $ch]} {  set err $n  ;  break  }
              lappend ok $n
            } else {  set aname [string tolower "$n@$ch"]
              if {![info exists storehosts($aname)]} { continue }
              if {[lindex $storehosts($aname) 3] == 1} {  set err $n ;  break  }
              lappend ok $n
            }
          }
        }

        if {$err ne ""} {
          putserv "NOTICE $nk :You can't target an exempt user on $ch: $err ($u@$h)"
          continue
        }

        if {[string match {*[bm]} $do]} {
          if {$do eq "m" || [string match $mmpre* $bmask]} {  set m $mmpre$m  }

          if {[ischanban $m $ch]} {
            putserv "NOTICE $nk :$m is already an active ban on $ch"
          } elseif {[lsearch -nocase $bmasks $m] == -1} {  lappend bmasks $m  }

          if {$do ne "kb"} {
            foreach n $ok {
              if {[isvoice $n $ch] && [lsearch -nocase $dvnicks $n] == -1} {
                lappend dvnicks $n
              }
            }
          }
        }

        if {[string match k* $do]} {
          foreach n $ok {
            if {[onchan $n $ch] && [lsearch -nocase $knicks $n] == -1} {
              lappend knicks $n
            }
          }
        }

        continue
      } ;############  END:  if  [string match {*[!@]*} $nick]  ################
     

      set aname [string tolower "$nick@$ch"]

      if {[onchan $nick $ch]} {
        set chost [getchanhost $nick $ch]
        set hand [nick2hand $nick $ch]
        set exempt [is:exempt $nick $hand $ch]

      } elseif {[info exists storehosts($aname)] && ($do ne "k")} {
        lassign $storehosts($aname) chost expire hand exempt

      } else {  putserv "NOTICE $nk :$nick is not on channel $ch"  ;  continue  }

      if {$exempt == 1} {
        putserv "NOTICE $nk :You can't target an exempt user on $ch: $nick ($chost)"
        continue
      }

      if {[string match u* $do]} {  set found 0

        foreach binfols [chanbans $ch] {   set ban [lindex $binfols 0]
          if {$do eq "um" && ![string match $mmpre* $ban]} { continue }
          set m $ban
          if {$mmpre ne "" && [string match $mmpre* $m]} {
            set m [string range $m [string length $mmpre] end]
          }
          if {[matchaddr $m $nick!$chost]} {  incr found
            if {[lsearch -nocase $bmasks $ban] == -1} {  lappend bmasks $ban  }
          }
        }

        if {$found == 0} {
          if {$do eq "um"} {  set x "mutes"  } else {  set x "bans"  }
          putserv "NOTICE $nk :No $x found for $nick on $ch"
        }
        continue
      }

      if {[string match {*[bm]} $do]} {
        set bmask [mask:host $nick $chost $masktype $do]

        if {[ischanban $bmask $ch]} {
          putserv "NOTICE $nk :$bmask \[$nick\] is already a ban on $ch"
        } elseif {[lsearch -nocase $bmasks $bmask] == -1} {  lappend bmasks $bmask  }

        if {($do ne "kb") && [isvoice $nick $ch]} {
          if {[lsearch -nocase $dvnicks $nick] == -1} {  lappend dvnicks $nick  }
        }
      }

      if {[string match k* $do] && [onchan $nick $ch]} {
        if {[lsearch -nocase $knicks $nick] == -1} {  lappend knicks $nick  }
      }
    }


    if {$dvnicks ne ""} {
      while {[set len [llength $dvnicks]] > 0} {
        if {$len > $pkb(maxban)} {
          set mode [string repeat "v" $pkb(maxban)]
          set nicks [join [lrange $dvnicks 0 [expr {$pkb(maxban) - 1}]]]
          set dvnicks [lrange $dvnicks $pkb(maxban) end]
        } else {
          set mode [string repeat "v" $len]
          set nicks [join $dvnicks]
          set dvnicks ""

          if {$pkb(mix_mode) != 0 && $len < $pkb(maxban) && $bmasks ne ""} {
            if {($len + [set blen [llength $bmasks]]) <= $pkb(maxban)} {
              set mode ${mode}+[string repeat "b" $blen]
              set nicks "$nicks [join $bmasks]"
              set bmasks ""
            }
          }

        }
        putquick "MODE $ch -$mode $nicks"
      }
    }
    if {$bmasks ne ""} {

      if {$seconds > 0} {
        utimer $seconds [list pub:kickban $nk Timer $hn $ch [join $bmasks] ub]
      }

      while {[set len [llength $bmasks]] > 0} {
        if {$len > $pkb(maxban)} {
          set mode [string repeat "b" $pkb(maxban)]
          set masks [join [lrange $bmasks 0 [expr {$pkb(maxban) - 1}]]]
          set bmasks [lrange $bmasks $pkb(maxban) end]
        } else {
          set mode [string repeat "b" $len]
          set masks [join $bmasks]
          set bmasks ""
        }
        putquick "MODE $ch $plus$mode $masks"
      }
    }
    if {$knicks ne ""} {
      while {[set len [llength $knicks]] > 0} {
        if {$len > $pkb(maxkick)} {
          set nicks [join [lrange $knicks 0 [expr {$pkb(maxkick) - 1}]] ","]
          set knicks [lrange $knicks $pkb(maxkick) end]
        } else {
          set nicks [join $knicks ","]
          set knicks ""
        }
        if {$reason eq ""} {  putserv "KICK $ch $nicks"
        } else {  putserv "KICK $ch $nicks :$reason"  }
      }
    }

  } ;##  END  :  foreach ch $chlist  ####

}


set pkb(admin_chan) [split [string trim $pkb(admin_chan)] ", "]
set pkb(admin_chan) [lsort -unique -nocase $pkb(admin_chan)]

set pkb(main_chan) [split [string trim $pkb(main_chan)] ", "]
set pkb(main_chan) [lsort -unique -nocase $pkb(main_chan)]


#### code for who is allowed to use the public commands

proc is:allowed {nk hn ch} {
  if {[isop $nk $ch] || [ishalfop $nk $ch] || [matchattr $hn o|o $ch]} { return 1 }

  foreach achan $::pkb(admin_chan) {
    if {[validchan $achan] && [onchan $nk $achan]} { return 1 }
  }
  return 0
}

#### code for who is exempt from the public commands

proc is:exempt {nk hn ch} {
  if {[isop $nk $ch] || [ishalfop $nk $ch]} { return 1 }
  if {[isbotnick $nk] || [matchattr $hn bo|bo $ch]} { return 1 }

  foreach achan $::pkb(admin_chan) {
    if {[validchan $achan] && [onchan $nk $achan]} { return 1 }
  }
  return 0
}


#### protected hosts & mask hosts code

set pkb(phosts) [split [string trim $pkb(phosts)]]

proc mask:host {nick chost masktype do} {
  set bmask [maskhost "$nick!$chost" $masktype]
  foreach phost $::pkb(phosts) {
    if {[string match -nocase $phost $chost]} {

      ## modified banmask used for protected hosts, from... ##
      ## http://forum.egghelp.org/viewtopic.php?p=110671&highlight=#110671 ##
      #set bmask "*![lindex [split $chost @] 0]@*"
      set bmask "*!*[string trimleft [lindex [split $chost @] 0] {~}]@*"

      break
    }
  }
  if {[string match *m $do]} { set bmask $::pkb(mute_maskpre)$bmask }
  return $bmask
}


#### stored nicks & uhosts code

if {![string is digit -strict $pkb(store_time)]} {  set pkb(stime) 900
} else {  set pkb(stime) [expr {$pkb(store_time) * 60}]  }

if {$pkb(stime) > 0} {
  bind part - * store:hosts  ;  bind sign - * store:hosts
  bind kick - * store:kick   ;  bind time - * expire:hosts
} elseif {[llength [binds store:hosts]]} {
  unbind part - * store:hosts  ;  unbind sign - * store:hosts
  unbind kick - * store:kick   ;  unbind time - * expire:hosts
  array unset storehosts
}

proc store:hosts {nk uh hn ch msg} {
  set allowed [is:allowed $nk $hn $ch]
  set aname [string tolower $nk@$ch]
  set ::storehosts($aname) [list $uh [expr {[unixtime]+$::pkb(stime)}] $hn $allowed]
}

proc store:kick {nk uh hn ch target reason} {
  set uhost [getchanhost $target $ch]
  set hand [finduser $target!$uhost]
  store:hosts $target $uhost $hand $ch pkb.tcl
}

proc expire:hosts {mn hr da mo yr} {
  global storehosts
  set ut [unixtime]

  foreach {aname avalue} [array get storehosts] {
    if {$ut >= [lindex $avalue 1]} { unset storehosts($aname) }
  }
}

putlog "Loaded pkb.tcl version 1.5 +kick-hack"


_________________
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
SpiKe^^
Owner


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

PostPosted: Mon Feb 07, 2022 3:57 am    Post subject: pkb.tcl version 1.5 +kick-hack tested Reply with quote

Loaded and quick tested the current modified code and all is fine.

Somewhere you messed up your code again, or are also running another script that doesn't play well with this script.

Quote:

<SpiKe^^> .k sumguy
* sumguy was kicked by Morticia (Stop that.)

<SpiKe^^> .k sumguy a custom reason
* sumguy was kicked by Morticia (a custom reason)

<SpiKe^^> !kick sumguy another custom reason
* sumguy was kicked by Morticia (another custom reason)

<SpiKe^^> !kban sumguy yet another custom reason
* Morticia sets mode: +b *!*@166-020-145-063.res.comcast.com
* sumguy was kicked by Morticia (yet another custom reason)

<SpiKe^^> !unban sumguy
* Morticia sets mode: -b *!*@166-020-145-063.res.comcast.com
* sumguy (richard@166-020-145-063.res.comcast.com) has joined #pc-mirc-help


_________________
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 Feb 07, 2022 1:55 pm    Post subject: Reply with quote

tested it and it seems working fine now including all scripts i already had loaded i tested both with and without any additional script loaded both worked fine
thanks again Spike^^
Back to top
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Mon Feb 07, 2022 10:34 pm    Post subject: Reply with quote

did some more testing and found this part not to function proper:

Quote:

## added code to fix bad nicks provided by lame channel ops, from... ##
## http://forum.egghelp.org/viewtopic.php?p=110725&highlight=#110725 ##
} elseif {[string match {[+%]?*} $item]} {
lappend nickls [string trimleft $item "+%"]
} elseif {[string match "@?*" $item] && ![string match {*[.:]*} $item]} {
lappend nickls [string trimleft $item "@"]



} elseif {[string match {*[!@]*} $item]} {
if {[string match u* $do]} { set orig $item }






for example:

Quote:

!kb nick:
!kban nick:
!kickban nick:
!k nick:
!kick nick:


returns :

Quote:

-Hawk- : nick: is not on channel #TestChannel



it doesnt strip the :
Back to top
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Mon Feb 07, 2022 11:08 pm    Post subject: Reply with quote

im not sure if i added it proper but i added this part :


Code:

    ## added code to fix bad nicks provided by lame channel ops, from... ##
    ## http://forum.egghelp.org/viewtopic.php?p=110725&highlight=#110725 ##
    } elseif {[string match {[+%]?*} $item]} {
      lappend nickls [string trimleft $item "+%"]
    } elseif {[string match "@?*" $item] && ![string match {*[.:]*} $item]} {
      lappend nickls [string trimleft $item "@"]

    } elseif {[string match {*[:]*} $item]} {
 lappend nickls [string trimright $item ":"]



added this part to it:

Code:
 
} elseif {[string match {*[:]*} $item]} {
 lappend nickls [string trimright $item ":"]


and it seems to trim the :
Back to top
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Mon Feb 07, 2022 11:21 pm    Post subject: Reply with quote

i spoke too soon again it doesnt seem to do strip both in 1 go if a nick contains like

+nick:

@nick:
Back to top
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Mon Feb 07, 2022 11:42 pm    Post subject: Reply with quote

this seems to work:

!kick nick:

but not

!kick +nick:
!kick @nick:
Back to top
View user's profile Send private message
SpiKe^^
Owner


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

PostPosted: Tue Feb 08, 2022 12:44 am    Post subject: wtf Reply with quote

What in the world are you talking about?

That code was never designed to strip the : from nick:

Read the patch request from just above the linked content.
Actually that request was yours... "for example doing !k @somenick"

You never said your channel ops were typing in nicks followed by a :
wtf would anyone do that?

As I said earlier in that thread, "There is no end to the number of ways an "operator" can misuse a command"
and there is no way to predict the stupid things people will type.

The error the script reported was exactly correct...
-Hawk- : nick: is not on channel #TestChannel
There is no way nick: could be on the channel, as : is not even a valid char to use in a nick!

The code I wrote, and posted above is working exactly as requested and designed.
I stand by it completely.
_________________
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: Tue Feb 08, 2022 10:51 am    Post subject: Reply with quote

The reason being that nick-completer of some clients like for example irccloud place a : right after the nick that's why we wanted to strip that as well

As we also use this on dalnet as well on wich a large portion of users use irccloud including chanops
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Tue Feb 08, 2022 12:28 pm    Post subject: Reply with quote

Well, chanops must know what they do, and ensure they type the good commands with good arguments.
If they are too lazy to use backspace to get the good nick, they are probably too lazy to be chanops.
_________________
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: Tue Feb 08, 2022 2:35 pm    Post subject: Reply with quote

In this case its the client that keeps adding the : not chanops
But your right about chanops need to have basic knowledge of kicks and bans no doubt CrazyCat cant argue there
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