egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Store Images

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Football
Master


Joined: 26 Dec 2008
Posts: 205
Location: Quakenet, #Football

PostPosted: Fri Dec 23, 2011 12:40 pm    Post subject: Store Images Reply with quote

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.
Back to top
View user's profile Send private message
username
Op


Joined: 06 Oct 2005
Posts: 196
Location: Russian Federation, Podolsk

PostPosted: Mon Dec 26, 2011 9:46 am    Post subject: Reply with quote

It based on this: http://www.egghelp.org/cgi-bin/tcl_archive.tcl?mode=download&id=939 , My and Drilly`s modifications.

Code:
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/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Football
Master


Joined: 26 Dec 2008
Posts: 205
Location: Quakenet, #Football

PostPosted: Fri Dec 30, 2011 9:03 am    Post subject: Reply with quote

hey username, thanks a lot for your help, it works great!
_________________
Idling at #Football, Quakenet.
Back to top
View user's profile Send private message
Football
Master


Joined: 26 Dec 2008
Posts: 205
Location: Quakenet, #Football

PostPosted: Fri Dec 30, 2011 1:53 pm    Post subject: Reply with quote

Any chance for an improvement for that script?

That it resizes images way too big to a default size?
_________________
Idling at #Football, Quakenet.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber