All pastes #632927 Raw Edit

Miscellany

public text v1 · immutable
#632927 ·published 2007-07-25 09:37 UTC
rendered paste body
package require mysqltcl

bind pub -|- !pre usePre
bind pub -|- !dbstats dbstat
#bind pub -|- !addpre addIt
#bind pub -|- !info infoCalled
#bind pub -|- !sitepre siteCalled
#bind pub -|- !nuke newNuke
#bind pub -|- !unnuke newUnNuke
#bind pub -|- !gn newGN
#bind pub -|- !delpre preRm

#bind bot -|- !addpre botPre
#bind bot -|- !nuke botNuke
#bind bot -|- !info botInfo
#bind bot -|- !unnuke botUnNuke
#bind bot -|- !delpre botDEL


bind pubm -|- "*" catchNew

set gtable "activedata"


proc botDEL { from command text } {

	        
        if {[string equal [string tolower $from] "efnet"] ==1} {
                #putserv "PRIVMSG #sun :$command $text"
        } else {
                #putserv "PRIVMSG #cxHQ :$command $text"
                #putserv "PRIVMSG #sun :$command $text \002$from"
        }


}

proc newUnNuke { nick uhost hand chan text } {
	#putserv "PRIVMSG $chan :!unnuke $text"
	#putserv "PRIVMSG #confusion :!unnuke $text"
	#putallbots "!unnuke $text"
	useUnNuke [lindex $text 0] [lindex $text 1] $nick
}

proc newNuke { nick uhost hand chan text } {
	#putserv "PRIVMSG $chan :!nuke $text"
	#putserv "PRIVMSG #confusion :!nuke $text"
	#putallbots "!nuke $text"
	useNuke [lindex $text 0] [lindex $text 1] $nick
}

proc newGN { nick uhost hand chan text } {
	useGC [lindex $text 0] [lindex $text 1]
}


#the most import catch of them all.
#
proc botPre {from command text} {

	#putserv "PRIVMSG #cxHQ :$command $text"

	putserv "PRIVMSG alexis :\002$from\002 $command $text"

	if {[string equal [string tolower $from] "irc.atx-team.com"] ==1} {
		putserv "PRIVMSG #psr :$command $text"
	} else {
		putserv "PRIVMSG #cxHQ :$command $text"
		putserv "PRIVMSG #psr :$command $text \002$from"
	}

}

proc botUnNuke {from command text} {

	if {[string equal [string tolower $from] "efnet"] ==1} {
                #putserv "PRIVMSG #psr :$command $text"
        } else {
                putserv "PRIVMSG #cxHQ :$command $text"
                putserv "PRIVMSG #psr :$command $text \002$from"
        }


	
	#putserv "PRIVMSG #cxHQ :$command $text"
	#putserv "PRIVMSG #sun :$command $text"
}


proc botNuke {from comand text} {
	

	if {[string equal [string tolower $from] "efnet"] ==1} {
                #putserv "PRIVMSG #sun :$comand $text"
	} else {
                putserv "PRIVMSG #cxHQ :$command $text"
                putserv "PRIVMSG #sun :$command $text \002$from"
        }


	#putserv "PRIVMSG #cxHQ :$comand $text"
	#putserv "PRIVMSG #sun :$comand $text"
}

proc botInfo {from comand text} {
	
	#putserv "PRIVMSG blackcat :\002$from\002 $comand $text"

	if {[string equal [string tolower $from] "efnet"] == 1} {
		#putserv "PRIVMSG #sun :$comand $text"
	} else {
		putserv "PRIVMSG #cxHQ :$comand $text"
		putserv "PRIVMSG #sun :$comand $text \002$from"
	}

}

proc preRm {nick uhost hand chan text} {
	useDel [lindex $text 0] [lindex $text 1] $nick
}


#
#This is for site pres
#
proc siteCalled {nick uhost hand chan text} {
    #addToDb [lindex $text 1] [lindex $text 0] [lindex $text 2] [lindex $text 3] $nick
    #infoInsert [lindex $text 0] [lindex $text 2] [lindex $text 3]
}


