<commit_before>#  -*- coding: utf-8 -*-
#  urban_dictionary.rb
#  Author: <NAME>
#  ------------------------
#  A Cinch plugin that provides UrbanDictionary interaction for yossarian-bot.
#  ------------------------
#  This code is licensed by <NAME> under the MIT License.
#  http://opensource.org/licenses/MIT

require 'json'

require_relative 'yossarian_plugin'

class UrbanDictionary < YossarianPlugin
	include Cinch::Plugin
	use_blacklist

	def usage
		'!ud <phrase> - Look up <phrase> on UrbanDictionary. Alias: !urban.'
	end

	def match?(cmd)
		cmd =~ /^(!)?(ud)|(urban)$/
	end

	match /ud (.+)/, method: :urban_dict, strip_colors: true
	match /urban (.+)/, method: :urban_dict, strip_colors: true

	def urban_dict(m, phrase)
		query = URI.encode(phrase)
		url = "http://api.urbandictionary.com/v0/define?term=#{query}"

		begin
			hash = JSON.parse(open(url).read)
			if hash['list'].empty?
				m.reply "UrbanDictionary has nothing for #{phrase}."
			else
				list = hash['list'][0]
				definition = list['definition'][0..255].gsub(/[\r\n]/, '')
				link = list['permalink']
				m.reply "#{phrase} - #{definition}... (#{link})", true
			end
		rescue Exception => e
			m.reply e.to_s, true
		end
	end
end<commit_msg>use .first instead of [0]<commit_after>#  -*- coding: utf-8 -*-
#  urban_dictionary.rb
#  Author: <NAME>
#  ------------------------
#  A Cinch plugin that provides UrbanDictionary interaction for yossarian-bot.
#  ------------------------
#  This code is licensed by <NAME> under the MIT License.
#  http://opensource.org/licenses/MIT

require 'json'

require_relative 'yossarian_plugin'

class UrbanDictionary < YossarianPlugin
	include Cinch::Plugin
	use_blacklist

	def usage
		'!ud <phrase> - Look up <phrase> on UrbanDictionary. Alias: !urban.'
	end

	def match?(cmd)
		cmd =~ /^(!)?(ud)|(urban)$/
	end

	match /ud (.+)/, method: :urban_dict, strip_colors: true
	match /urban (.+)/, method: :urban_dict, strip_colors: true

	def urban_dict(m, phrase)
		query = URI.encode(phrase)
		url = "http://api.urbandictionary.com/v0/define?term=#{query}"

		begin
			hash = JSON.parse(open(url).read)
			if hash['list'].empty?
				m.reply "UrbanDictionary has nothing for #{phrase}."
			else
				list = hash['list'].first
				definition = list['definition'][0..255].gsub(/[\r\n]/, '')
				link = list['permalink']
				m.reply "#{phrase} - #{definition}... (#{link})", true
			end
		rescue Exception => e
			m.reply e.to_s, true
		end
	end
end
{'fraction_non_alphanumeric': 0.1958553433563592, 'fraction_numerical': 0.005688744412840309, 'mean_word_length': 3.0163132137030995, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4597011', 'n_tokens_mistral': 926, 'n_tokens_neox': 836, 'n_words': 213}