ika_bot/lib/lesson.rb

47 lines
1.1 KiB
Ruby
Raw Normal View History

require "rufus-scheduler"
2025-08-14 20:02:00 -04:00
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
2025-08-23 14:38:42 -04:00
attr_reader :lesson_plan, :channel, :running, :scheduler
attr_accessor :responder
2025-08-14 20:02:00 -04:00
2025-08-23 14:38:42 -04:00
def initialize(lesson_plan=DEFAULT_LESSON_PLAN, scheduler: Rufus::Scheduler.new, responder: nil)
2025-08-14 20:02:00 -04:00
@lesson_plan = lesson_plan
@running = false
@scheduler = scheduler
2025-08-23 14:38:42 -04:00
@responder = responder
2025-08-14 20:02:00 -04:00
end
def stop!
@scheduler.shutdown
2025-08-14 20:02:00 -04:00
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
2025-08-23 14:38:42 -04:00
responder.call "#{time} minutes to #{message}"
2025-08-14 20:02:00 -04:00
end
end
end_offset = lesson_plan.map(&:first).sum(0)
scheduler.in "#{end_offset}m" do
2025-08-23 14:38:42 -04:00
responder.call "Lesson over!"
2025-08-14 20:02:00 -04:00
@running = false
end
@running = true
2025-08-14 20:02:00 -04:00
end
def running?
running
end
end