<commit_before>local simplehttp = require'simplehttp'
local json = require'json'

local urlEncode = function(str)
	return str:gsub(
		'([^%w ])',
		function (c)
			return string.format ("%%%02X", string.byte(c))
		end
	):gsub(' ', '+')
end

local parseJSON = function(data)
	data = json.decode(data)

	if(data.has_related_words) then
		return data.list[1].definition
	end
end

local APIBase = 'http://api.urbandictionary.com/v0/define?term=%s'
return {
	PRIVMSG = {
		['^!ud (.+)$'] = function(self, source, destination, input)
			simplehttp(
				APIBase:format(urlEncode(input)),

				function(data)
					local result = parseJSON(data)

					if(result) then
						local msgLimit = (512 - 16 - 65 - 10) - #self.config.nick - #destination
						if(#result > msgLimit) then
							result = result:sub(1, msgLimit - 3) .. '...'
						end
						self:Msg('privmsg', destination, source, string.format('%s: %s', source.nick, result))
					else
						self:Msg('privmsg', destination, source, string.format("%s: %s is bad and you should feel bad.", source.nick, input))
					end
				end
			)
		end,
	},
}
<commit_msg>urbandict: Add spacing instead of stripping away newlines.<commit_after>local simplehttp = require'simplehttp'
local json = require'json'

local urlEncode = function(str)
	return str:gsub(
		'([^%w ])',
		function (c)
			return string.format ("%%%02X", string.byte(c))
		end
	):gsub(' ', '+')
end

local parseJSON = function(data)
	data = json.decode(data)

	if(data.has_related_words) then
		return data.list[1].definition:gsub('\r\n', ' ')
	end
end

local APIBase = 'http://api.urbandictionary.com/v0/define?term=%s'
return {
	PRIVMSG = {
		['^!ud (.+)$'] = function(self, source, destination, input)
			simplehttp(
				APIBase:format(urlEncode(input)),

				function(data)
					local result = parseJSON(data)

					if(result) then
						local msgLimit = (512 - 16 - 65 - 10) - #self.config.nick - #destination
						if(#result > msgLimit) then
							result = result:sub(1, msgLimit - 3) .. '...'
						end
						self:Msg('privmsg', destination, source, string.format('%s: %s', source.nick, result))
					else
						self:Msg('privmsg', destination, source, string.format("%s: %s is bad and you should feel bad.", source.nick, input))
					end
				end
			)
		end,
	},
}

{'fraction_non_alphanumeric': 0.16396317404647084, 'fraction_numerical': 0.0131521262604121, 'mean_word_length': 3.380038387715931, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3179816', 'n_tokens_mistral': 946, 'n_tokens_neox': 780, 'n_words': 189}