home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HaCKeRz KrOnIcKLeZ 3
/
HaCKeRz_KrOnIcKLeZ.iso
/
scriptz
/
chanserv.tcl
< prev
next >
Wrap
Text File
|
1996-04-23
|
14KB
|
473 lines
# chanserv.tcl
# 27 March 1996 by Gord-@saFyre
# for eggdrop version 1.0
# provides dcc and msg/public commands for multichannel bot settings
# stores and reloads info on "added" channels to provide permanence -
# bot will rejoin and reset all channels it was on if it crashes and
# is brought back up.
# ADDED COMMANDS:
# All change commands require master status.
#
# DCC commands added:
# .join <channel>
# .leave <channel>
# .setmode [<+/-mode>...<+-mode>][-TOPIC][+TOPIC <topictext>]
# setmode applies the changes to the console channel of the
# master who issues the command - if no parameters are given,
# it returns the status of the current channel's modes
# .channels
# channels lists the channels the bot is currently on (op command)
#
# MSG commands added:
# /msg <bot> join <channel>
# /msg <bot> leave <channel>
# /msg <bot> channels
# channels lists the channels the bot is currently on (op command)
#
# PUB commands added:
# !topic <topictext>
# !setmode [<+/-mode>...<+-mode>][-TOPIC][+TOPIC <topictext>]
# setmode applies the changes to the channel in which the
# command was publicly issued - if no parameters are given,
# it returns the status of the current channel's modes
#
# set the default options you would like new channels to have (these
# can only be shanged using the builtin tcl commands).
set defchanoptions {chanmode "+n-likm" idle-kick 120}
# set the default modes you would like new channels to have (these
# can later be changed for each channel using the 'setmode' command.
set defchanmodes {-clearbans +enforcebans +dynamicbans +userbans +autoop -bitch +greet +protectops +statuslog}
# set the file in which chanserv will store channel state information
# for permanence
set chanfile "pinkfloyd.channelfile"
##############################################
# Do NOT modify anything below this #
##############################################
proc cleanarg {arg} {
set response ""
for {set i 0} {$i < [string length $arg]} {incr i} {
set char [string index $arg $i]
if {($char != "\12") && ($char != "\15")} {
append response $char
}
}
return $response
}
set savedchans { }
set okchanmodes {+clearbans -clearbans +enforcebans -enforcebans +dynamicbans -dynamicbans +userbans -userbans +autoop -autoop +bitch -bitch +greet -greet +protectops -protectops +statuslog -statuslog}
proc getchanmode {channel} {
global savedchans
for {set i 0} {$i < [llength $savedchans]} {incr i} {
set this [lindex $savedchans $i]
if {[string compare [string tolower [lindex $this 0]] [string tolower $channel]] == 0} {
return [lindex $this 1]
}
}
return ""
}
proc getchantopic {channel} {
global savedchans
for {set i 0} {$i < [llength $savedchans]} {incr i} {
set this [lindex $savedchans $i]
if {[string compare [string tolower [lindex $this 0]] [string tolower $channel]] == 0} {
return [lindex $this 2]
}
}
return ""
}
proc setchanmode {channel data} {
global savedchans
for {set i 0} {$i < [llength $savedchans]} {incr i} {
set this [lindex $savedchans $i]
if {[string compare [string tolower [lindex $this 0]] [string tolower $channel]] == 0} {
set topic [lindex $this 2]
set this [list $channel $data $topic]
set savedchans [lreplace $savedchans $i $i $this]
savechans
return 0
}
}
}
proc setchantopic {channel data} {
global savedchans
for {set i 0} {$i < [llength $savedchans]} {incr i} {
set this [lindex $savedchans $i]
if {[string compare [string tolower [lindex $this 0]] [string tolower $channel]] == 0} {
set modes [lindex $this 1]
set this [list $channel $modes $data]
set savedchans [lreplace $savedchans $i $i $this]
savechans
return 0
}
}
}
proc savechans {} {
global savedchans
global chanfile
set fd [open $chanfile w]
foreach channelinfo $savedchans {
puts $fd $channelinfo
}
close $fd
return
}
proc loadchans {} {
global savedchans
global chanfile
global botnick
global defchanoptions
putlog "### chanserv.tcl by Gord-@saFyre loaded."
if {[catch {set fd [open $chanfile r]}] != 0} {
setconfigchans
putlog "### channel file $chanfile does not exist!"
return 0
}
set savedchans { }
while {![eof $fd]} {
set savedchans [lappend savedchans [string trim [gets $fd]]]
}
close $fd
set savedchans [lreplace $savedchans end end]
if ([llength $savedchans]) {
foreach channelinfo $savedchans {
set channel [lindex $channelinfo 0]
set modes [lindex $channelinfo 1]
set topic [lindex $channelinfo 2]
set needop "need-op \{gain-ops $channel\}"
set needinvite "need-invite \{ \}"
set options [concat $defchanoptions $needop $needinvite]
channel add $channel $options
foreach mode $modes {
channel set $channel $mode
}
if {$topic != ""} {
putserv "TOPIC $channel :$topic"
}
putlog "Added saved channel $channel with modes \"$modes\" and topic \"$topic\""
}
}
if {($savedchans == { }) && ([llength [channels]] > 0} {
setconfigchans
}
return
}
proc setconfigchans {} {
global savedchans
foreach channel [channels] {
set chanmodes [lrange [channel info $channel] 4 end]
set savit $channel
lappend savit $chanmodes ""
lappend savedchans $savit
}
savechans
return 1
}
proc addchannel {channel chanmodes topic} {
global defchanoptions savedchans
if {[lsearch [string tolower [channels]] [string tolower $channel]] >= 0} {return 0}
set needop "need-op \{gain-ops $channel\}"
set needinvite "need-invite \{ \}"
set options [concat $defchanoptions $needop $needinvite]
channel add $channel $options
foreach option $chanmodes {
channel set $channel $option
}
if {$topic != ""} {
putserv "TOPIC $channel :$topic"
}
lappend channel $chanmodes $topic
lappend savedchans $channel
savechans
return 1
}
proc remchannel {channel} {
global savedchans
if {[lsearch [string tolower [channels]] [string tolower $channel]] == -1} {return 0}
if ([llength $savedchans]) {
set index 0
foreach channelinfo $savedchans {
set ochannel [lindex $channelinfo 0]
if {[string tolower $ochannel] == [string tolower $channel]} {
set savedchans [lreplace $savedchans $index $index]
channel remove $channel
savechans
return 1
}
incr index
}
}
return 0
}
proc dcc_botjoin {handle idx channel} {
global defchanmodes
if {([llength $channel] != 1) || ([string first # $channel] == -1)} {
putdcc $idx "syntax: .join #channel"
return 0
}
if {[addchannel $channel $defchanmodes ""]} {
putcmdlog "joined $channel - requested by $handle"
} else {
putdcc $idx "I'm already on $channel!"
}
return 0
}
bind dcc m join dcc_botjoin
proc dcc_botleave {handle idx channel} {
if {([llength $channel] != 1) || ([string first # $channel] == -1)} {
putdcc $idx "syntax: .leave #channel"
return 0
}
if {[lsearch [string tolower [channels]] [string tolower $channel]] == 0} {
putdcc $idx "I can't leave my home channel!"
return 0
}
if {[remchannel $channel]} {
putcmdlog "left $channel - requested by $handle"
} else {
putdcc $idx "I'm not on $channel!"
}
return 0
}
bind dcc m leave dcc_botleave
proc dcc_settopic {handle idx topic} {
set channel [lindex [console $idx] 0]
set topic [cleanarg $topic]
if {[llength $topic] >= 1} {
set t2 ""
for {set i 0} {$i < [string length $topic]} {incr i} {
set this [string index $topic $i]
if {$this == "\""} {
append t2 "\'"
} {
if {$this == "\{"} {
append t2 "("
} {
if {$this == "\}"} {
append t2 ")"
} {
append t2 $this
}
}
}
}
set topic $t2
putserv "TOPIC $channel :$topic"
setchantopic $channel $topic
putcmdlog "Channel $channel default topic set to \"$topic\" by $handle."
putdcc $idx "Topic set for channel $channel."
return 0
}
set topic [getchantopic $channel]
putdcc $idx "Default topic for $channel is \"$topic\"."
return 0
}
bind dcc n topic dcc_settopic
proc msg_botjoin {nick uhost handle channel} {
global defchanmodes botnick
set channel [cleanarg $channel]
if {([llength $channel] != 1) || ([string first # $channel] == -1)} {
putserv "NOTICE $nick :syntax: /msg $botnick join #channel"
return 0
}
if {[addchannel $channel $defchanmodes ""]} {
putcmdlog "joined $channel - requested by $handle"
} else {
putserv "NOTICE $nick :I'm already on $channel!"
}
return 0
}
bind msg m join msg_botjoin
proc msg_botleave {nick uhost handle channel} {
global botnick
set channel [cleanarg $channel]
if {([llength $channel] != 1) || ([string first # $channel] == -1)} {
putserv "NOTICE $nick :syntax: /msg $botnick leave #channel"
return 0
}
if {[lsearch [string tolower [channels]] [string tolower $channel]] == 0} {
putserv "NOTICE $nick :I can't leave my home channel!"
return 0
}
if {[remchannel $channel]} {
putcmdlog "left $channel - requested by $handle"
} else {
putserv "NOTICE $nick :I'm not on $channel!"
}
return 0
}
bind msg m leave msg_botleave
proc pub_settopic {nick uhost handle channel topic} {
set topic [cleanarg $topic]
if {[llength $topic] >= 1} {
set t2 ""
for {set i 0} {$i < [string length $topic]} {incr i} {
set this [string index $topic $i]
if {$this == "\""} {
append t2 "\'"
} {
if {$this == "\{"} {
append t2 "("
} {
if {$this == "\}"} {
append t2 ")"
} {
append t2 $this
}
}
}
}
set topic $t2
putserv "TOPIC $channel :$topic"
setchantopic $channel $topic
putcmdlog "Channel $channel default topic set to \"$topic\" by $handle."
putserv "NOTICE $nick :Topic set for channel $channel."
return 0
}
set topic [getchantopic $channel]
putserv "NOTICE $nick :Default topic for $channel is \"$topic\"."
return 0
}
bind pub m !topic pub_settopic
proc chanmodechange {handle channel modes} {
set modes [cleanarg $modes]
global okchanmodes
set donemodes { }
set chanmodes [getchanmode $channel]
if {([string index $modes 0] != "+") && ([string index $modes 0] != "-")} {return $donemodes}
set t2 ""
for {set i 0} {$i < [string length $modes]} {incr i} {
set this [string index $modes $i]
if {$this == "\""} {
append t2 "\'"
} {
if {$this == "\{"} {
append t2 "("
} {
if {$this == "\}"} {
append t2 ")"
} {
append t2 $this
}
}
}
}
set modes $t2
for {set i 0} {$i < [llength $modes]} {incr i} {
set mode [string tolower [lindex $modes $i]]
if {[string match $mode "+topic"]} {
if {[expr $i + 1] < [llength $modes]} {
set topic [lrange $modes [expr $i + 1] end]
} else {
set topic ""
}
setchantopic $channel $topic
putserv "TOPIC $channel :$topic"
putcmdlog "Channel $channel default topic set to \"$topic\" by $handle."
lappend donemodes +topic
setchanmode $channel $chanmodes
return $donemodes
}
if {[string match $mode "-topic"]} {
setchantopic $channel ""
putserv "TOPIC $channel :"
putcmdlog "Channel $channel default topic set to \"$topic\" by $handle."
lappend donemodes -topic
continue
}
if {[lsearch $okchanmodes $mode] != -1} {
channel set $channel $mode
lappend donemodes $mode
set antimode [string trimleft $mode "+-"]
if {[string index $mode 0] == "-"} {
set antimode "+$antimode"
} else {
set antimode "-$antimode"
}
set index [lsearch $chanmodes $antimode]
if {$index != -1} {
set chanmodes [lreplace $chanmodes $index $index $mode]
}
setchanmode $channel $chanmodes
}
}
return $donemodes
}
proc dcc_chchanmodes {hand idx arg} {
set arg [cleanarg $arg]
set channel [lindex [console $idx] 0]
set setmodes [chanmodechange $hand $channel $arg]
if {$setmodes == { }} {
set setmodes [lrange [channel info $channel] 4 end]
} {
putcmdlog "$hand set channel $channel to: $setmodes"
}
putdcc $idx "Channel $channel set to: $setmodes"
return 0
}
bind dcc m setmode dcc_chchanmodes
proc dcc_channels {hand idx arg} {
putdcc $idx "Currently on: [channels]"
return 0
}
bind dcc o channels dcc_channels
proc pub_chchanmodes {nick uhost hand arg channel} {
set arg [cleanarg $arg]
set setmodes [chanmodechange $hand $channel $arg]
if {$setmodes == { }} {
set setmodes [lrange [channel info $channel] 4 end]
} {
putcmdlog "$hand set channel $channel to: $setmodes"
}
putserv "NOTICE $nick :Channel $channel set to: $setmodes"
return 0
}
bind pub m !setmode pub_chchanmodes
proc msg_channels {nick uhost hand arg channel} {
putserv "NOTICE $nick :Currently on: [channels]"
return 0
}
bind msg o channels msg_channels
loadchans