proc addIt { nick uhost hand chan text} {
	
	if {[string equal $chan "#alexispre4"] == 1} {
		putserv "PRIVMSG #alexispre4 :\0034HELL\003 No BiTCH"
		return 0
	}


	if {[string equal $chan "#alexispre3"] == 1} {
		putserv "PRIVMSG #alexispre3 :\0034Hell fucking no\003"
		return 0
	}

	if {[string equal $chan "#alexispre5"] == 1} {
		putserv "PRIVMSG #alexispre5 :\0034HELL FUCKING NO"
		return 0
	}

	if {[string equal $chan "#alexispre2"] == 1} {
		putserv "PRIVNSG #alexispre2 :\0034 hell fucking no"
		return 0
	}


    addToDb [lindex $text 1] [lindex $text 0] $nick
	
}


proc infoCalled {nick uhost hand chan text} {
    infoInsert [lindex $text 0] [lindex $text 1] [lindex $text 2] $nick
}


proc useDel {rls why nick} {
global gtable
		
	set db [getInstance]
		
	set output [mysqlsel $db "SELECT * FROM $gtable WHERE rls = '$rls' LIMIT 1;" -list]
	if {[string equal "" $output] == 1} {
		putserv "PRIVMSG #psr :rls not found"
        	mysqlclose $db
       		return 0
	}	
		
		
	if {[catch { mysqlexec $db "delete from $gtable where rls='$rls';"} data ]} {
		putserv "PRIVMSG #psr :\002$rls\002 wants to be removed \0034$why\0034 , but $data"
	}	
		
		
	if {[onchan $nick "#psr"]} {
                putserv "PRIVMSG #psr :!delpre $rls $why"
        } else {
                putserv "PRIVMSG #psr :!delpre $rls $why"
        }	
		
		
	putallbots "!delpre $rls $why"
		
		
	putserv "PRIVMSG #psr :\002JUST REMOVED \0034$rls $why"
}

#
# This will set the size and files.
#
proc infoInsert {rlsname files size nick} {
global spamchan
global gtable

    set db [getInstance]

    #not about to add something we already have in the database.
    if {[string equal $files "0"] == 1 && [string equal $size "0"] ==1 } {
	return 0
    }

    if {[string equal $files ""] == 1 && [string equal $size ""] == 1} {
	return 0
    }
    
  
    set match [findMatch $rlsname]


   set output [mysqlsel $db "SELECT files,size FROM $gtable WHERE rls = '$rlsname' LIMIT 1;" -list]
   set output [lindex $output 0]
	
	
   if { [string equal "0" [lindex $output 0]] == 0 || [string equal "0" [lindex $output 1]] == 0} {
        mysqlclose $db
    	return 0
   }	
	
	
	
    set type [lindex $match 1]
	
    if {[string equal [string index $match end-1] ")"] == 1} {
	#putserv "PRIVMSG #psr :Already have a file size for [string index $match end-1] other $match"
	mysqlclose $db
	return 0
    }	
	
	#putserv "PRIVMSG #psr :This is Info $rlsname $size $files"
 	
    if { [catch {mysqlexec $db "UPDATE $gtable set files='$files',size='$size' where rls='$rlsname';"} data] } {
	putserv "PRIVMSG #psr :Tryed to update files for $rlsname but failed $data"
	addToDb $rlsname "UNKNOWN" "INFO"
	mysqlclose $db
	infoInsert $rlsname $files $size
	return 0
    }	
	
    mysqlclose $db
    
    
	#if {[onchan $nick "#psr"]} {
		#putserv "PRIVMSG #psr :!info $rlsname $files $size"
	#} else {
		putserv "PRIVMSG #psr :!info $rlsname $files $size"
	#}
	
	putallbots "!info $rlsname $files $size"
	
}


