Kuvaton Eggdrop script

A very simple little TCL script for an eggdrop bot that will grab either some random images or return search results from http://kuvaton.com/. Any problems or suggestions just let me know.

Example:

kuv

Script should hopefully be quite readable and reusable 🙂

####################################################################
# Name                  moonie:kuvaton    			   #  
# Author		m00nie			                   #
# Description           Grabs some random pics or allow a reach of #
#			Kuvaton: http://www.kuvaton.com  	   #
# Version               1.1                                        #
# Requirements          http packages for tcl                      #
# Additional info	http://wp.me/p25Sys-fy (www.m00nie.com)	   # 
####################################################################

namespace eval moonie {
   namespace eval kuvaton {
        package require http
        bind pub - !kuv moonie::kuvaton::random
        bind pub - !ks moonie::kuvaton::search
        variable version "1.1"
        ::http::config -useragent "Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0"

proc search {nick uhost hand chan text} {
        putlog "moonie::kuvaton::search is running"
        regsub -all {\s+} $text "%20" text
        set url "http://kuvaton.com/search/index.php?find=$text"
        set repeat "4"
        set regex "http:\/\/kuvaton.com/kuvei\/.*?\""
        puthelp "PRIVMSG $chan :[getinfo $nick $chan $url $repeat $regex]"
}

proc random {nick uhost hand chan text} {
        putlog "moonie::kuvaton::random is running"
        set url "http://kuvaton.com/1/rand/"
        set repeat "4"
        set regex "http:\/\/pics.kuvaton.com/kuvei\/.*?\""
        puthelp "PRIVMSG $chan :[getinfo $nick $chan $url $repeat $regex]"
}

proc getinfo {nick chan url repeat regex} {
        putlog "moonie::kuvaton::getinfo is running"
        putlog "moonie::kuvaton::getinfo Nick: $nick, Chan: $chan, URL: $url"
        if { [catch {
                global botnick
                for { set i 1 } { $i <= 5 } { incr i } {
                        set rawpage [::http::data [::http::geturl "$url" -timeout 5000]]
                        if {[string length rawpage] > 0} { break }
                }
                putlog "moonie::kuvaton::getinfo Rawpage length is: [string length $rawpage]"
                if {[string length $rawpage] == 0} { error "kuvaton returned no data 🙁 or we couldnt connect properly" }

                set pagepics [regexp -all -inline "$regex" $rawpage]
                putlog "moonie::kuvaton::getinfo pagepics lenght is: [string length $pagepics]"
                if {[string length $pagepics] == 0} { error "No pics, sorry :(" }
                putlog "moonie::kuvaton::getinfo uncleaned URLs are: $pagepics"

                printout ($nick $chan $pagepics $repeat)
                } catch] == 1} { putlog "moonie::kuvaton failed: $catch"; return "$catch" }\
                else { return $catch }
}


proc printout {nick chan urllist repeat} {
        for {set i 0} {$i < $repeat} {incr i} {
                putlog "moonie::kuvaton::printout is running loop number $i"
                set link [lindex $urllist $i]
                set link [string range $link 0 end-1]
                regsub -all {\s+} $link "%20" link
                putlog "moonie::kuvaton::printout clean links are: $link"
                puthelp "PRIVMSG $chan $link"
        }
}
}
}
putlog "moonie::kuvaton $moonie::kuvaton::version loaded"

As ever any comments or suggestions are welcome

m00nie 😀