<commit_before>module Ruboty
  module Actions
    class Todo < Base
      COMMANDS = %w[list help add start finish delete cleanup renum]
      attr_reader :todo_list

      def call
        (command, arg) = (message[:data] || '').split(/\s/, 2)
        command = parse_command(command)
        @todo_list = ::Ruboty::Todo::List.new(message.robot.brain)

        result = self.send(command, arg)
        message.reply(result)
      end

      def list(arg)
        todo_list.items.map(&:format).join(?\n)
      end

      def help(arg)
      end

      def add(arg)
        return '' if arg.to_s == ''
        todo_list.add(title: arg).format(new_item: true)
      end

      def start(arg)
        change_item_state(arg, :start)
      end

      def finish(arg)
        change_item_state(arg, :finish)
      end

      def delete(arg)
        change_item_state(arg, :delete)
      end

      def cleanup(arg)<commit_msg>:information_desk_person: add help<commit_after>module Ruboty
  module Actions
    class Todo < Base
      COMMANDS = %w[list help add start finish delete cleanup renum]
      attr_reader :todo_list

      def call
        (command, arg) = (message[:data] || '').split(/\s/, 2)
        command = parse_command(command)
        @todo_list = ::Ruboty::Todo::List.new(message.robot.brain)

        result = self.send(command, arg)
        message.reply(result)
      end

      def list(arg)
        todo_list.items.map(&:format).join(?\n)
      end

      def help(arg)
<<EOH
  `todo list`
    show todo list
  `todo add [TITLE]`
    add list to new todo
  `todo start [ID}`
    start todo
  `todo finish [ID]`
    finish todo (will removed by `cleanup`)
  `todo delete [ID]`
    remove todo (will removed by `cleanup`)
  `todo cleanup`
    delete finished and deleted items from list
  `todo renum`
    renum id from 1
  `todo help`
    show this help
EOH
      end

      def add(arg)
        return 'specify todo tilte like `todo add [TITLE]`' if title == ''
        todo_list.add(title: title).format(new_item: true)
      end

      def start(arg)
        change_item_state(arg, :start)
      end

      def finish(arg)
        change_item_state(arg, :finish)
      end

      def delete(arg)
        change_item_state(arg, :delete)
      end

      def cleanup(arg)
{'fraction_non_alphanumeric': 0.10878112712975098, 'fraction_numerical': 0.001310615989515072, 'mean_word_length': 2.2344632768361583, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4302214', 'n_tokens_mistral': 779, 'n_tokens_neox': 749, 'n_words': 200}