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

require 'yaml'

require_relative '../yossarian_plugin'

class UserIntros < YossarianPlugin
	include Cinch::Plugin

	@@user_intros_file = File.expand_path(File.join(File.dirname(__FILE__), 'user_intros.yml'))

	def initialize(*args)
		super
		@intros = {}
	end

	def sync_intros_file
		File.open(@@user_intros_file, "w+") do |file|
			file.write @intros.to_yaml
		end
	end

	def usage
		'!intro <intro> - Set a custom intro message for your nick. Prefix with \'rm\' to remove your intro.'
	end

	def match?(cmd)
		cmd =~ /^(!)?intro$/
	end

	listen_to :connect, method: :initialize_intros

	def initialize_intros(m)
		if File.exist?(@@user_intros_file)
			@intros = YAML::load_file(@@user_intros_file)
		end
	end

	match /intro (.+)/, method: :set_intro

	def set_intro(m, intro)
		intro.gsub!(/\x01/, '')
		if @intros.has_key?(m.channel.to_s)
			@intros[m.channel.to_s][m.user.nick] = intro
		else
			@intros[m.channel.to_s] = {m.user.nick => intro}
		end
		m.reply "#{m.user.nick}: Your intro for #{m.channel.to_s} has been set to: \'#{intro}\'."
		sync_intros_file
	end

	match /rmintro/, method: :remove_intro

	def remove_intro(m)
		if @intros.has_key?(m.channel.to_s) && @intros[m.channel.to_s].has_key?(m.user.nick)
			@intros[m.channel.to_s].delete(m.user.nick)
			m.reply "#{m.user.nick}: Your intro for #{m.channel.to_s} has been removed."
			sync_intros_file
		else
			m.reply "#{m.user.nick}: You don't currently have an intro."
		end
	end

	match /showintro/, method: :show_intro

	def show_intro(m)
		if @intros.has_key?(m.channel.to_s) && @intros[m.channel.to_s].has_key?(m.user.nick)
			m.reply "#{m.user.nick}: Your intro is currently \'#{@intros[m.channel.to_s][m.user.nick]}\'."
		else
			m.reply "#{m.user.nick}: You don't currently have an intro."
		end
	end

	listen_to :join, method: :intro_user

	def intro_user(m)
		if @intros.has_key?(m.channel.to_s) && @intros[m.channel.to_s].has_key?(m.user.nick)
			m.reply @intros[m.channel.to_s][m.user.nick]
		end
	end
end
<commit_msg>add a zero-width space to intros to prevent trigger loops with other bots<commit_after>#  -*- coding: utf-8 -*-
#  user_intros.rb
#  Author: <NAME>
#  ------------------------
#  A Cinch plugin that provides custom intros for users for yossarian-bot.
#  ------------------------
#  This code is licensed by <NAME> under the MIT License.
#  http://opensource.org/licenses/MIT

require 'yaml'

require_relative '../yossarian_plugin'

class UserIntros < YossarianPlugin
	include Cinch::Plugin

	@@user_intros_file = File.expand_path(File.join(File.dirname(__FILE__), 'user_intros.yml'))

	def initialize(*args)
		super
		@intros = {}
	end

	def sync_intros_file
		File.open(@@user_intros_file, "w+") do |file|
			file.write @intros.to_yaml
		end
	end

	def usage
		'!intro <intro> - Set a custom intro message for your nick. Prefix with \'rm\' to remove your intro.'
	end

	def match?(cmd)
		cmd =~ /^(!)?intro$/
	end

	listen_to :connect, method: :initialize_intros

	def initialize_intros(m)
		if File.exist?(@@user_intros_file)
			@intros = YAML::load_file(@@user_intros_file)
		end
	end

	match /intro (.+)/, method: :set_intro

	def set_intro(m, intro)
		intro.gsub!(/\x01/, '')
		if @intros.has_key?(m.channel.to_s)
			@intros[m.channel.to_s][m.user.nick] = intro
		else
			@intros[m.channel.to_s] = {m.user.nick => intro}
		end
		m.reply "#{m.user.nick}: Your intro for #{m.channel.to_s} has been set to: \'#{intro}\'."
		sync_intros_file
	end

	match /rmintro/, method: :remove_intro

	def remove_intro(m)
		if @intros.has_key?(m.channel.to_s) && @intros[m.channel.to_s].has_key?(m.user.nick)
			@intros[m.channel.to_s].delete(m.user.nick)
			m.reply "#{m.user.nick}: Your intro for #{m.channel.to_s} has been removed."
			sync_intros_file
		else
			m.reply "#{m.user.nick}: You don't currently have an intro."
		end
	end

	match /showintro/, method: :show_intro

	def show_intro(m)
		if @intros.has_key?(m.channel.to_s) && @intros[m.channel.to_s].has_key?(m.user.nick)
			m.reply "#{m.user.nick}: Your intro is currently \'#{@intros[m.channel.to_s][m.user.nick]}\'."
		else
			m.reply "#{m.user.nick}: You don't currently have an intro."
		end
	end

	listen_to :join, method: :intro_user

	def intro_user(m)
		if @intros.has_key?(m.channel.to_s) && @intros[m.channel.to_s].has_key?(m.user.nick)
			m.reply "\u200B#{@intros[m.channel.to_s][m.user.nick]}"
		end
	end
end

{'fraction_non_alphanumeric': 0.17717460995939302, 'fraction_numerical': 0.0019234879247702502, 'mean_word_length': 3.469914040114613, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7640225', 'n_tokens_mistral': 1987, 'n_tokens_neox': 1833, 'n_words': 400}