<commit_before>local currency = {}

local HTTPS = require('ssl.https')
local utilities = require('mattata.utilities')

currency.command = 'currency [amount] <from> to <to>'

function currency:init(config)
	currency.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('currency', true).table
	currency.doc = config.cmd_pat .. [[currency [amount] <from> to <to>
Example: ]] .. config.cmd_pat .. [[currency 10 GBP to EUR
Returns exchange rates for various currencies.
Source: Google Finance.]]
end

function currency:action(msg, config)

	local input = msg.text:upper()
	if not input:match('%a%a%a TO %a%a%a') then
		utilities.send_message(self, msg.chat.id, currency.doc, true, msg.message_id, true)
		return
	end

	local from = input:match('(%a%a%a) TO')
	local to = input:match('TO (%a%a%a)')
	local amount = utilities.get_word(input, 2)
	amount = tonumber(amount) or 1
	local result = 1

	local url = 'https://www.google.com/finance/converter'

	if from ~= to then

		url = url .. '?from=' .. from .. '&to=' .. to .. '&a=' .. amount
		local str, res = HTTPS.request(url)
		if res ~= 200 then
			utilities.send_reply(self, msg, config.errors.connection)
			return
		end

		str = str:match('<span class=bld>(.*) %u+</span>')
		if not str then
			utilities.send_reply(self, msg, config.errors.results)
			return
		end

		result = string.format('%.2f', str)

	end

	local output = amount .. ' ' .. from .. ' = ' .. result .. ' ' .. to .. '\n\n'
	output = output .. os.date('!%F %T UTC') .. '\nSource: Google Finance`'
	output = '```\n' .. output .. '\n```'

	utilities.send_message(self, msg.chat.id, output, true, nil, true)

end

return currency<commit_msg>Minor modifications<commit_after>local currency = {}
local HTTPS = require('ssl.https')
local functions = require('mattata.functions')
function currency:init(configuration)
	currency.command = 'currency [amount] <from> to <to>'
	currency.triggers = functions.triggers(self.info.username, configuration.command_prefix):t('currency', true).table
	currency.doc = configuration.command_prefix .. [[currency [amount] <from> to <to>
	Example: ]] .. configuration.command_prefix .. [[currency 10 GBP to EUR
	Returns exchange rates for various currencies.
	Source: Google Finance.]]
end
function currency:action(msg, configuration)
	local input = msg.text:upper()
	if not input:match('%a%a%a TO %a%a%a') then
		functions.send_message(self, msg.chat.id, currency.doc, true, msg.message_id, true)
		return
	end
	local from = input:match('(%a%a%a) TO')
	local to = input:match('TO (%a%a%a)')
	local amount = functions.get_word(input, 2)
	amount = tonumber(amount) or 1
	local result = 1
	local api = configuration.currency_api
	if from ~= to then
		api = api .. '?from=' .. from .. '&to=' .. to .. '&a=' .. amount
		local str, res = HTTPS.request(api)
		if res ~= 200 then
			functions.send_reply(self, msg, configuration.errors.connection)
			return
		end
		str = str:match('<span class=bld>(.*) %u+</span>')
		if not str then
			functions.send_reply(self, msg, configuration.errors.results)
			return
		end
		result = string.format('%.2f', str)
	end
	local output = amount .. ' ' .. from .. ' = ' .. result .. ' ' .. to .. '\n\n'
	output = output .. os.date('!%F %T UTC') .. '\nSource: Google Finance`'
	output = '```\n' .. output .. '\n```'
	functions.send_message(self, msg.chat.id, output, true, nil, true)
end
return currency
{'fraction_non_alphanumeric': 0.17099056603773585, 'fraction_numerical': 0.005306603773584905, 'mean_word_length': 3.840228245363766, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '5910439', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1143, 'n_words': 312}