View difference between Paste ID: zHpW0EqL and BndHJ4A6
SHOW: | | - or go back to the newest paste.
1-
; --------------
1+
2-
alias -l api_key { return REGISTER_ON_EMBED_LY }
2+
3-
; --------------
3+
4
ON *:TEXT:*:#: {
5
  tokenize 32 $strip($1-)
6
7
  var %t = $numtok($1-,32)
8
  var %i = 1
9
10
  while (%i <= %t) { 
11
    var %w = $gettok($1-,%i,32)
12
13
    if (%w) && ($isurl(%w)) { get_title $chan %w }
14
15
    inc %i
16
  }
17-
    if (%w) && ($isurl(%w)) { scan_url $chan %w }
17+
18
19
alias get_title {
20
  if (!$1) && (!$2) { return }
21
22
  var %dom = $gettok($2-,2,47)
23-
alias scan_url {
23+
  var %url = $gettok($2-,3-,47)
24
25-
  if ($me !ison $1) { return }
25+
  :start
26
  var %s = URL_SEARCH_ $+ $ticks $+ $rand(1,100000)
27-
  var %v = URL_SEARCH_ $+ $ticks $+ $rand(1,100000000)
27+
28-
  var %u = https://api.embed.ly/1/extract?key= $+ $api_key $+ &format=json&nojsoncallback=1&url= $+ $urldecode($2-)
28+
  if ($sock(%s)) { goto start }
29
30-
  JSONOpen -ud %v %u
30+
  if (*https://* iswm $1-) { sockopen -e %s %dom 443 }
31-
  if ($jsonerror) { return }
31+
  else { sockopen %s %dom 80 }
32
33-
  var %title = $json(%v,description).value
33+
  sockmark %s $1 %url
34
35-
  if (%title) { msg $1 Title: %title }
35+
  socklist
36
}
37
38
ON *:SOCKOPEN:URL_SEARCH_*: { 
39
  if ($sockerr) { return }
40
41
  sockwrite -nt $sockname GET / $+ $gettok($sock($sockname).mark,2-,32) HTTP/1.1
42
  sockwrite -nt $sockname User-Agent: Mozilla/5.0 (Windows NT 10.0 $+ $chr(59) Win64 $+ $chr(59) x64 $+ $chr(59) rv:61.0) Gecko/20100101 Firefox/61.0
43
  sockwrite -nt $sockname Host: $sock($sockname).addr
44
  sockwrite -nt $sockname Connection: Close
45
  sockwrite -nt $sockname $crlf
46
}
47
48
ON *:SOCKREAD:URL_SEARCH_*: {
49
  if ($sockerr) { return }
50
51
  var %r 
52
  sockread %r
53
54
  ; echo 2 -s DEBUG: %r
55
56
  if ($regex(%r,/\<title\>(.*)\<\/title\>/i)) {
57
    var %title = $regml(1) 
58
    var %c = $gettok($sock($sockname).mark,1,32)
59
60
    if (%title) && ($me ison %c) { msg %c Title: %title }
61
62
    sockclose $sockname
63
  }
64
}