<commit_before># encoding: utf-8

module Plugins
  class CommandControl

    include Cinch::Plugin
    include Cinch::Extensions::Authentication

    enable_authentication
    match /turn (.+) (.+)/

    def initialize(*args)
      super
      @bot.cleverbot_enabled = true
      @bot.dctv_commands_enabled = true
    end

    def execute(m, group, action)
      failed = false
      case action
      when "on"
        @turn_off = false
      when "off"
        @turn_off = true
      else
        failed = true
      end

      case group
      when "cleverbot",
        @bot.cleverbot_enabled = toggle_command_set(m, "Cleverbot interfaces", @bot.cleverbot_enabled)
      when "dctv"
        @bot.dctv_commands_enabled = toggle_command_set(m, "DCTV commands", @bot.dctv_commands_enabled)
      when "all"
        @bot.cleverbot_enabled = toggle_command_set(m, "Cleverbot interfaces", @bot.cleverbot_enabled)
        @bot.dctv_commands_enabled = toggle_command_set(m, "DCTV commands", @bot.dctv_commands_enabled)
      else
        failed = true
      end

      m.user.notice "Sorry, I don't know how to turn #{group} #{action}" if failed
    end

    private

      def toggle_command_set(m, command_set_name, command_boolean_variable)
        if @turn_off
          if command_boolean_variable
            m.user.notice "#{command_set_name} have been disabled"
          else
            m.user.notice "#{command_set_name} are already disabled"
          end
          return false
        else
          if command_boolean_variable
            m.user.notice "#{command_set_name} are already enabled"
          else
            m.user.notice "#{command_set_name} have been enabled"
          end
          return true
        end
      end
  end

end<commit_msg>compact and clean code<commit_after># encoding: utf-8

module Plugins
  class CommandControl

    include Cinch::Plugin
    include Cinch::Extensions::Authentication

    enable_authentication
    match /turn (.+) (.+)/

    def initialize(*args)
      super
      @bot.cleverbot_enabled = true
      @bot.dctv_commands_enabled = true
    end

    def execute(m, group, action)
      failed = false
      case action
      when "on": turn_off = false
      when "off": turn_off = true
      else
        failed = true
      end

      case group
      when "cleverbot": @bot.cleverbot_enabled = toggle_command_set(m, "Cleverbot interfaces", turn_off, @bot.cleverbot_enabled)
      when "dctv": @bot.dctv_commands_enabled = toggle_command_set(m, "DCTV commands", turn_off, @bot.dctv_commands_enabled)
      when "all"
        @bot.cleverbot_enabled = toggle_command_set(m, "Cleverbot interfaces", turn_off, @bot.cleverbot_enabled)
        @bot.dctv_commands_enabled = toggle_command_set(m, "DCTV commands", turn_off, @bot.dctv_commands_enabled)
      else
        failed = true
      end

      m.user.notice "Sorry, I don't know how to turn #{group} #{action}" if failed
    end

    private

      def toggle_command_set(m, command_set_name, turn_off, command_boolean_variable)
        if turn_off
          command_boolean_variable ? m.user.notice("#{command_set_name} have been disabled") : m.user.notice("#{command_set_name} are already disabled")
          return false
        else
          command_boolean_variable ? m.user.notice("#{command_set_name} are already enabled") : m.user.notice("#{command_set_name} have been enabled")
          return true
        end
      end
  end

end
{'fraction_non_alphanumeric': 0.08701936976004626, 'fraction_numerical': 0.0005782017924255566, 'mean_word_length': 2.578076525336091, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '2943436', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1040, 'n_words': 259}