Language: EN FR PT ES NL DE SV RU
######################################################################
#                                                                    #
#====================================================================#
# gt-sqlmsg.tcl by slackin                                           #
#====================================================================#
# Slackin's sqlmsg table relay companion for PugBot!                 #
# Custom written for #pugbot & GT                                    #
######################################################################
#                                                                    #
######################################################################
######################################################################
# Config section, please edit with                                   #
# proper info                                                        #
#--------------------------------------------------------------------#
 
#--------------------------------------------------------------------#
# End of config section                                              #
######################################################################
######################################################################
 
# load the mysqltcl interface
package req mysqltcl
bind msg o "startmsg" start_msg_sql
 
set qbot "1"
set gbot "1"
 
proc start_msg_sql {nick host hand arg} {
	after 250 sqlmsg_do_table                      
	set sqlmsg_running 1
	putlog "Manual Start"
}
 
if {![info exists sqlmsg_running]} {   
	after 250 sqlmsg_do_table                      
	set sqlmsg_running 1
	putlog "Auto Start"
}                                      
 
proc sqlmsg_do_table {} {
	global db qbot gbot
	#putlog "running...."
	# your stuff here ...              
	# ...
	set qry "SELECT * FROM $db(tbl_msg) ORDER BY message_id"
	#putlog "Before query"
	foreach row [mysqlsel $db(sqlhand) $qry -list] {
		# quote
		#putlog "After query"
		set msgsend [lindex $row 1]
		set msgid [lindex $row 0]
		set msgtype [lindex $row 2]
		set msgnetwork [lindex $row 3]
		set msgtarget [lindex $row 4]
		#putlog "Before delete query"
		set qry "DELETE FROM $db(tbl_msg) WHERE message_id = '$msgid'"
		mysqlsel $db(sqlhand) $qry
		#putlog "Before switch"
		switch $msgnetwork {
			QuakeNet {
				switch $msgtype {
					GT-0 {
					    set tobot "qnet-0"
					    set msgtype "notice"
					}
					GT-1 {
					    set tobot "qnet-1"
					    set msgtype "notice"
					}
					GT-2 {
					    set tobot "qnet-2"
					    set msgtype "notice"
					}
					GT-3 {
					    set tobot "qnet-3"
					    set msgtype "notice"
					}
					GT-4 {
					    set tobot "qnet-4"
					    set msgtype "notice"
					}
					GT-5 {
					    set tobot "qnet-7"
					    set msgtype "notice"
					}
					GT-6 {
					    set tobot "qnet-8"
					    set msgtype "notice"
					}
					GT-7 {
					    set tobot "qnet-7"
					    set msgtype "notice"
					}
					GT-8 {
					    set tobot "qnet-8"
					    set msgtype "notice"
					}
					GT-9 {
					    set tobot "qnet-9"
					    set msgtype "notice"
					}
					GT-INFO {
					    set tobot "qnet-10"
					    set msgtype "notice"
					}
					default {
						set tobot "qnet-$qbot"
						if {$qbot == "4"} {
							set qbot "1"
						} else {
							set qbot [expr $qbot + 1]
						}
					}
				}
			}
			GameSurge {
				switch $msgtype {
					GT-0 {
					    set tobot "gs-0"
					    set msgtype "notice"
					}
					GT-1 {
					    set tobot "gs-1"
					    set msgtype "notice"
					}
					GT-2 {
					    set tobot "gs-2"
					    set msgtype "notice"
					}
					GT-3 {
					    set tobot "gs-3"
					    set msgtype "notice"
					}
					GT-4 {
					    set tobot "gs-4"
					    set msgtype "notice"
					}
					GT-5 {
					    set tobot "gs-7"
					    set msgtype "notice"
					}
					GT-6 {
					    set tobot "gs-8"
					    set msgtype "notice"
					}
					GT-7 {
					    set tobot "gs-7"
					    set msgtype "notice"
					}
					GT-8 {
					    set tobot "gs-8"
					    set msgtype "notice"
					}
					GT-9 {
					    set tobot "gs-9"
					    set msgtype "notice"
					}
					GT-INFO {
					    set tobot "gs-10"
					    set msgtype "notice"
					}
					default {
						set tobot "gs-$gbot"
						if {$gbot == "4"} {
							set gbot "1"
						} else {
							set gbot [expr $gbot + 1]
						}
					}
				}
			}
			default {
				putlog "no var tobot set, please check tables..."
				putlog "$msgtype $msgnetwork $msgtarget $msgsend"
				set tobot "bum"
			}
		}
		#putlog "After switch"
		if {[lsearch -exact [bots] $tobot] != -1} {
			putbot $tobot "pugrelay $msgtype $msgnetwork $msgtarget $msgsend"
			#putlog "$tobot pugrelay $msgsend $msgtype $msgnetwork $msgtarget $msgid"
		}
	}
	#putlog "Before timer call"
	after 250 sqlmsg_do_table
	#putlog "After timer call"
return 1                           
}
 
putlog "GT-sqlmsg.tcl by slackin LOADED"