lib/protonbot/titler/plugin.rb in protonbot-titler-0.1.1 vs lib/protonbot/titler/plugin.rb in protonbot-titler-0.1.2
- old
+ new
@@ -9,11 +9,11 @@
hook(type: :privmsg) do |dat|
#core.privmsg_patch(dat)
unless /(bot|serv)/i.match("#{dat[:nick]}!#{dat[:user]}@#{dat[:host]}")
regex = %r((?:(?:https?):\/\/)?(?:\S+(?::\S*)?@)?(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?)i
pattern = "%N%B[ :NICK%N#:URLNUM %B|%N :OUT %B]%N"
- dat[:message].scan(regex).each_with_index do |v, k|
+ dat[:message].scan(regex)[0,5].each_with_index do |v, k|
unless %r(http[s]?://).match(v)
v = 'http://' + v
end
out = ''
err = nil
@@ -26,22 +26,22 @@
err = e
end
if err
dat.reply(pattern
.gsub(':NICK', dat[:nick])
- .gsub(':URLNUM', k.to_s)
+ .gsub(':URLNUM', (k+1).to_s)
.gsub(':OUT', "%C%RED\u200B#{err.message}%N"))
elsif [200, 201, 203, 204, 205, 206, 207, 208, 226, 304].include?(res.code) && res["Content-Type"][/text\/html.*/]
body = res.body.to_s
html = Nokogiri::HTML(body)
dat.reply(pattern
.gsub(':NICK', dat[:nick])
- .gsub(':URLNUM', k.to_s)
+ .gsub(':URLNUM', (k+1).to_s)
.gsub(':OUT', "%C%GREEN\u200B" + html.title + '%N'))
else
dat.reply(pattern
.gsub(':NICK', dat[:nick])
- .gsub(':URLNUM', k.to_s)
+ .gsub(':URLNUM', (k+1).to_s)
.gsub(':OUT', "%C%ORANGE\u200B#{res.code}%N"))
end
end
end
end
\ No newline at end of file