<commit_before>
class Typo < RubotPlugin

	def initialize
		# Remember this many previous lines for each user.
		@remembered = 10

		# This will hold previous messages from all users we see.
		@msgs = {}
	end

	def user_said nick, message
		# A user said something, let's write it down.
		unless @msgs[nick]
			@msgs[nick] = Array.new
		end

		@msgs[nick].push message
		if @msgs[nick].length > @remembered
			@msgs[nick].shift
		end
	end

	def replace source, nick, orig, cor
		return unless @msgs[nick]
		found = @msgs[nick].grep(/#{orig}/).last
		return unless found
		corrected = found.sub /#{orig}/i, cor
		say source, "#{nick} meant to say: #{corrected}"
		user_said nick, corrected
	end

	def privmsg user, source, message
		if message.match /^s\/(.+)\/(.+)/
			nick = user.nick
			orig = $1
			cor = $2
			cor.chop! if cor[-1..-1] == "/"
			replace source, nick, orig, cor
		elsif message.match /^(.+?)\/(.+)\/(.+)/
			nick = $1
			orig = $2
			cor = $3
			cor.chop! if cor[-1..-1] == "/"
			replace source, nick, orig, cor
		elsif message.match /^(.+): s\/(.+)\/(.+)/
			say source, "match"
		else
			nick = user.nick
			message.sub! /^\001ACTION/, "* " + user.nick
			user_said nick, message
		end
	end

end
<commit_msg>Catch last \001 after ACTION.<commit_after>
class Typo < RubotPlugin

	def initialize
		# Remember this many previous lines for each user.
		@remembered = 10

		# This will hold previous messages from all users we see.
		@msgs = {}
	end

	def user_said nick, message
		# A user said something, let's write it down.
		unless @msgs[nick]
			@msgs[nick] = Array.new
		end

		@msgs[nick].push message
		if @msgs[nick].length > @remembered
			@msgs[nick].shift
		end
	end

	def replace source, nick, orig, cor
		return unless @msgs[nick]
		found = @msgs[nick].grep(/#{orig}/).last
		return unless found
		corrected = found.sub /#{orig}/i, cor
		say source, "#{nick} meant to say: #{corrected}"
		user_said nick, corrected
	end

	def privmsg user, source, message
		if message.match /^s\/(.+)\/(.+)/
			nick = user.nick
			orig = $1
			cor = $2
			cor.chop! if cor[-1..-1] == "/"
			replace source, nick, orig, cor
		elsif message.match /^(.+?)\/(.+)\/(.+)/
			nick = $1
			orig = $2
			cor = $3
			cor.chop! if cor[-1..-1] == "/"
			replace source, nick, orig, cor
		elsif message.match /^(.+): s\/(.+)\/(.+)/
			say source, "match"
		else
			nick = user.nick
			if message.match /\001/
				message.sub! /^\001ACTION/, "* " + user.nick
				message.sub! /\001$/, ""
			end
			user_said nick, message
		end
	end

end

{'fraction_non_alphanumeric': 0.1641732283464567, 'fraction_numerical': 0.014566929133858268, 'mean_word_length': 2.6456241032998564, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7349379', 'n_tokens_mistral': 1100, 'n_tokens_neox': 923, 'n_words': 286}