Language: EN FR PT ES NL DE SV RU
######################################################################
#                                                                    #
#====================================================================#
# gt-mass.tcl by slackin                                             #
#====================================================================#
# Slackin's mass commands script!                                    #
# Custom written for #pugbot & GT                                    #
######################################################################
#                                                                    #
######################################################################
######################################################################
# Config section, please edit with                                   #
# proper info                                                        #
#--------------------------------------------------------------------#
 
### Set the directory and prefix for the topic files
set topicdir "./"
set tp "topic"
 
### Define the botnicks
set gtmass_botnicks {"gs-02" "qnet-02"}
 
### Define what networks each botnick is on
set gtmass_onchan(GameSurge) "gs-02"
set gtmass_onchan(QuakeNet) "qnet-02"
 
### Define what networks should relay to which networks
set gtmass_relayto(GameSurge) {"QuakeNet"}
set gtmass_relayto(QuakeNet) {"GameSurge"}
 
#--------------------------------------------------------------------#
# End of config section                                              #
######################################################################
######################################################################
 
# Bind's for the commands and catches
#bind pub m .mtopic pub_mass_topic
bind pub o .mmod pub_mass_moderate
bind pub o .mkick pub_mass_kick
bind bot - gtmass gtmass_botdat
#bind topc * * check_topic
bind pub m .nsreg register_bot
bind pub m .nsconfirm confirm_bot
bind pub m .nsauth auth_bot
bind pub m .nschpass chpass_bot
 
 
# Mass topic bind function
proc auto_auth {} {
	global network nick
	switch $network {
		QuakeNet {
			set auth_string "Q@CServe.quakenet.org :AUTH GT-GSN c01oph4rm"
		}
		GameSurge {
			set auth_string "AuthServ@Services.GameSurge.net :auth gt-pugbot c01oph4rm"
		}
		rizon {
			set auth_string "nickserv :IDENTIFY c01oph4rm"
		}
	}
	putlog "$network"
	putserv "PRIVMSG $auth_string"
	putserv "MODE $nick +x"
 
}
 
proc chpass_bot {frnick uhost hand chan text} {
	global network
	switch $network {
		QuakeNet {
			set chpass_string "Q@CServe.quakenet.org :NEWPASS xY9!6ZkD6z c01oph4rm c01oph4rm"
		}
		GameSurge {
			set chpass_string "AuthServ@Services.GameSurge.net :pass UF9buL9u c01oph4rm"
		}
		rizon {
			set chpass_string "nickserv :IDENTIFY c01oph4rm"
		}
	}
	putlog "$network"
	putserv "PRIVMSG $chpass_string"
 
}
 
proc auth_bot {frnick uhost hand chan text} {
	global network nick
	switch $network {
		QuakeNet {
			set auth_string "Q@CServe.quakenet.org :AUTH GT-GSN c01oph4rm"
		}
		GameSurge {
			set auth_string "AuthServ@Services.GameSurge.net :auth gt-pugbot c01oph4rm"
		}
		rizon {
			set auth_string "nickserv :IDENTIFY c01oph4rm"
		}
	}
	putlog "$network"
	putserv "PRIVMSG $auth_string"
	putserv "MODE $nick +x"
 
}
 
proc confirm_bot {nick uhost hand chan text} {
	global network
	switch $network {
		QuakeNet {
			set confirm_string "Q :HELLO admins@pugbot.com admins@pugbot.com"
		}
		GameSurge {
			putlog "use website!"
			return 0
		}
		rizon {
			set confirm_string "nickserv :confirm $text"
		}
	}
	putlog "$network"
	putserv "PRIVMSG $confirm_string"
 
}
 
proc register_bot {nick uhost hand chan text} {
	global network
	switch $network {
		QuakeNet {
			set register_string "Q :HELLO admins@pugbot.com admins@pugbot.com"
		}
		GameSurge {
			putlog "use website!"
			return 0
		}
		rizon {
			set register_string "nickserv :REGISTER c01oph4rm admins@pugbot.com"
		}
	}
	putlog "$network"
	putserv "PRIVMSG $register_string"
 
}
 
# Relay function for mass commands
proc mcommand_botsend {chan param} {
	global gtmass_onchan {botnet-nick} network gtmass_relayto
	foreach gtmass_relaychan $gtmass_relayto($network) {
		if {[lsearch -exact [bots] $gtmass_onchan($gtmass_relaychan)] == -1} {
			putlog "gt-mass.tcl: Warning: bot $gtmass_onchan($gtmass_relaychan) not linked."
		} else {
			putbot $gtmass_onchan($gtmass_relaychan) "gtmass $chan $network $param"
		}
	}
}
 
