Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######################################################
- # WindropClan @ http://windrop.clan.su
- # Автор: Vertigo
- # Версия: 2.1 (mod Vladislav)
- # Описание: Скрипт цитирует заголовок URL-ссылки, когда ее пишут в канал.
- # Юзеры с флагом I (глобал) будут игнорироваться скриптом.
- # Команда: !ссылки
- ######################################################
- namespace eval title {
- # На фразы, начинающиеся с указанных символов не будет реакции:
- variable denyprefixes {"!" "$" "." "^"}
- # На указанные домены будет осуществляться автореагирование (помимо http://):
- variable domains {".ru" ".com" ".org" ".su" ".info" ".net" ".de" ".au" ".ua"}
- # [1/0] Разрешить реагирование на текст, содержащий только домены (без http://):
- variable nodomains 0
- # Максимальное число редиректов:
- variable maxredirects 5
- # Таймут соединения (в секундах):
- variable timeout 10
- # Сколько байт скачивать при запросе (актуально, если сервер поддерживает Accept-Range):
- variable readlimit 11564
- # Юзер-агент:
- variable useragent {Opera/9.52 (Windows NT 5.1; U; en)}
- # [1/0] Включить отладку:
- variable debug 0
- # Шаблон вывода сообщения в канал:
- variable deftemplate {\037Заголовок\037:}
- # Защита от флуда (в секундах):
- variable flood 5
- # Канальный флаг, разрешающий/запрещающий работу скрипта:
- variable flagactas "no"
- variable chflag "$flagactas[namespace tail [namespace current]]"
- setudef flag $chflag
- if {![catch {package require tls} err]} {::http::register https 443 ::tls::socket; variable using_ssl 1} else {variable using_ssl 0}
- variable redir 0
- variable clock 0
- variable template ""
- bind pubm - * ::title::pub
- bind ctcp - "ACTION" ::title::actn
- if {[info exists sp_version]} {set ::max_tcl_events 20; set ::select_timeout 100}
- proc pub {nick uhost hand chan text} {
- variable chflag ; variable flagactas
- if {![channel get $chan $chflag] ^ $flagactas eq "no" } {return}
- if {[info exists ::vktitle::clock] && ([string match -nocase "*http://vk.com*" $text] || [string match -nocase "*https://vk.com*" $text] || [string match -nocase "*.vk.com*" $text] || [string match -nocase "*http://vkontakte.ru*" $text] || [string match -nocase "*https://vkontakte.ru*" $text] || [string match -nocase "*.vkontakte.ru*" $text])} {return}
- if {[info exists ::youtubetitle::clock] && ([string match -nocase "*http://*youtube*watch*" $text] || [string match -nocase "*https://*youtube*watch*" $text] || [string match -nocase "*http://youtu.be/?*" $text] || [string match -nocase "*https://youtu.be/?*" $text])} {return}
- if {[info exists ::bash::clock] && [string match -nocase "*http://bash.im/quote/*" $text]} {return}
- ::title::main $nick $uhost $hand $chan $text; return
- }
- proc actn {nick uhost hand chan key text} {
- variable chflag ; variable flagactas
- if {[string match "*#*" $chan]} { if {![channel get $chan $chflag] ^ $flagactas eq "no"} {return} }
- ::title::main $nick $uhost $hand $chan $text; return
- }
- proc nodomain {text} {
- variable domains
- foreach _ $domains { if {![string match "*$_*" "$text"]} {continue}; if {[string match "*$_*" "$text"]} {return 0} }; return 1
- }
- proc main {nick uhost hand chan text} {
- if {[matchattr $hand I]} {return}
- variable denyprefixes; variable using_ssl; variable debug; variable nodomains
- set text [string trim [string map { "" \[ "" \] "" \{ "" \} "" ( "" ) "" \" "" ' "" > "" < ""} [stripcodes bcruag $text]]]
- foreach _ $denyprefixes { if {[string index $text 0] eq $_} {if {$debug} {putlog "::title:: \[main\] Found denied prefix. Not responding."}; return} }
- if {![string match "*http://*" $text] && ![string match "*https://*" $text] && ![string match "*www.*" $text] && ![string match "*wap.*" $text] && [nodomain $text]} {if {$debug} {putlog "::title:: \[main\] Links not found."}; return}
- variable flood; variable clock
- if {[expr [clock seconds]-$clock] < $flood} {return}; set clock [clock seconds]
- set i 0; set urls [list]; foreach _ [split $text] {
- if {$i > 1} {return}
- if {[regexp -nocase -- {^(http://.+?)$} $_ -> url] || [regexp -nocase -- {^(www.*?|wap.*?)$} $_ -> url]} { if {[lsearch -exact -nocase $urls $url] == -1} {incr i; lappend urls $url; request $url $nick $uhost $chan} }
- if {$using_ssl && [regexp -nocase -- {^(https://.+?)$} $_ -> url]} { if {[lsearch -exact -nocase $urls $url] == -1} {incr i; lappend urls $url; request $url $nick $uhost $chan} }
- if {![regexp -nocase -- {^(http://.+?)$} [lindex $_ 0]] && $nodomains} { if {![nodomain [lindex $_ 0]]} { if {[lsearch -exact -nocase $urls "http://[lindex $_ 0]"] == -1} {incr i; lappend urls "http://[lindex $_ 0]"; request "http:\/\/[lindex $_ 0]" $nick $uhost $chan} } }
- }
- }
- proc request {url nick uhost chan} {
- variable useragent; variable debug; variable timeout; variable readlimit
- if {[string range $url 0 7] eq "http://-"} {set url "http://[string range [string trim $url "-"] 8 end]"}
- if {![regexp -nocase -- {^(https://.+?)$} $url] && [string range $url 0 6] ne "http://"} {set url "http://$url"}
- set extra [list $nick $uhost $chan $url]
- if {[regexp -nocase -- {^http://[а-яё]{1}.+?\.?} $url] || [regexp -nocase -- {^http://www.[а-яё]{1}.+?\.?} $url]} {
- regsub -all -nocase -- {^http://([а-яё]{1}.+?\.?)(/)} [string map [list \[ \\\[ \] \\\] \{ \\\{ \} \\\} \$ \\\$ \\ \\\\] $url] "http://\[::ccs::idna::encode \[encoding convertto utf-8 \\1\]\]\\2" url; set url [subst -novar $url]
- regsub -all -nocase -- {^http://([а-яё]{1}.+?\.?)$} [string map [list \[ \\\[ \] \\\] \{ \\\{ \} \\\} \$ \\\$ \\ \\\\] $url] "http://\[::ccs::idna::encode \[encoding convertto utf-8 \\1\]\]" url; set url [subst -novar $url]
- regsub -all -nocase -- {^http://www.([а-яё]{1}.+?\.?)(/)} [string map [list \[ \\\[ \] \\\] \{ \\\{ \} \\\} \$ \\\$ \\ \\\\] $url] "http://\[::ccs::idna::encode \[encoding convertto utf-8 \\1\]\]\\2" url; set url [subst -novar $url]
- regsub -all -nocase -- {^http://www.([а-яё]{1}.+?\.?)$} [string map [list \[ \\\[ \] \\\] \{ \\\{ \} \\\} \$ \\\$ \\ \\\\] $url] "http://\[::ccs::idna::encode \[encoding convertto utf-8 \\1\]\]" url; set url [subst -novar $url]
- }
- ::http::config -useragent $useragent
- if {$debug} {putlog "::title \[request\] Extra: $extra."}
- if {[catch {set token [::http::geturl $url -binary 1 -timeout [expr $timeout*1000] -headers [list "Range" "bytes=0-$readlimit"] -command [list [namespace current]::data $extra]]} err]} {return}
- }
- proc data {extra token} {
- variable maxredirects; variable deftemplate; variable debug;
- variable redir; variable maxredirects; variable using_ssl; variable template
- set status [::http::status $token]
- set ncode [::http::ncode $token]
- array set meta [::http::meta $token]
- if {$debug} {putlog "::title:: \[data\] status: $status\; metacode: $ncode\."}
- if {![info exists meta(Content-Length)]} {set Size "размер неизвестен"} else {set Size [fsize $meta(Content-Length)]}
- if {[info exists meta(Content-Range)]} { if {[regexp -nocase -- {bytes.*?\/(.+?)$} $meta(Content-Range) -> Size]} {set Size [fsize $Size]} else {set Size ""} }
- if {[info exists meta(Content-Type)]} {set Type $meta(Content-Type)} else {set Type "неизвестен"}
- if {$Size eq "размер неизвестен" && $Type eq "неизвестен"} {::http::cleanup $token; return}
- set nick [lindex $extra 0]; set uhost [lindex $extra 1]; set chan [lindex $extra 2]; set url [lindex $extra 3]
- set tempurl [regsub -nocase -- "http.*://" $url ""]
- set query [join [lindex [split $tempurl "/"] 0] "/"]
- set get [join [lrange $tempurl 1 end] "/"]
- if {[info exists meta(Location)]} {
- if {$debug} {putlog "::title:: \[data\] query: $query\; get: $get"}
- set simb "/"
- if {![string match "*http://*" $meta(Location)] && [string range $meta(Location) 0 0] == "/"} { set link "http://$host$meta(Location)"}
- if {![string match "*http://*" $meta(Location)] && ![string match "*https://*" $meta(Location)] && [string range $meta(Location) 0 0] != "/"} { set link "http://$query$simb$meta(Location)"}
- if {[string match "http://*" $meta(Location)]} {set link $meta(Location)}
- if {![string match "*https://*" $meta(Location)] && ![info exists link] && $using_ssl == 1} {set link "https://$query$simb$meta(Location)"}
- if {[string match "*https://*" $meta(Location)] && $using_ssl == 1} {set link $meta(Location)}
- if {$meta(Location) != "" && [string match "*domain=*" [::http::meta $token]] && ![string match "http*" $meta(Location)]} {set link "http://[lindex [split http://$query "/"] 2]$simb$meta(Location)"}
- if {($ncode eq "301" || $ncode eq "302") && $status eq "ok"} {
- if {$debug} {putlog "::title:: \[data\] redirect detected."}
- incr redir
- if {$debug} {putlog "::title:: \[data\] Redirect \#$redir."}
- if {$redir >= $maxredirects} {if {$debug} {putlog "::title:: \[data\] Max. redirects reached. Stopping."}; set redir 0; return}
- set url $link
- ::http::cleanup $token
- ::title::request $url $nick $uhost $chan
- }
- } else {
- if {$debug} {putlog "::title:: \[data\] Data received. Processing..."}
- catch {array unset meta; unset -nocomplain meta}
- set html [::http::data $token]; set meta [::http::meta $token]; ::http::cleanup $token; append meta $html
- if {![regexp -nocase -- {charset=(.+?)\"} $meta -> charset]} {set charset ""}
- unset -nocomplain meta
- if {[string length $html] < 5000 && [regexp -nocase -- {<meta http-equiv="refresh" content=".*URL=(.+?)".*</head>} $html -> redirr]} {
- regsub -all -- {\"\>} $redirr {} redirr; set simb "/"
- if {![string match "*http://*" $redirr] && [string index $redirr 0] != "/"} {set redirr "http://$query$simb[lindex [split $get "/"] 0]$simb$redirr"}
- if {![string match "*http://*" $redirr] && [string index $redirr 0] == "/"} {set redirr "http://$query$redirr"}
- ::title::request $redirr $nick $uhost $chan
- if {$debug} {putlog "::title:: \[data\] meta-refresh redirect detected. URL: $redirr"}
- return
- }
- switch -glob -- [string range $html 0 19] {
- "GIF8*" {set title [gif_dimensions $html]; set sh_size 1}
- "\x89PNG\r\n\x1a\n*" {set title [png_dimensions $html]; set sh_size 1}
- "\xFF\xD8\xFF*" {set title [jpeg_dimensions $html]; set sh_size 1}
- "BM*" {set title [bmp_dimensions $html]; set sh_size 1}
- default {set title [::title::decode $html $charset]; set template $deftemplate; set sh_size 0}
- }
- set bayan [tpoisk $url]
- if {$bayan == 0 || [string equal -nocase [lindex $bayan 1] $nick]} {set msgbayan1 ""; set msgbayan2 ""; tsave $url $nick} else {set msgbayan1 "\[:\]||||\[:\]-"; set msgbayan2 " $::gcolor(14)([lindex $bayan 1] [clock format [lindex $bayan 2] -format "%d.%m.%Y"], [expr 1+[lindex $bayan 3]]-й раз)"; tsave $url $nick}
- if {$title ne ""} {
- if {[string length $title] > 250} {set title "[string range $title 0 250]..."}
- if {$sh_size} {append title " $::gcolor(5)@\017 $Size"}
- putserv "PRIVMSG $chan :$::gcolor(14)^-$msgbayan1[subst $template]\017 $title$msgbayan2"
- variable redir
- set redir 0
- } else {putserv "PRIVMSG $chan :$::gcolor(14)^-$msgbayan1\037Файл\037:\017 $::gcolor(14)тип:\017 $Type $::gcolor(5)@\017 $Size$msgbayan2"; return}
- }
- }
- proc bmp_dimensions {data} {
- variable template
- set template "\037Изображение\037:\017 $::gcolor(14)формат:\017 bmp $::gcolor(5)::\017"
- binary scan [string range $data 18 25] ii width height
- set ret [list $width $height]
- return "$::gcolor(14)разрешение:\017 [join $ret x] px."
- }
- proc jpeg_dimensions {data} {
- variable template
- set template "\037Изображение\037:\017 $::gcolor(14)формат:\017 jpeg $::gcolor(5)::\017"
- set ret [list]
- set i 2
- while {[string index $data $i] eq "\xFF"} {
- binary scan [string range $data [incr i] [expr $i+2]] H2S type len
- incr i 3
- set len [expr {$len & 0x0000FFFF}]
- incr len -2
- if {[string match {c[0-3]} $type]} {set p $i; break}
- incr i $len
- }
- if {[info exists p]} {binary scan [string range $data $p [expr $p+4]] cSS precision height width; set ret [list $width $height]}
- return "$::gcolor(14)разрешение:\017 [join $ret x] px."
- }
- proc png_dimensions {data} {
- variable template
- set template "\037Изображение\037:\017 $::gcolor(14)формат:\017 png $::gcolor(5)::\017"
- set ret [list]
- set i 0
- binary scan [string range $data [incr i 8] [expr $i+7]] Ia4 len type
- set r [string range $data [incr i 8] [expr $i+$len]]
- if {$i < [string length $data] && $type eq "IHDR"} {
- binary scan $r II width height
- set ret [list $width $height]
- }
- return "$::gcolor(14)разрешение:\017 [join $ret x] px."
- }
- proc gif_dimensions {data} {
- variable template
- set template "\037Изображение\037:\017 $::gcolor(14)формат:\017 gif $::gcolor(5)::\017"
- set sig [string range $data 0 3]
- set ret [list]
- binary scan [string range $data 6 7] s wid
- binary scan [string range $data 8 9] s hgt
- set ret [list $wid $hgt]
- return "$::gcolor(14)разрешение:\017 [join $ret x] px."
- }
- proc decode {data charset} {
- variable debug
- regsub -all -- {[\x5C\x27\x2F\x3E\x3C\x22\x5F\x7B\x5D\x7D\x5B]+} $charset "" charset
- set charset [string trim $charset]
- regsub -all -nocase "fc|!.*" $charset "" charset
- set charset [string trim [string tolower $charset] \x5D\x7D\x7B\x5B\x3C\x3E\x22\x27]
- set charset [lindex [split $charset] 0]
- if {$charset == "" || $charset == "windows-1251" || $charset == "no"} {set charset cp1251}
- set charset0 ""
- set charset [string map {"win-" "cp" "windows-" "cp" "iso-" "iso" "cp-" "cp" "utf8" "utf-8"} $charset]
- if {[string is space [lsearch -all [encoding names] $charset]]} {if {$debug} {putlog "::title:: \[decode\] Encoding $charset was not found! Setting to default..."}; set charset [encoding system]}
- if {[regexp -nocase -- {<title>(.+?)</title>} $data -> info]} {set info [string trim $info]} else {set info ""}
- if {$info == ""} { if {[regexp -nocase -- {<title.*>(.+?)</title>} $data -> info]} {set info [string trim $info]} else {set info ""} }
- if {$info == "" && [string match "*card*" $data]} { if {[regexp -nocase -- {title="(.*?)"} $data -> info]} {set info [string trim $info]} else {set info ""} }
- if {$info == "" && [string match "*meta name*" $data]} { if {[regexp -nocase -- {name="title" content="(.*?)"} $data -> info]} {set info [string trim $info]} else {set info ""} }
- if {$debug} {putlog "::title:: \[decode\] Raw title: $info"}
- regsub -all "\n|\r|\t" $info " " info
- regsub -all { } $info { } info
- if {$data == {}} {if {$debug} {putlog "::title:: \[decode\] Data not present!"}; return ""}
- if {$charset == {}} {set charset cp1251}
- set info000 [encoding convertfrom [encoding system] $info]
- set enc_need ""
- if {[string match -nocase "*windows-1251*" $data] && ![regexp -nocase -- {[а-яА-ЯёЁ]} $data]} {set enc_need 1}
- if {![regexp -- {[а-яА-ЯёЁ]} $info]} {set enc_need auto}
- if {[string match "*\\\?\\\?\\\?*" $info] && ![string match "*charset=*" $data]} {set enc_need 2}
- if {[string match "*Рµ*" $info] || [string match "*?¶*" $info] || ([string match "*?°*" $info] && ![string match "*-°?*" $info]) || [string match -nocase "<meta http-equiv*charset=utf-8" $data]} {set enc_need 3}
- if {([string match -nocase "*koi8-r*" $data] && $enc_need != "3" && $charset != "cp1251") || ([string tolower $charset] == "koi8-r" && $enc_need != "3")} {set enc_need 2}
- if {[string range $info000 1 4] ==[string toupper [string range info000 1 4]] && [regexp -- {[А-Я]} $info]} {set enc_need 2}
- if {[string match "*а*" $info]} {set enc_need "not_need"}
- if { $info == "" } {return}
- if {[string match "\\\?\\\?\\\?\\\?*" $info]} {set enc_need "auto"}
- if {$debug} {putlog "::title:: \[decode\] Charset detected: $charset\; Encoding mode: $enc_need."}
- switch -glob -- $enc_need {
- "1" {set info [encoding convertfrom [encoding system] $info]}
- "2" {set info [encoding convertfrom koi8-r $info]}
- "3" {set info [encoding convertfrom utf-8 $info]}
- "auto" {set info [encoding convertfrom $charset $info]}
- default {set info [lindex $info]}
- }
- set debinfo [regsub -all -- {\x20|[^А-Яа-яёЁ]} $info ""]
- if {[issmall [string range $debinfo 0 0]] && ![issmall [string range $debinfo 1 15]] && [regexp -- {[А-ЯЁ]} $debinfo] && $charset != "utf-8"} {set info [encoding convertfrom koi8-r [encoding convertto cp1251 $info]]}
- set info [::title::webstrip $info]
- if {![regexp -all -- {[а-яА-ЯёЁa-zA-Z]} $info]} {set info [encoding convertfrom [encoding system] $info]}
- if {[string match "*Р°*СЂ*" $info] || [string match "*Р»*Рї*" $info]} {set info [encoding convertfrom utf-8 [encoding convertto [encoding system] $info]]}
- set enc_need 0
- return $info
- }
- proc issmall {{t ""}} {
- if {$t eq ""} {return 1}
- set a [regexp -all -- {[а-яё]} $t];
- set b [format %.1f [expr $a/[string length $t].0*100]]
- if {$b >=40} {return 1} else {return 0}
- }
- proc regsub-eval {re string cmd} {return [subst [regsub -all $re [string map {\[ \\[ \] \\] \$ \\$ \\ \\\\} $string] "\[format %c \[$cmd\]\]"]]}
- proc fsize {bytes} {
- if {![string is digit $bytes]} {error "value must be a valid digit, more then zero"}
- if {$bytes >=0 && $bytes < 1024} {return "$bytes byte\(s\)"
- } elseif {$bytes >= 1024 && $bytes < 1024000} {return "[format %.2f [expr $bytes /1024.0]] KB"
- } elseif {$bytes >= 1024e3 && $bytes < 1024e6} {return "[format %.2f [expr $bytes/1024.0/1024.0]] MB"
- } elseif {$bytes >= 1024e6 && $bytes < 1024e9} {return "[format %.2f [expr $bytes/1024.0/1024.0/1024.0]] GB"
- } elseif {$bytes >= 1024e9 && $bytes < 1024e12} {return "[format %.2f [expr $bytes/1024.0/1024.0/1024.0/1024.0/1024.0]] TB"
- } elseif {$bytes >= 1024e12 && $bytes < 1024e15} {return "[format %.2f [expr $bytes/1024.0/1024.0/1024.0/1024.0/1024.0/1024.0]] PB"
- } elseif {$bytes >= 1024e15 && $bytes < 1024e18} {return "[format %.2f [expr $bytes/1024.0/1024.0/1024.0/1024.0/1024.0/1024.0/1024.0]] EB"
- } elseif {$bytes >= 1024e18 && $bytes < 1024e21} {return "[format %.2f [expr $bytes/1024.0/1024.0/1024.0/1024.0/1024.0/1024.0/1024.0/1024.0]] ZB"
- } else {return "[format %.2f [expr $bytes/1024.0/1024.0/1024.0/1024.0/1024.0/1024.0/1024.0/1024.0/1024.0]] IB"
- }
- }
- proc webstrip {t} {
- regsub -all -nocase -- {<.*?>(.*?)</.*?>} $t {\1} t
- regsub -all -nocase -- {<.*?>} $t {} t
- set t [string map -nocase {‬ "" ‪ "" ‏ "" &rln; "" — - » » « « " \" < < > > " " & & © © © © • • · - § § ® ® \
- ‖ || \
- & & [ ( \ / ] ) { ( } ) \
- £ Ј ¨ Ё © © « « ­ ® ® \
- ¡ Ў ¿ ї ´ ґ · · ¹ № » » \
- ¼ ј ½ Ѕ ¾ ѕ À А Á Б Â В \
- Ã Г Ä Д Å Е Æ Ж Ç З È И \
- É Й Ê К Ë Л Ì М Í Н Î О \
- Ï П Ð Р Ñ С Ò Т Ó У Ô Ф \
- Õ Х Ö Ц × Ч Ø Ш Ù Щ Ú Ъ \
- Û Ы Ü Ь Ý Э Þ Ю ß Я à а \
- á б â в ã г ä д å е æ ж \
- ç з è и é й ê к ë л ì м \
- í н î о ï п ð р ñ с ò т \
- ó у ô ф õ х ö ц ÷ ч ø ш \
- ù щ ú ъ û ы ü ь ý э þ ю \
- ° ° ‧ · ˌ . ū u ī i ˈ ' \
- ɔ o ɪ i ' '} $t]
- set t [string map -nocase {¡ \xA1 ¤ \xA4 ¢ \xA2 £ \xA3 ¥ \xA5 ¦ \xA6 \
- § \xA7 ¨ \xA8 © \xA9 ª \xAA « \xAB ¬ \xAC \
- ­ \xAD ® \xAE ¯ \xAF ° \xB0 ± \xB1 ² \xB2 \
- ³ \xB3 ´ \xB4 µ \xB5 ¶ \xB6 · \xB7 ¸ \xB8 \
- ¹ \xB9 º \xBA » \xBB ¼ \xBC ½ \xBD ¾ \xBE \
- ¿ \xBF × \xD7 ÷ \xF7 À \xC0 Á \xC1 Â \xC2 \
- Ã \xC3 Ä \xC4 Å \xC5 Æ \xC6 Ç \xC7 È \xC8 \
- É \xC9 Ê \xCA Ë \xCB Ì \xCC Í \xCD Î \xCE \
- Ï \xCF Ð \xD0 Ñ \xD1 Ò \xD2 Ó \xD3 Ô \xD4 \
- Õ \xD5 Ö \xD6 Ø \xD8 Ù \xD9 Ú \xDA Û \xDB \
- Ü \xDC Ý \xDD Þ \xDE ß \xDF à \xE0 á \xE1 \
- â \xE2 ã \xE3 ä \xE4 å \xE5 æ \xE6 ç \xE7 \
- è \xE8 é \xE9 ê \xEA ë \xEB ì \xEC í \xED \
- î \xEE ï \xEF ð \xF0 ñ \xF1 ò \xF2 ó \xF3 \
- ô \xF4 õ \xF5 ö \xF6 ø \xF8 ù \xF9 ú \xFA \
- û \xFB ü \xFC ý \xFD þ \xFE ÿ \xFF} $t]
- set t [::title::regsub-eval {&#([0-9]{1,5});} $t {string trimleft \1 "0"}]
- regsub -all {\s+} $t " " t
- return $t
- }
- # Сохранение ссылок:
- variable file "data/title.dat"
- proc treads {} {
- variable file
- if {![file exists $file]} {set f [open $file w+]; close $f}
- set f [open $file r]; set data [lrange [split [read $f] \n] 0 end-1]; close $f
- return $data
- }
- proc tsave {url nick} {
- variable file
- set data [treads]; set url [string trim $url "/"]
- if {[set num [lsearch -index 0 -exact -noc $data $url]] != -1} {
- set stat [lindex $data $num]; set num2 [expr [lindex $stat 3]+1]; set stat [lreplace $stat 3 3 $num2]
- set data [lreplace $data $num $num $stat]; set f [open $file w+]; foreach line $data { puts $f $line }; close $f
- } else { set f [open $file a+]; puts $f [list $url $nick [unixtime] 1]; close $f }
- }
- proc tpoisk {url} {
- set data [treads]; set url [string trim $url "/"]
- set info ""; foreach line $data { if {[string equal -nocase [lindex $line 0] $url]} {set info $line; break} }
- if {$info != ""} {return $info} else {return 0}
- }
- # Вывод ссылок на pastebin:
- variable urltimer 20
- variable urlclock 0
- foreach bind {ссылка ссылки} {bind pub - $::gprefix(1)$bind [namespace current]::urlpub; bind msg - $::gprefix(1)$bind [namespace current]::urlmsg}
- proc urlmsg {nick host hand text} {urlpub $nick $host $hand $nick $text; return}
- proc urlpub {nick host hand chan text} {
- variable urltimer; variable urlclock
- if {$chan != $nick && [channel get $chan no[namespace tail [namespace current]]]} {return} else {set text [lindex [split [string trim [string map { {}} [stripcodes cubr $text]]]] 0]}
- if {[expr [clock seconds]-$urlclock] < $urltimer} {putserv "[expr {$nick == $chan ? "PRIVMSG":"NOTICE"}] $nick :Команда недавно запрашивалась. Повтори попытку через [expr $urltimer-([clock seconds]-$urlclock)] сек."; return}; set urlclock [clock seconds]
- set data [treads]; if {[llength $data] == 0} {putserv "[expr {$nick == $chan ? "PRIVMSG":"NOTICE"}] $nick :В базе нет ссылок!"; return} else {
- if {[string is space $text]} {set data [lrange [lreverse $data] 0 99]} else {
- set ndata [list]; foreach _ $data { if {[string equal -nocase [lindex $_ 1] $text]} {lappend ndata $_} }; set data $ndata; if {[llength $data] == 0} {putserv "[expr {$nick == $chan ? "PRIVMSG":"NOTICE"}] $nick :В базе нет ссылок от $text!"; return} else {set data [lrange [lreverse $data] 0 99]}
- }
- }
- set ndata ""; foreach _ $data {append ndata "[lindex $_ 0] <- [lindex $_ 1] ([clock format [lindex $_ 2] -format "%d.%m.%Y в %H:%M"])\n"}; set data $ndata
- ::http::config -urlencoding utf-8 -useragent "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)"
- set tok [::http::geturl "http://pastebin.com/api/api_post.php" -query [http::formatQuery api_dev_key 3c297476dcac3461208c96a18fdf28a3 api_paste_format text api_option paste api_paste_expire_date 1D api_paste_name "Urls $::botnick" api_paste_code $data] -timeout 20000]; set adres [::http::data $tok]; ::http::cleanup $tok
- if {[string match -nocase "*post limit, maximum pastes*" $adres]} {putserv "[expr {$nick == $chan ? "PRIVMSG":"NOTICE"}] $nick :Достигнут лимит, попробуйте завтра!"} else {putserv "PRIVMSG $chan :$::gcolor(14)Последние ссылки: $::gcolor(12)$adres"}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement