<commit_before>#  -*- coding: utf-8 -*-
#  link_titling.rb
#  Author: <NAME>
#  ------------------------
#  A Cinch plugin that autotitles any links sniffed by yossarian-bot.
#  ------------------------
#  This code is licensed by <NAME>oodruff under the MIT License.
#  http://opensource.org/licenses/MIT

require 'nokogiri'

require_relative 'yossarian_plugin'

class LinkTitling < YossarianPlugin
	include Cinch::Plugin

	match /(http(s)?:\/\/[^ \t]*)/, use_prefix: false, method: :link_title

	def link_title(m, link)
		begin
			html = Nokogiri::HTML(open(link, {:read_timeout => 3}))
			title = html.css('title').text.gsub(/[\t\r\n]/, '')

			m.reply "Title: \'#{title}\'"
		rescue Exception => e
			m.reply e.to_s, true
		end
	end
end
<commit_msg>only print the title if one is found<commit_after>#  -*- coding: utf-8 -*-
#  link_titling.rb
#  Author: <NAME>
#  ------------------------
#  A Cinch plugin that autotitles any links sniffed by yossarian-bot.
#  ------------------------
#  This code is licensed by <NAME> under the MIT License.
#  http://opensource.org/licenses/MIT

require 'nokogiri'

require_relative 'yossarian_plugin'

class LinkTitling < YossarianPlugin
	include Cinch::Plugin

	match /(http(s)?:\/\/[^ \t]*)/, use_prefix: false, method: :link_title

	def link_title(m, link)
		begin
			html = Nokogiri::HTML(open(link, {:read_timeout => 3}))
			title = html.css('title').text.gsub(/[\t\r\n]/, '')

			if title.size > 0
				m.reply "Title: \'#{title}\'"
			end
		rescue Exception => e
			m.reply e.to_s, true
		end
	end
end

{'fraction_non_alphanumeric': 0.21147646679561574, 'fraction_numerical': 0.003223726627981947, 'mean_word_length': 2.68646080760095, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4002906', 'n_tokens_mistral': 596, 'n_tokens_neox': 554, 'n_words': 141}