Add lessons
This commit is contained in:
parent
f70a16ec43
commit
4304fbfe41
10
ika.rb
10
ika.rb
@ -1,17 +1,27 @@
|
||||
require 'discordrb'
|
||||
require_relative './session'
|
||||
require_relative './lesson'
|
||||
|
||||
token = File.read("./token")
|
||||
|
||||
bot = Discordrb::Bot.new(token:)
|
||||
|
||||
current_session = nil
|
||||
current_lesson = Lesson.new
|
||||
|
||||
bot.message do |event|
|
||||
if event.message.content == "!init"
|
||||
next event.respond("There's already a session running") unless current_session.nil?
|
||||
|
||||
next current_session = Session.new(event, event.message.author)
|
||||
elsif event.message.content == "!lesson"
|
||||
next event.respond("There's already a lesson running") if current_lesson.running?
|
||||
event.respond("Starting a lesson now!")
|
||||
next current_lesson.start!(event.channel)
|
||||
elsif event.message.content == "!stoplesson"
|
||||
next event.respond("There's no lesson running") unless current_lesson.running?
|
||||
event.respond("Ending the current lesson!")
|
||||
next current_lesson.stop!
|
||||
end
|
||||
|
||||
current_session&.respond_to event
|
||||
|
38
lesson.rb
Normal file
38
lesson.rb
Normal file
@ -0,0 +1,38 @@
|
||||
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, :thread, :running
|
||||
|
||||
def initialize(lesson_plan=DEFAULT_LESSON_PLAN)
|
||||
@lesson_plan = lesson_plan
|
||||
@running = false
|
||||
end
|
||||
|
||||
def stop!
|
||||
thread.kill if thread
|
||||
@running = false
|
||||
end
|
||||
|
||||
def start!(channel)
|
||||
stop!
|
||||
@channel = channel
|
||||
@thread = Thread.new do
|
||||
@running = true
|
||||
lesson_plan.each do |time, message|
|
||||
channel.send_message "#{time} minutes to #{message}"
|
||||
sleep(time * 60)
|
||||
end
|
||||
channel.send_message "Lesson over!"
|
||||
@running = false
|
||||
end
|
||||
end
|
||||
|
||||
def running?
|
||||
running
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user