# Mass kick a user from all networks
proc pub_mass_kick {nick uhost hand chan text} {
	global network
	set knick [join [lindex $text 0]]
	set kreason [join [lrange $text 1 end]]
	set khost "*!*[string range [getchanhost $knick $chan] 2 120]"
	mcommand_botsend $chan [concat "mkick" $network $nick $knick $khost $kreason]
	do_mass_kick $chan $network $nick $knick $khost $kreason
}
 
# Mass moderate a channel
proc pub_mass_moderate {nick uhost hand chan text} {
	global gtmass_onchan network
	mcommand_botsend $chan [concat "mmoderate" $network $nick]
	do_mass_moderate $chan $network $nick
}
 
# Mass topic bind function
proc pub_mass_topic {nick uhost hand chan text} {
	global gtmass_onchan network
	if {$text != ""} {
		mcommand_botsend $chan [concat "mtopic" [gtmass_cleannick $nick] $text]
	}
	do_mass_topic [gtmass_cleannick $nick] $chan $text
}
 
# Catch for events from other bots
proc gtmass_botdat {bot gtmass param} {
	global gtmass_relaynet gtmass_relayto network
	switch [lindex $param 2] {
		mtopic	{ do_mass_topic [lindex $param 3] [lindex $param 0] [lrange $param 4 end] }
		mmoderate { do_mass_moderate [lindex $param 0] [lindex $param 3] [lindex $param 4] }
		mkick { do_mass_kick [lindex $param 0] [lindex $param 3] [lindex $param 4] [lindex $param 5] [lindex $param 6] [lrange $param 7 end] }
		default { putlog "clink.tcl: Warning: unknown action type \"[lindex $param 2]\" for [lindex $param 0]." }
	}
}
 
# Clean up the nick
proc gtmass_cleannick {nick} {
	if {[string range $nick 0 0] == "\{"} {
	      set nick "\\$nick"
	}
        return $nick
}
 
proc do_mass_kick {chan fnetwork fnick knick khost kreason} {
	global network nick
	if {[onchan $knick $chan] == "0"} {
		send_msg_db $fnetwork $fnick "$knick is not on $chan on $network, setting ban anyway" "notice"
		newchanban $chan $khost $fnick $kreason 60
	} elseif {![botisop $chan]} {
		send_msg_db $fnetwork $fnick "$nick is not opped on $chan on $network" "notice"
	} else {
		send_msg_db $fnetwork $fnick "$knick found on $chan on $network kicking and banning now!" "notice"
		newchanban $chan $khost $fnick $kreason 60
		putkick $chan $knick "$kreason - $fnick"
	}
}
 
proc do_mass_moderate {chan fnetwork fnick} {
	global network nick
	set ismod [string first "m" [getchanmode $chan]]
	if {![botisop $chan]} {
		send_msg_db $fnetwork $fnick "$nick is not opped on $chan on $network" "notice"
	} else {
		if {$ismod == "-1"} {
			pushmode $chan +m
			send_msg_db $fnetwork $fnick "$nick: $chan +m on $network" "notice"
		} else {
			pushmode $chan -m
			send_msg_db $fnetwork $fnick "$nick: $chan -m on $network" "notice"
		}
	}
}
 
proc send_msg_db {network target msg type} {
	global db
	set qry "INSERT INTO `outgoing_messages`(`message`,`type`,`network`,`target`) VALUES('$msg','$type','$network','$target')"
	mysqlsel $db(sqlhand) $qry
}
 
# Topic function
proc do_mass_topic {nname channel mtopic} {
	set what [lrange $mtopic 0 end]
	if {$what == ""} {
		puthelp "NOTICE $nname :Usage: .topic <Topic you want.>"
	return 1
	}
	if {![botisop $channel]} {
		puthelp "NOTICE $nname :TOPIC CHANGED FAILED ON $channel NO OPS."
	return 1
	}
	#putserv "TOPIC $channel :$what - $nname"
	#save_topic $nname $channel $what
return 1
}
 
# Topic save function
proc save_topic {nname channel topic} {
	global topicdir tp
	set tpfile [open $topicdir/${tp}.$channel w]
	puts $tpfile "$topic"
	puts $tpfile "$nname"
	close $tpfile
	putlog "Successfully save topic for $channel"
return 1
}
 
# Check the topic, if it doesn't match the one on file, change it back
proc check_topic {tpnick uhost hand channel topic} {
	global topicdir tp
	if {[file exists $topicdir/${tp}.$channel]} {
		set tpfile [open $topicdir/${tp}.$channel r]
		gets $tpfile ttopic
		gets $tpfile nname
		close $tpfile
		if {$topic != "$ttopic - $nname"} {
			#putserv "TOPIC $channel :[join $ttopic] - [join $nname]"
		}
	} else {
		putlog "No topic file $topicdir/${tp}.$channel for $channel exists."
	}
return 1
}
 
putlog "GT-mass.tcl by slackin LOADED"