<commit_before>local patterns = {}

local utilities = require('otouto.utilities')

patterns.triggers = {
	'^/?s/.-/.-$'
}

function patterns:action(msg)
	if not msg.reply_to_message then return true end
	local output = msg.reply_to_message.text
	if msg.reply_to_message.from.id == self.info.id then
		output = output:gsub('Did you mean:\n"', '')
		output = output:gsub('"$', '')
	end
	local m1, m2 = msg.text:match('^/?s/(.-)/(.-)/?$')
	if not m2 then return true end
	local res
	res, output = pcall(
		function()
			return output:gsub(m1, m2)
		end
	)
	if res == false then
		utilities.send_reply(self, msg, 'Malformed pattern!')
	else
		output = output:sub(1, 4000)
		output = 'Did you mean:\n"' .. output .. '"'
		utilities.send_reply(self, msg.reply_to_message, output)
	end<commit_msg>patterns.lua   Trim whitespace off the ends of strings (partial fix for https://github.com/topkecleon/otouto/issues/74).   Make output style consistent with translate.lua.<commit_after>local patterns = {}

local utilities = require('otouto.utilities')

patterns.triggers = {
	'^/?s/.-/.-$'
}

function patterns:action(msg)
	if not msg.reply_to_message then return true end
	local output = msg.reply_to_message.text
	if msg.reply_to_message.from.id == self.info.id then
		output = output:gsub('Did you mean:\n"', '')
		output = output:gsub('"$', '')
	end
	local m1, m2 = msg.text:match('^/?s/(.-)/(.-)/?$')
	if not m2 then return true end
	local res
	res, output = pcall(
		function()
			return output:gsub(m1, m2)
		end
	)
	if res == false then
		utilities.send_reply(self, msg, 'Malformed pattern!')
	else
		output = output:sub(1, 4000)
		output = '*Did you mean:*\n"' .. utilities.md_escape(utilities.trim(output)) .. '"'
		utilities.send_reply(self, msg.reply_to_message, output, true)
	end
{'fraction_non_alphanumeric': 0.16208637128435222, 'fraction_numerical': 0.012338754907459339, 'mean_word_length': 3.9555555555555557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '2945360', 'n_tokens_mistral': 692, 'n_tokens_neox': 647, 'n_words': 161}