<commit_before>module Ruboty
  module Handlers
    class Karoshi < Base
      NAMESPACE = 'karoshi'

      on %r|(?<n_hours>\d(\.\d)?)時間残業します|, description: '発言者の残業が申請されます', name: :n_hours_application
      on %r|残業申請者一覧|, description: '残業者を取得します', name: :show_list

      def n_hours_application(message)
        from = message.original[:from]
        n_hours = message[:n_hours].to_f
        write(from: from, n_hours: n_hours)
        message.reply("#{n_hours}時間ですね。残業頑張ってください")
      end

      def show_list(message)
        if workers = read
          workers.each do |worker, data|
            message.reply("#{worker}: #{data[:n_hours]}時間")
          end
        else
          message.reply("残業する人はいません。")
        end
      end

      private

      def write(from: from, n_hours: n_hours)
        today = Date.today

        robot.brain.data[NAMESPACE] ||= {}
        robot.brain.data[NAMESPACE][today] ||= {}
        robot.brain.data[NAMESPACE][today][from] = {n_hours: n_hours}
      end

      def read
        data = robot.brain.data[NAMESPACE] || {}
        data[Date.today] || {}
      end
    end
  end<commit_msg>Support 時間"半" Style<commit_after>module Ruboty
  module Handlers
    class Karoshi < Base
      NAMESPACE = 'karoshi'

      on %r|(?<n_hours>\d(\.\d)?)時間(?<half_an_hour>半)?残業します|, description: '発言者の残業が申請されます', name: :n_hours_application
      on %r|残業申請者一覧|, description: '残業者を取得します', name: :show_list

      def n_hours_application(message)
        from = message.original[:from]
        n_hours = message[:n_hours].to_f
        n_hours += 0.5 if message[:half_an_hour].to_s != ''
        write(from: from, n_hours: n_hours)
        message.reply("#{n_hours}時間ですね。残業頑張ってください")
      end

      def show_list(message)
        if workers = read
          workers.each do |worker, data|
            message.reply("#{worker}: #{data[:n_hours]}時間")
          end
        else
          message.reply("残業する人はいません。")
        end
      end

      private

      def write(from: from, n_hours: n_hours)
        today = Date.today

        robot.brain.data[NAMESPACE] ||= {}
        robot.brain.data[NAMESPACE][today] ||= {}
        robot.brain.data[NAMESPACE][today][from] = {n_hours: n_hours}
      end

      def read
        data = robot.brain.data[NAMESPACE] || {}
        data[Date.today] || {}
      end
    end
  end
{'fraction_non_alphanumeric': 0.1342138900724329, 'fraction_numerical': 0.0008521516829995739, 'mean_word_length': 2.3257790368271953, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, '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': '4601370', 'n_tokens_mistral': 908, 'n_tokens_neox': 862, 'n_words': 147}