ika_bot/lib/lesson.rb

47 lines
1.1 KiB
Ruby

require "rufus-scheduler"
DEFAULT_LESSON_PLAN = [
[15, "login and catch up on the week"],
[45, "review chapter vocab and grammar"],
[15, "answer Seth Clydesdale Genki review questions"],
[15, "ask closing questions and have Japanese conversation"],
]
class Lesson
attr_reader :lesson_plan, :channel, :running, :scheduler
attr_accessor :responder
def initialize(lesson_plan=DEFAULT_LESSON_PLAN, scheduler: Rufus::Scheduler.new, responder: nil)
@lesson_plan = lesson_plan
@running = false
@scheduler = scheduler
@responder = responder
end
def stop!
@scheduler.shutdown
end
def start!(channel)
lesson_plan.each_with_index do |(time, message), index|
offset = lesson_plan.map(&:first)[0..index - 1].sum(0)
offset = 0 if index == 0
scheduler.in "#{offset}m" do
responder.call "#{time} minutes to #{message}"
end
end
end_offset = lesson_plan.map(&:first).sum(0)
scheduler.in "#{end_offset}m" do
responder.call "Lesson over!"
@running = false
end
@running = true
end
def running?
running
end
end