All pastes #728542 Raw Edit

Untitled

public text v1 · immutable
·published 2007-10-07 02:47 UTC
rendered paste body
#################################################################################################

#                                                                                               #

# LoReZ Public Commands Script v1.0 (pcmd.tcl)                                                  #

# Email: lorez@zerol.de                                                                         #

# IRC: #muenchen @ Quakenet                                                                     #

#                                                                                               #

# Please contact me if you notice any bugs                                                      #

#                                                                                               #

# Installation: Put the script into your scripts directory, add "source scripts/pcmd.tcl" to    #

#               your eggdrop config and rehash the bot. (moretools.tcl is REQUIRED for this     #

#               script to work)                                                                 #

#                                                                                               #

# Usage:        You can use the op/deop/voice/devoice/kick/kickban/ban/unban commands with a    #

#               wildmask/hostmask (e.g. "!op *a*b*c*" or "!deop *@*.quakenet.org" or            #

#               "!voice *a* *b* *@*.de Bot" for multiple args).                                 #

#               You also can use as many channelsmodes as you want in one command (e.g.         #

#               "!mode +sCn-c+kl test 1337")                                                    #

#                                                                                               #

#################################################################################################



#################################################################################################

#                                   START OF CONFIGURATION                                      #

#################################################################################################



array set pcmd {

    chans	""

    mask 	1

    opcmd	"!op"

    opflg	"o"

    deopcmd	"!deop"

    deopflg	"o"

    voicecmd	"!voice"

    voiceflg	"o"

    devoicecmd	"!devoice"

    devoiceflg  "o"

    kickcmd	"!kick"

    kickflg	"o"

    kickbancmd	"!kickban"

    kickbanflg	"o"

    bancmd	"!ban"

    banflg	"o"

    unbancmd	"!unban"

    unbanflg	"o"

    invitecmd	"!invite"

    inviteflg	"o"

    topiccmd	"!topic"

    topicflg	"o"

    modecmd	"!mode"

    modeflg	"o"

}



#################################################################################################

#                                     END OF CONFIGURATION                                      #

#################################################################################################



#################################################################################################

#                      START OF CODE (EDIT NOTHING! EVEN IF YOU KNOW TCL)                       #

#################################################################################################



if { 1 >= 0 } { 

    namespace eval pcmd {

	proc init { } {

            set start [clock clicks]

	    global pcmd

	    bind pub $pcmd(opflg) $pcmd(opcmd) "pcmd::mode op"

	    bind pub $pcmd(deopflg) $pcmd(deopcmd) "pcmd::mode deop"

	    bind pub $pcmd(voiceflg) $pcmd(voicecmd) "pcmd::mode voice"

	    bind pub $pcmd(devoiceflg) $pcmd(devoicecmd) "pcmd::mode devoice"

	    bind pub $pcmd(kickflg) $pcmd(kickcmd) "pcmd::mode kick"

	    bind pub $pcmd(kickbanflg) $pcmd(kickbancmd) "pcmd::mode kickban"

	    bind pub $pcmd(banflg) $pcmd(bancmd) "pcmd::mode ban"

	    bind pub $pcmd(unbanflg) $pcmd(unbancmd) "pcmd::mode unban"

    	    bind pub $pcmd(inviteflg) $pcmd(invitecmd) "pcmd::mode invite"

	    bind pub $pcmd(topicflg) $pcmd(topiccmd) "pcmd::mode topic"

	    bind pub $pcmd(modeflg) $pcmd(modecmd) "pcmd::mode chan"

            set end [clock clicks]

	    putlog "pcmd.tcl v1.0 by LoReZ successfully initialized in [expr ($end-$start)/1000.0]ms"

	}

	proc mode { mode nick uhost hand chan target } {

	    global pcmd

	    if {([lsearch -exact [string tolower $pcmd(chans)] [string tolower $chan]] != -1) || ($pcmd(chans) == "")} {

		if {![botisop $chan]} {

		putquick "NOTICE $nick :Bot isn't opped"   

		} else {

		    switch -exact $mode {

			kick {

			    pcmd::setmodes kick $nick $chan "[pcmd::nicks $target $chan $mode]"

			}

			kickban {

			    pcmd::setmodes +b $nick $chan "[pcmd::hosts $nick $target $chan $mode]"

			    pcmd::setmodes kickban $nick $chan "[pcmd::nicks $target $chan $mode]"

			}

			invite {

                            foreach x $target {

                                putquick "INVITE $x $chan"

                            }

			}

			topic {

			    putquick "TOPIC $chan :$target"

			}

			chan {

                            pcmd::setmodes mode $nick $chan "$target"

			}

			default {

			    set modechr1 [expr {[regexp -all "(de|un)" $mode] ? "-" : "+"}]

			    regsub -all "(de|un|oice|an|p)" "$mode" "" modechr2

			    set modechr $modechr1$modechr2

			    set targets [expr {[regexp -all "ban" $mode] ? [pcmd::hosts $nick $target $chan $mode] : [pcmd::nicks $target $chan $mode]}]

			    pcmd::setmodes $modechr $nick $chan "$targets"

			}

		    }    

		}

	    }

	}

	proc setmodes { mode nick chan targets } {

	    global pcmd

	    if {($targets == 0) || ($targets == "")} {

		putquick "NOTICE $nick :No User/Host match or Host also matches Bothost"

	    } else {

		if {($mode == "kick") || ($mode == "kickban")} {

		    foreach x $targets {

			putkick $chan $x "requested by $nick"

		    }

                } elseif {$mode == "mode" } {

                    set x 0

                    set y 1

                    if {([string index [lindex $targets 0] $x] == "+") || ([string index [lindex $targets 0] $x] == "-")} {

                        if {([string match *k* [lindex $targets 0]])} {

                            set key [expr {[string match *k* [getchanmode $chan]] ? [lindex [getchanmode $chan] 1] : ""}] 

                        }

                        while {$x < [string length [lindex $targets 0]]} {

                            if {([string index [lindex $targets 0] $x] == "+") || ([string index [lindex $targets 0] $x] == "-")} {

                                set modechr1 [string index [lindex $targets 0] $x]

                            } else {

                                set modechr2 [string index [lindex $targets 0] $x]

                                if {$modechr2 == "k"} {

                                    if {$modechr1 == "+"} {

                                        if {[llength $targets] < 2} {

                                            putquick "NOTICE $nick :No value given for mode +k"

                                        } else {

                                            if {$key == ""} {

                                                pushmode $chan $modechr1$modechr2 [lindex $targets $y]

                                            } else {

                                                pushmode $chan -$modechr2 $key

                                                pushmode $chan $modechr1$modechr2 [lindex $targets $y]

                                            }

                                            incr y

                                        }

                                    } else {

                                        pushmode $chan $modechr1$modechr2 $key

                                    }

                                } elseif {$modechr2 == "l"} {

                                    if {$modechr1 == "+"} {

                                        if {[llength $targets] < 2} {

                                            putquick "NOTICE $nick :No value given for mode +l"

                                        } else {

                                            pushmode $chan $modechr1$modechr2 [lindex $targets $y]

                                            incr y

                                        }

                                    } else {

                                        pushmode $chan $modechr1$modechr2

                                    }

                                } else {

                                    pushmode $chan $modechr1$modechr2

                                }

                            }

                            incr x    

                        }

                        flushmode $chan

                    } else {

                        putquick "NOTICE $nick :Modes have to start with + or -"

                    }

		} else {

		    foreach x $targets {

			pushmode $chan $mode $x

		    }

		    flushmode $chan

		}

	    }

	}

	proc nicks { target chan mode } {

	    global botnick pcmd

	    foreach x [chanlist $chan] {

		if {$x != $botnick} {

		    foreach y $target {

			if {($mode == "kick") || ($mode == "kickban")} {

			    set ison 0

			    set ismode $ison

			} else {

			    set ison [expr {[string match *op* $mode] ? [isop $x $chan] : [string match *voice* $mode] ? [isvoice $x $chan] : [ishalfop $x $chan]}]

			    set ismode [expr {[string match *de* $mode] ? 1 : 0}]

			}

			if {([string match -nocase $y $x]) && ($ison == $ismode) && (![onchansplit $x $chan])} {

			    append nicks " " $x

			}

			if {([regexp -all ".*@.*" $y])} {

			    if {([string match -nocase $y [getchanhost $x $chan]]) && ($ison == $ismode) && (![onchansplit $x $chan])} {

				append nicks " " $x

			    }

			}

		    }

		}

	    }

	    return [expr {[info exists nicks] ? [lsort -unique $nicks] : 0}]

	}

	proc hosts { nick target chan mode } {

	    global botname pcmd

	    if {$mode == "unban"} {

		foreach x $target {

		    foreach y [chanbans $chan] {

			if {([string match $x $y])} {

			    append hosts " " [lindex $y 0]

			}

		    }

		}  

	    } else {

		foreach x $target {

		    if {([regexp -all ".*@.*" $x])} {

			append hosts " " $x

		    } else {

			foreach y [chanlist $chan] {

			    if {([string match -nocase $x $y])} {

				append hosts " " [masktype $x![getchanhost $y $chan] $pcmd(mask)]

			    }

			}

		    }

		}

		if {([info exists hosts])} {

		    set hosts [lsort -unique $hosts]

		    foreach x $hosts {

			foreach y $hosts {

			    if {(([string match -nocase $x $y]) && ($x != $y)) || ([string match $y $botname])} {

				set hosts [lreplace $hosts [lsearch -exact $hosts $y] [lsearch -exact $hosts $y]]

				if {([string match $y $botname])} {

				    putquick "NOTICE $nick :Mask $y matches Bothost!"

				}

			    }

			}

		    }

		}

	    }

	    return [expr {[info exists hosts] ? [lsort -unique $hosts] : 0}]

	}

    }

    pcmd::init

} else {

    putlog "alltools.tcl is required! Script not initialized! You can get moretools.tcl @ http://www.egghelp.org"

}



#################################################################################################

#                                          END OF CODE                                          #

#################################################################################################