This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Store Images

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Store Images

Post by Football »

Hey,

I need a script that will store links to .jpg, .bmp, .gif files, into a txt file (will make sure theres no duplicates, meaning won't save the same link twice) and then when someone types !image it will randomly paste a link to the channel.

Of course the script must have protections so people can't flood and the bot won't quit due to flood.

* When the image displayed its displayed with a number, such as 'Image #55: http://www....'

Then you can also !erase 55 to remove it

Thanks
Idling at #Football, Quakenet.
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

It based on this: http://www.egghelp.org/cgi-bin/tcl_arch ... oad&id=939 , My and Drilly`s modifications.

Code: Select all

set piccheck(version) "0.1"
set filePath /var/www/pictures.html


bind pub - !plast urlshow
proc urlshow {nick ushost hand chan text} {
global filePath
    set file [open $filePath r]
    set data [read $file]
    close $file
    putlog [llength [split $data \n]]
    set plast [string map {<br> "" <b> "\002" </b> "\002" "<img src=\"" "\00312\037" "\">" "\037"} [lindex [split $data \n] [expr [llength [split $data \n]]-2]]]
    putserv "PRIVMSG $chan :Last picture: $plast"
}

bind pubm - * urlcheck

setudef flag piccheck

proc urlcheck { nick uhost hand chan str } {
global piccheck
set urlcheck(ext) {
       jpg
       jpe
       jpeg
       gif
       png
}
if {![regexp {((?:http://|www\.)+[^ ]+)} $str str]} { return 0 }
set extension ""
       set wlink $str
       regsub -all -- {(http://)+} $str "" str
       regexp {(www.)?[A-z|0-9|\-|\.|\_]*\.[A-z]{2,3}} $str host
       regexp {[/]+(.)*} $str url
       regexp {[A-z]{3,4}$} $str extension
       set ispic 0
       foreach i $urlcheck(ext) {
               if {[string match -nocase $extension $i]} {
                       set ispic 1
               }
       }
       if {$ispic != 1} { return 0 }
       set linecheck "[getdata $host $url $chan]"
       putlog "-- $linecheck"
       set ispic 0
       if {[string match -nocase *error* $linecheck]} { putserv "PRIVMSG $chan :\002Error:\002 $linecheck. \002Not a picture.\002"; set ispic 1 }
       if {[string match -nocase "*<html>*" $linecheck]} { putserv "PRIVMSG $chan :\002Error:\002 $linecheck. \002Not a picture.\002"; set ispic 1 }
       #putlog $linecheck
       global filePath
       set file [open $filePath r]
       set data [read $file]
       close $file
       set already 0;
       foreach line [split $data \n] {
           if { [string match -nocase "*$wlink*" "$line"] == 1 } {
               catch {unset data}
               set already 1
               putserv "PRIVMSG $chan :\002$nick\002, your link already exists."
           }
       }
       if { $ispic == 0 && $already == 0 } {
              set file [open $filePath "a"]
              puts $file "<br><b>Added by $nick at [time] [date]<b><br> \<img src=\"$wlink\"\><br>"
              close $file
putserv "PRIVMSG $chan :\002$nick\002, your link already in base."
       }
}

proc getdata { host url chan } {
global sock
               if {[string match "*error*" [open_socket $host $url $chan]]} { return "error"}
               gets $sock line
               if {[string match -nocase "*HTTP/1.? 301 Moved*" $line]} {
                       while {![eof $sock]} {
                               gets $sock line
                               if {[string match -nocase "*Location*" $line]} {
                                       set url [lindex [split $line] 1]
                                       regsub -all -- {(http://)+} $url "" url
                                       regexp {[/]+(.)*} $url url
                                       close $sock
                                       open_socket $host $url $chan
                                       gets $sock line
                                       break
                               }
                       }
               }
               if {![string match "HTTP/1.? 200 OK" $line]} { close $sock;return "error($line)" }
               set msg ""
               while {(![eof $sock]) && ([string length $line] != 0)} {
                       gets $sock line

                       if {[string match -nocase *server* $line]} {regsub -all -- "Server" $line "\002Server\002" line; append msg $line }
                       if {[string match -nocase *date* $line]} {regsub -all -- "Date" $line "\002Date\002" line; append msg ", " $line }

                       if {[string match -nocase *content*type* $line]} { 
                           if {![string match -nocase "*image/*" "$line"]} {
                           close $sock
                           return error
                           }
                       regsub -all -- "Content-Type" $line "\002Content-Type\002" line; append msg ", " $line
                       }

                       if {[string match -nocase *content*length* $line]} {regsub -all -- "Content-Length" $line "\002Content-Length\002" line; append msg ", " $line }
                       if {[string match -nocase *connection* $line]} {regsub -all -- "Connection" $line "\002Connection\002" line; append msg ", " $line }
                       if {[string match -nocase *keep*alive* $line]} {regsub -all -- "Keep-Alive" $line "\002Keep-Alive\002" line; append msg ", " $line }
                       if {[string match -nocase *expires* $line]} {regsub -all -- "Expires" $line "\002Expires\002" line; append msg ", " $line }
                       if {[string match -nocase *cache*control* $line]} {regsub -all -- "Cache-Control" $line "\002Cache-Control\002" line; append msg ", " $line }
                       if {[string match -nocase *accept*ranges* $line]} {regsub -all -- "Accept-Ranges" $line "\002Accept-Ranges\002" line; append msg ", " $line }
               }
               gets $sock line
               close $sock
putserv "PRIVMSG $chan :[string trim [join [append msg "."]] ", "]"
return $line
}

proc open_socket { host url chan } {
global sock
#putlog "Host: $host - url : $url"

       if {[catch {set sock [socket [string map -nocase {www. ""} $host] 80] } sockerror]} {
               putserv "PRIVMSG $chan: \002Error:\002 $sockerror"
               return "error: $sockerror"
       } else {
               puts $sock "GET $url HTTP/1.1"
               puts $sock "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
               puts $sock "Accept :*/*"
               puts $sock "Host: $host"
               puts $sock ""
               flush $sock
       }
}

putlog "Drilly's Picture-URL-Saver $piccheck(version) loaded..."
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

hey username, thanks a lot for your help, it works great!
Idling at #Football, Quakenet.
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

Any chance for an improvement for that script?

That it resizes images way too big to a default size?
Idling at #Football, Quakenet.
Post Reply