proc useNuke {rls why nick} {
global gtable

	set db [getInstance]

		
	set output [mysqlsel $db "SELECT nuke FROM $gtable WHERE rls = '$rls' LIMIT 1;" -list]
        
        if {[string equal "" $output] == 1 || [string equal "1" [lindex $output 0]] == 1} {

		if {[onchan $nick "#sun"]} {
			#putserv "PRIVMSG #psr :\0034 $rls was already nuked"
		}

                mysqlclose $db
                return 0
            }


	if { [catch {mysqlexec $db "UPDATE $gtable set why='$why' where rls='$rls';"} data] } {
		putserv "PRIVMSG #psr :was unable to update $data"
	}	
	if {[catch {mysqlexec $db "UPDATE $gtable set nuke='1' where rls ='$rls';"} dataO] } {
		putserv "PRIVMSG #psr :was unable to nuke $data0"
	}



	if {[onchan $nick "#psr"]} {
                putserv "PRIVMSG #psr :!nuke $rls $why"
        } else {
                putserv "PRIVMSG #psr :!nuke $rls $why"
        }


	putallbots "!newnuke $rls $why"

	mysqlclose $db
	return 0

}


proc useUnNuke {rls why nick} {
global gtable
	
	set db [getInstance]
	set output [mysqlsel $db "SELECT nuke FROM $gtable WHERE rls = '$rls' LIMIT 1;" -list]
    	
	if {[string equal "" $output] == 1 || [string equal "0" [lindex $output 0]] == 1} {
		if {[onchan $nick "#blackcatism"]} {
			#putserv "PRIVMSG #psr :\0034$rls was never nuked"
		}
        	mysqlclose $db
       		return 0
	 }

	

	#set db [getInstance]
        if { [catch {mysqlexec $db "UPDATE $gtable set why='$why' where rls='$rls';"} data] } {
                putserv "PRIVMSG #psr :was unable to update $data"
        }
       
        if {[catch {mysqlexec $db "UPDATE $gtable set nuke='0' where rls ='$rls';"} dataO] } {
                putserv "PRIVMSG #psr :was unable to nuke $data0"
        }

	



        if {[onchan $nick "#psr"]} {         
                putserv "PRIVMSG #psr :!unnuke $rls $why"
        } else {
                putserv "PRIVMSG #psr :!unnuke $rls $why"        
        }
	
	
	putallbots "!unnuke $rls $why"

}

proc useGC {rls new} {

global gtable	

	
	set db [getInstance]
	if { [catch {mysqlexec $db "UPDATE $gtable set mtype='$new' where rls='$rls';"} data] } {
		putserv "PRIVMSG #psr :Was unable to update $rls $new"
	}

	mysqlclose $db
	return 0

}


#
#This is for removing something from something section :)
#
# removes rls and adds to the nuke
#
proc delNuke {rls section} {


    set db [getInstance]

    set output [mysqlsel $db "SELECT * FROM $gtable WHERE rls = '$rls' LIMIT 1;" -list]
    if {[string equal "" $output] == 1} {
	mysqlclose $db
	return 0
    }


    #Says it valid, and that were just removed it from the other section.
    if { [string equal [findMatch $rls] ""] ==0 } {
	mysqlexec $db "delete from $section where rls='$rls';"
    }
    



	

    #Adds rls to the nuke section.
    addToDb "NUKE" $rls "0" "0"    
    mysqlclose $db

}



#
#Used to return the stats of the data base.
#
proc dbstat {nick uhost hand chan text } {

    putserv "PRIVMSG $chan :\002 \0030building\002\0037.....\002"

    set db [getInstance]
    set i 0
    set p 0

    foreach type [mysqlinfo $db tables] {
	foreach number [mysqlsel $db "SELECT FOUND_ROWS() from $type;" -list] {
	    incr i
	    incr p
	}
	#putserv "PRIVMSG $chan :\002\(\002$type\002\)\002 has\00310 $i\002 entrys"
	set i 0
    }
    
    putserv "PRIVMSG $chan :\002\[\002\ \0037database\002\ \0030]\002\0030 $p releases"

    mysqlclose $db

}





#for used in other
#
#
proc usePre {nick uhost hand chan text} {

    set key [lindex $text 0]

    #Full Rls to the channel.
    if { [string match "*.*" $key] ==1 && [string match "*-*" $key] == 1 || [string match "*_*" $key] ==1 && [string match "*-*" $key] == 1 } {
	set nick $chan
    }

    set dataOut [findMatch $key]

    if {[string equal $dataOut ""] == 1 } {
	putserv "PRIVMSG $chan :no encontre nada de $key cono"
	return 0
    }

    #putserv "PRIVMSG #blackcatism :$dataOut"
	
    foreach line [split $dataOut "\n"] {
	putserv "PRIVMSG $nick :$line"
    }

}


