<commit_before>module Chat
  class User
    # Public: Returns the user ID
    attr_reader :id

    # Public: Returns the user name
    attr_reader :name

    # Public: Returns the the user e-mail
    attr_reader :email

    # Public: Returns the md5-hash of the user e-mail
    # String
    attr_reader :hash

    # Public: Returns the user role
    attr_reader :role

    # Public: Returns the preset user color
    attr_reader :color

    # Public: Returns if the user wants to see NSFW content
    attr_reader :nsfw

    # Public: New instance of User from scratch
    #
    # id    - user ID
    # name  - <NAME>
    # email - user e-mail
    # role  - user role
    # color - user preferred HEX color
    # nsfw  - user preferred NSFW setting on/off
    def initialize(id, name, email, role, color, nsfw)
      @id    = id
      @name  = name
      @email = email
      @hash  = Digest::MD5.hexdigest(email)
      @role  = role
      @color = color
      @nsfw  = nsfw
    end

    # Public: New instance of User from a datastore session identifier
    #
    # identifier - key for datastore look-up
    #
    # Returns an instance of User
    def self.from_datastore(identifier)
      user_hash = JSON.parse(redis("get", "user:session:#{identifier}"))
      self.new user_hash['id'], user_hash['name'], user_hash['email'], user_hash['role'], user_hash['color'], user_hash['nsfw']
    end

    # Public: Mute the user
    #
    # Returns nothing
    def mute!
      self.class.redis("set", "chat:mute:#{@name}", true)
    end

    # Public: Remove the mute on the user<commit_msg>Exception on empty datastore user<commit_after>module Chat
  class User
    # Public: Returns the user ID
    attr_reader :id

    # Public: Returns the user name
    attr_reader :name

    # Public: Returns the the user e-mail
    attr_reader :email

    # Public: Returns the md5-hash of the user e-mail
    # String
    attr_reader :hash

    # Public: Returns the user role
    attr_reader :role

    # Public: Returns the preset user color
    attr_reader :color

    # Public: Returns if the user wants to see NSFW content
    attr_reader :nsfw

    # Public: New instance of User from scratch
    #
    # id    - user ID
    # name  - <NAME>
    # email - user e-mail
    # role  - user role
    # color - user preferred HEX color
    # nsfw  - user preferred NSFW setting on/off
    def initialize(id, name, email, role, color, nsfw)
      @id    = id
      @name  = name
      @email = email
      @hash  = Digest::MD5.hexdigest(email)
      @role  = role
      @color = color
      @nsfw  = nsfw
    end

    # Public: New instance of User from a datastore session identifier
    #
    # identifier - key for datastore look-up
    #
    # Returns an instance of User
    def self.from_datastore(identifier)
      user_hash = JSON.parse(redis("get", "user:session:#{identifier}"))
      raise "Given user is empty" if user_hash.nil?
      self.new user_hash['id'], user_hash['name'], user_hash['email'], user_hash['role'], user_hash['color'], user_hash['nsfw']
    end

    # Public: Mute the user
    #
    # Returns nothing
    def mute!
      self.class.redis("set", "chat:mute:#{@name}", true)
    end

    # Public: Remove the mute on the user
{'fraction_non_alphanumeric': 0.09561998766193708, 'fraction_numerical': 0.0012338062924120913, 'mean_word_length': 2.4390243902439024, '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': '5232851', 'n_tokens_mistral': 1030, 'n_tokens_neox': 1002, 'n_words': 344}