<commit_before># A ConditionalTask acts as a prodcedure that can be used by a TimedTask.
#
# @example
#   bot = Bot.new(config)
#   period_len = 90
#   tt = TimedTask.new(period_len) { MoveAfkUsers.new(bot).run }
#   tt.start
#   ...
#   tt.stop
class PeriodicTask
  def initialize(bot)
    @bot = bot
    @afk_channel = Channel.find_by_name("AFK")
  end

  def run
    task
  end

  protected

  def task
    raise "Not implemented yet"
  end

end

# Check the afk state of every online user.
class MoveAfkUsers < PeriodicTask
  def task
    afk_users = User.all.select(&:afk?)
    afk_users.each do |user|
      @bot.move_target(user, @afk_channel.id)
      @bot.say_as_poke(user, "Sorry, but I moved you to the AFK channel.")
    end
  end
end<commit_msg>Do not move users to the AFK channel that are already in that channel<commit_after># A ConditionalTask acts as a prodcedure that can be used by a TimedTask.
#
# @example
#   bot = Bot.new(config)
#   period_len = 90
#   tt = TimedTask.new(period_len) { MoveAfkUsers.new(bot).run }
#   tt.start
#   ...
#   tt.stop
class PeriodicTask
  def initialize(bot)
    @bot = bot
    @afk_channel = Channel.find_by_name("AFK")
  end

  def run
    task
  end

  protected

  def task
    raise "Not implemented yet"
  end

end

# Check the afk state of every user that is online.
# If they are afk and not already located at the AFK channel,
# then move them to the AFK channel.
class MoveAfkUsers < PeriodicTask
  def task
    afk_users = User.all.select(&:afk?)
    afk_users.each do |user|
      unless user.channel_id == @afk_channel.id
        @bot.move_target(user, @afk_channel.id)
        @bot.say_as_poke(user, "Sorry, but I moved you to the AFK channel.")
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09362435381964389, 'fraction_numerical': 0.0022975301550832855, 'mean_word_length': 2.9322799097065464, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4292748', 'n_tokens_mistral': 628, 'n_tokens_neox': 617, 'n_words': 195}