#THis will return any matchs with a current rls.
proc findMatch {keyed} {
global gtable

    set db [getInstance]
    set count 0
    set output ""

    set data [mysqlsel $db "select *,SEC_TO_TIME(unix_timestamp(now()) - unix_timestamp(<b style="color:black;background-color:#ffff66">pretime</b>)) as data from $gtable WHERE rls like '%$keyed%' GROUP BY data;" -list]
    mysqlclose $db

	if {[string equal $data ""] == 1} {
		#putserv "PRIVMSG #blackcatism :not found"
		return ""
	}
			
	foreach rls $data {
		set realrls [lindex $rls 0]
		set files [lindex $rls 2]
		set size [lindex $rls 3]
		set type [lindex $rls 4]
		set mtype [string toupper [lindex $rls 5]]
		set nuked [lindex $rls 6]
		set reason [lindex $rls 7]
		set now [lindex $rls 9]
			
		if {$count < 25} {
			#putserv "PRIVMSG #blackcatism :DATA\002 ->$rls"
			if {[string equal "0" $mtype] == 0} {
                                append output "\002\(\002\00311 $mtype \003\002\)\002"
                        }
			
			if {[string equal "0" $size] == 1 && [string equal "0" $files] == 1} {
				#putserv "PRIVMSG herbs :just added one with no size $rls"
				append output "\002\(\002\00311 $type\003 \002\)\002 $realrls [fixTime $now]"
			} elseif {[string equal "1" $nuked] == 1} {
				append output "\002\(\002 \00311NUKED\003 \002\)\002 $realrls [fixTime $now] \(\002$reason\002\)"
			} else {
				#putserv "PRIVMSG herbs :just added one with zero size $rls"
				append output "\002\(\002\00311 $type\003 \002\)\002 $realrls [fixTime $now] \(\002$files files $size mb\002\)"
			}
			
			incr count
			append output "\n"
			
		} else {
			break
		}	
	}		
			
    return $output	
}			
			
#
#This method will get a time 10:01:01 and fix it so people can understand it.
#
proc fixTime {daTime} {
    
    set temp [split $daTime ":"]
    
	if {[lindex $temp 0] == 0} {
    		append line " \00310[lindex $temp 1]\003" " \002Mins\002"  " \00310[lindex $temp 2]\003" " \002Seconds\002"
	} else {
		#putserv "PRIVMSG #blackcatism :Called Secound when we have [lindex $temp 0]"
		append line "\00310[lindex $temp 0]\003" " \002H\002" " \00310[lindex $temp 1]\003" " \002M\002"  " \00310[lindex $temp 2]\003" " \002S\002"
	}

    return $line
}


proc searchQuick { keyed } {
global gtable

    set db [getInstance]
    set count 0
    set output ""

    if { [catch {set data [mysqlsel $db "select rls,<b style="color:black;background-color:#ffff66">pretime</b>,section,nuke,files,size,SEC_TO_TIME(unix_timestamp(now()) - unix_timestamp(<b style="color:black;background-color:#ffff66">pretime</b>)) as data from $gtable WHERE rls like '%$keyed%';" -list]} data] } {
	putserv "PRIVMSG #psr :\002FAILED\002 to search $section $keyed -< $data"
	mysqlclose $db
	return 0
    }


	if {[string compare $data ""] != 0} {
	    foreach element $data {
		if { (10 > $count) } {
			putserv "PRIVMSG #psr :quick search data -< $data"
		    #putserv "PRIVMSG #moon :\(\0039  \003\) \( [lindex $element 0] \) [fixTime [lindex $element 2]]"
		    append output "\(\0039  \003\) \( [lindex $element 0] \) [fixTime [lindex $element 4]]  "
		    if {[string equal "-" [lindex $element 3]] == 0} {
			append output "\( \002[lindex $element 2]\002files "
			#putserv "PRIVMSG #moon :files -< [lindex $element 2]"
		    }
		    if {[string equal "-" [lindex $element 3]] == 0} {
			append output "\002[lindex $element 3]\002mb \)"
			#putserv "PRIVMSG #moon :size -< [lindex $element 3]"
		    }
		    append output "\n"
		    incr count
		}
	    }
	}
    
    mysqlclose $db
    return $output 
}


proc catchNew { nick uhost hand chan text } {

	    #putserv "PRIVMSG #psr :FOUND A NEW $text"
	    #putserv "PRIVMSG #psr :$text < NEW FOUND > [split $text "\["]"
    
    set text [fixColor $text]
    
    #putserv "PRIVMSG #moon :[lindex $text 1]"
    
    if {[string match "*NEW*" [lindex $text 1]] == 0} {
	return 0;
    }

    putserv "PRIVMSG #psr  :$text"

	    #set splited [split $text "\"]
	    #set matched [findMatch [string range $splited [lindex $splited 2] [lindex $splited ]]]
	    set type [string trim [lindex $text 5]]
	    set name [string trim [lindex $text 8]]
	    
    set theRls ""

    #putserv "PRIVMSG #psr : $type $name"


    if {[string equal $type "REQUESTS"] == 1} {
	set theRls [findMatch $name]
	putserv "PRIVMSG $chan :\002Allowed\002 $theRls"
	return 0
    } else {
	set theRls [findMatch $name]
	#if {[string equal $theRls ""] == 1} {
	    #set theRls [findMatch $name]
	#}
    }


    if {[string equal $theRls ""] == 0} {
		#putserv "PRIVMSG #psr :Age of Rls _,-.> [lindex $theRls 6] "
	#set theRls [fixColor $theRls]		


    	if {[string match "H*" $theRls] == 1 && [string compare [fixColor [lindex $theRls 6]] "01"] >= 0} {
       	    putserv "PRIVMSG $chan :\002BackFill\002 $theRls"
       	} else {
       	    putserv "PRIVMSG $chan :\002Allowed\002 $theRls"
       	}

    } else {
	#JUST FOUND A NEW PRE YA
	#putserv "PRIVMSG $chan :$type $nick $name"
	putserv "PRIVMSG alexis :\002NEW\002 $type $name"
	addToDb $type $name $nick
   }


}


#
#This will change the type of the data. to make sure that we don't have any errors.
#
proc fixName {type} {

    if { [string match "* *" $type] == 1} {
	putserv "PRIVMSG #psr :$type has found a blank"
	regsub -all { } [string range $type 0 [lindex [split $type] end-1]] {.} type
	putserv "PRIVMSG #psr :New type $type"
    }

}


#
#This will fix the type to be a real type.
#
proc fixType {name} {

    if {[string equal $name "-"] ==1 || [string equal "PRE" $name] == 1} {
	return "UNKNOWN"
    }   

    return [lindex [split [string toupper $name] "-"] 0]
}



#
#THIs method will RegSub the color codes
#
proc fixColor {textIn} {
    return [stripcodes bc $textIn]
}


#
# This method will add the info to the db
# and display it to some other channel
#
proc addToDb {type name nick} {
global gtable
	putserv "PRIVMSG #psr :\002 CALLED \002 $type $name"	

    if {[string equal $type ""] == 1 || [string equal $name ""] == 1} {
	putserv "PRIVMSG #psr :Tryed to add Blank Data"
	return -1;
    }

	#putserv "PRIVMSG #psr :called with $type $name $files $size"
	#putserv "PRIVMSG #psr :$name"

    #Full Rls to the channel.
    if {![string match *.*-* $name] && ![string match *_*-* $name]} {
	putserv "PRIVMSG #psr :\002SORRY BUT THIS COULD NOT BE ADDED DUE TO SPOOF $type $name"
        return 0

    } elseif { [string match "*dupe*" $name] ==1 } {
	putserv "PRIVMSG #psr :\002SORRY BUT THIS COULD NOT BE ADDED DUE TO SPOOF $type $name"
	return 0
    } elseif { [string length $name] < 13 } {
	putserv "PRIVMSG #psr :\002SORRY BUT THIS COULD BE A SPOOF $name"
	return 0
    } elseif { [string match "*trash*" $name] == 1 } {
	putserv "PRIVMSG #psr :\002SORRY BUT THIS COULD BE A SPOOF $name"
	return 0
   } elseif { [string match "*testpre*" [string tolower $name]] == 1 } {
	putserv "PRIVMSG #psr :\002 SPOOF $name"
	return 0
   } elseif { [string last $name "-"] < [string last $name "."] || [string last $name "-"] < [string last $name "_"] } {
	putserv "PRIVMSG #psr :\002 SPOOF $name"
	return 0
   }


	#putserv "PRIVMSG #psr :No SPOOF"

    #checkAdd $type
    set type [fixType $type]
    #checkAdd $type

    putserv "PRIVMSG $chan :Just added a \002$type\002 named \002$name\002 with the rls time \002$date\002 to the DataBase"

    #To be added later, l8s for n0w
    set group ""

    set db [getInstance]
    
    #This is going to check the mysql database for rls that are already added by it. NAME ONLY.

    set output [mysqlsel $db "SELECT * FROM $gtable WHERE rls = '$name' LIMIT 1;" -list]
	
    if { [string equal $output ""] != 1} {
	#putserv "PRIVMSG #psr :DUPE in the database., but not able to select from $output"
	mysqlclose $db
	return 0
    }


    #Says if we don't have a vaild table then lets make one.
    if { [catch {mysqlexec $db "INSERT into $gtable values ('$name','[getDate] [getTime]','0','0','$type','0','0','0','$nick');"} stuff] } {
	putserv "PRIVMSG blackcat :\002RESULT FAILED TO INSERT type _< $name >_ $stuff"
	#mysqlexec $db "create table $type (rls varchar(200),pretime datetime,files varchar(100),size varchar(100));"
	#mysqlexec $db "INSERT into $type values ('$name','[getDate] [getTime]','-','-');"
    }



    #putserv "PRIVMSG $chan :DATA called and stored -< $type $name $chan"
    mysqlclose $db


    #putserv "PRIVMSG $spamchan :$spmsg $name $type"

	putallbots "!addpre $name $type"

        if {[onchan $nick "#psr"]} {
                putserv "PRIVMSG #psr :!addpre $name $type"
        } else {
                putserv "PRIVMSG #psr :!addpre $name $type"
		putserv "PRIVMSG alexis :$name"
        }

	#putallbots "!addpre $name $type"

}


#Adds in the table if it is not found.
proc checkAdd { inTable } {

    #putserv "PRIVMSG #moon :$inTable"

    set flag "true"

    set db [getInstance]

    foreach table [mysqlinfo $db tables] {
	#putserv "PRIVMSG #moon :about to compair $table $inTable"
	if {[string equal $inTable $table] == 1} {
	    set flag "false"
	    #putserv "PRIVMSG #moon :was true"
	    break;
	}
    }

    #To to add a new table with that name.
    if {[string equal $flag "true"]  == 1} {
	putserv "PRIVMSG #psr :TRYED TO MAKE TABLE $inTable"
	
	if {[catch {mysqlexec $db "create table $inTable (rls varchar(200),pretime datetime,files varchar(100),size varchar(100));"} msg] } {
	    putserv "PRIVMSG #psr :Faild to make table $inTable"
	}
	
	#putserv "PRIVMSG #psr :table made"
    }

    mysqlclose $db

}


#
#This method will get the time
#
proc getTime {} {
    return [clock format [clock seconds] -format %T]
}


proc getDate {} {
    set temp [clock format [clock seconds] -format "%Y-%m-%d"]
    return $temp
}


#
#Just gets the data mysql buffer or whatever
#
proc getInstance {} {
    return [mysqlconnect -user alexis -password alexis -db mysql]
}



#THIS PROC will check our database, as well as open a connection to it.
proc startup {} {

    #putserv "PRIVMSG #psr :\002\[\002\ \0037prebot v1.0 by alexis loaded\002\ \0030]"

	#makes sure we can axx the db
    set db [getInstance]
    mysqlclose $db

	
}


startup