xkcd eggdrop script
Небольшой скриптик для eggdrop’а, который выдаёт на канал случайный комикс с xkcd.
Пример работы:
<z0rc> !xkcd
<Kuro-sama> XKCD №64: Solar Plexus
<Kuro-sama> http://imgs.xkcd.com/comics/solar_plexus.jpg
<Kuro-sama> It hurts to be hit there, you know
<z0rc> !xkcd 448
<Kuro-sama> XKCD №448: Good Morning
<Kuro-sama> http://imgs.xkcd.com/comics/good_morning.png
<Kuro-sama> As my standard, I use going to sleep at midnight and waking up at 8 AM.
<Legio> !xkcd 404
<Kuro-sama> Такого выпуска нет.
<iSage> !xkcd latest
<MahouShoujoAi> XKCD №488: Steal This Comic
<MahouShoujoAi> http://imgs.xkcd.com/comics/steal_this_comic.png
<MahouShoujoAi> I spent more time trying to get an audible.com audio book playing than it took to listen to the book. I have lost every other piece of DRM-locked music I have paid for.
Changelog:
v1.1 Добавлена возможность показа выпуска по его номеру.
v1.2 Добавлена возможность показа последнего вышедшого выпуска.
Прошу:
foreach p [array names xkcd *] { catch {unset xkcd($p) } } namespace eval xkcd {} set xkcd(ver) 1.2 set xkcd(authors) "z0rc & iSage" set xkcd(timeout) 20 set xkcd(time) 210 bind pub - !xkcd ::xkcd::pub_xkcd proc ::xkcd::pub_xkcd {nick uhost hand chan text} { global xkcd set xkcdline [utimers] foreach line $xkcdline { if {"xkcd:reset $uhost" == [lindex $line 1]} { set xkcdtime [lindex $line 0] } } if { [info exists xkcd(host,$uhost)] } { set temp [duration $xkcdtime] regsub -all -- {hours} $temp {час(ов)} temp regsub -all -- {hour} $temp {час} temp regsub -all -- {minutes} $temp {минут(ы)} temp regsub -all -- {minute} $temp {минуту} temp regsub -all -- {seconds} $temp {секунд(ы)} temp regsub -all -- {second} $temp {секунду} temp if {$xkcd(time) > 0} { putserv "NOTICE $nick :Вы сможете использовать команду \002!xkcd\002 через \002$temp\002" } return } set xkcd(host,$uhost) 1 set xkcd(timer,$uhost) [utimer $xkcd(time) [list xkcd:reset $uhost ] ] putlog "\[xkcd\] Downloading..." if { $text == "latest" } { set query "http://xkcd.com/" } elseif { $text=="" } { set query "http://dynamic.xkcd.com/comic/random/" set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e" set http [::http::config -useragent $ua -urlencoding "utf-8"] set http [::http::geturl "$query" -query "" -timeout [expr 1000 * 10]] upvar #0 $http state foreach {name value} $state(meta) { if { $name eq "Location" } { set query $value } } } elseif {[string match {[0-9]*} $text]} { set query "http://xkcd.com/$text/" } set http [::http::geturl "$query" -query "" -timeout [expr 1000 * 10]] set html [::http::data $http] ::http::cleanup $http putlog "\[xkcd\] Downloaded..." regexp -all {http://xkcd.com/(.*?)/} $html -> num regexp -all {</div>\n<br/>\n<br/>\n<img src=\"(.*?)\"} $html -> link regexp -all {<h1>(.*?)</h1><br/>} $html -> title regexp -all {title=\"(.*?)\"} $html -> fin putlog "\[xkcd\] Parsed..." putserv "PRIVMSG $chan :XKCD №$num: \002$title\002" putserv "PRIVMSG $chan :$link" putserv "PRIVMSG $chan :$fin" putlog "\[xkcd\] Done..." return } proc xkcd:reset { uhost } { global xkcd catch {killutimer $xkcd(timer,$uhost)} catch {unset xkcd(timer,$uhost)} catch {unset xkcd(host,$uhost)} } putlog "xkcd.tcl v$xkcd(ver) by $xkcd(authors) loaded"
или вот.
Спасибо iSage за помощь в доводке скрипта.

Комментировать