All pastes #760785 Raw Edit

Stuff

public text v1 · immutable
·published 2007-11-04 10:30 UTC
rendered paste body
bind pub m|- !blacklist pub:search
proc pub:search {nick uhost hand chan text} {
global settings
    set file "search.db"

    if {![file exists $file]} {set fds [open $file w]; puts "# $file"; close $fds;}
      set where $settings(suppchan)
	set aqwzsx [lindex $text 0]
	set lsn [lindex $text 1]
	set expire [lindex $text 2]
	set starter [join [lrange $text 3 end]]
      set jessicayhip [unixtime] ;#date
    switch -- $aqwzsx {      
        
             -add {
		set fdz [open $file r]
		set conte [read $fdz]
		close $fdz
            set tm [convert_to_ut $expire]
            if {[string match -nocase "*$lsn*" $conte]} {puthelp "privmsg $chan :This channel ($lsn) already exist in our blacklist database."; return }
            set fd [open $file a+]
            puts $fd "$lsn $hand $where $jessicayhip $starter $tm"
            close $fd
            puthelp "PRIVMSG $chan :\002SEARCH\002 Added channel $lsn to database $file by ${hand}, ${where}, on [ctime $jessicayhip] reason: $starter, will expire on: $expire"
        }
        -remove {
        set fdz [open $file r]
         set conte [read $fdz]
         close $fdz
        if {![string match -nocase "*$lsn*" $conte]} {puthelp "privmsg $chan :This nickname ($lsn) doesn't exist in our blacklist database."; return }

            set fd [open $file r]
            set reads [read $fd]
            close $fd
            set data ""
            
            if {[llength $reads]} {
                set fd [open $file w]
                    foreach line [split $reads \n] {
                    if {![string match -nocase *$lsn* $line]} {
                        if {[llength $line]} {puts $fd "$line\n"}
                    }
                }
                close $fd
                puthelp "PRIVMSG $chan :\002SEARCH\002 I removed the nick $lsn from $file"
            }
        }    
            -verify {
            set fd [open $file r]
            set cont [read $fd]
            close $fd
            foreach abuse [split $cont \n] {if {[string match -nocase "*$lsn*" $abuse]} {
                      set a1       [lindex $abuse 0]           ;#chan
                      set b2       [lindex $abuse 1]           ;#hand
                        set c3       [lindex $abuse 2]           ;#who
                set d4       [lindex $abuse 3]           ;#time
                        set e5       [join [lrange $abuse 4 end-1]]    ;#reason
                        set f6        [lindex $abuse end]     ;#expiration time
                        set f6        [clock format $f6 -format %d.%m.%Y]      ;#converting to human time format
                puthelp "PRIVMSG $chan :\002SEARCH\002 $a1 blacklisted by ${b2}, ${c3}, on [ctime $d4], reason: $e5, will expire on: $f6"}
                return 1
            }
            return 0
        }
            -list {
            set fd [open $file r]
            set cont [read $fd]
            close $fd
            set listabuse ""
            foreach abuse [split $cont \n] {lappend listabuse "[lindex $abuse 0]"}
            puthelp "PRIVMSG $chan :\002SEARCH\002 I retrieved the following list from ${file}: [join $listabuse]"
        } 
        default {puthelp "privmsg $chan :Usage: !search <-add|-remove|-verify|-list> \$chan"}
    }
}

proc convert_to_ut {date} {
regexp {([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})} $date date dd mm yyyy
clock scan $mm/$dd/$yyyy
}

proc check_if_expired {} {
            set currtime [unixtime]
            set fd [open $file r]
            set reads [read $fd]
            close $fd
            set data ""
            
            if {[llength $reads]} {
                set fd [open $file w]
                foreach line [split $reads \n] {
		    set tte [lindex $line end]
                    if {$tte > $currtime} {
                        if {[llength $line]} {puts $fd "$line\n"}
                    }
                }
                close $fd
            }
}