Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose/isolate main function of the script. #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions urltitle.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,25 @@ namespace eval UrlTitle {
}
}

proc handler {nick host user chan text} {
proc getTitle {url} {
variable httpsSupport
variable htmlSupport
# enable https if supported
if {$httpsSupport} {
::http::register https 443 [list UrlTitle::socket]
}
set title [UrlTitle::parse $url]
if {$htmlSupport} {
set title [::htmlparse::mapEscapes $title]
}
# unregister https if supported
if {$httpsSupport} {
::http::unregister https
}
return $title
}

proc handler {nick host user chan text} {
variable delay
variable last
variable ignore
Expand All @@ -114,18 +130,7 @@ namespace eval UrlTitle {
![regexp {://([^/:]*:([^/]*@|\d+(/|$))|.*/\.)} $word] && \
![urlisignored $word]} {
set last $unixtime
# enable https if supported
if {$httpsSupport} {
::http::register https 443 [list UrlTitle::socket]
}
set urtitle [UrlTitle::parse $word]
if {$htmlSupport} {
set urtitle [::htmlparse::mapEscapes $urtitle]
}
# unregister https if supported
if {$httpsSupport} {
::http::unregister https
}
set urtitle [UrlTitle::getTitle $word]
if {$urtitle eq ""} {
break
}
Expand Down