2025-08-15 16:25:29 -04:00
|
|
|
require_relative './session'
|
2025-08-15 17:03:12 -04:00
|
|
|
require_relative './lesson'
|
|
|
|
require_relative './commands'
|
2025-08-15 16:25:29 -04:00
|
|
|
|
|
|
|
class Ika
|
|
|
|
attr_reader :bot
|
|
|
|
attr_reader :lessons, :sessions
|
|
|
|
attr_accessor :current_lesson, :current_session
|
|
|
|
|
|
|
|
def initialize(bot)
|
|
|
|
@bot = bot
|
|
|
|
@lessons = {}
|
|
|
|
@sessions = {}
|
|
|
|
@current_session = nil
|
|
|
|
@current_lesson = Lesson.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def start!
|
|
|
|
bot.remove_handler @message_handler if @message_handler
|
|
|
|
|
|
|
|
@message_handler = bot.message do |message|
|
|
|
|
handle_message message
|
|
|
|
end
|
|
|
|
|
|
|
|
bot.run # you can run this in the background, idk
|
|
|
|
end
|
|
|
|
|
2025-08-15 17:03:12 -04:00
|
|
|
def stop!
|
2025-08-15 16:25:29 -04:00
|
|
|
bot.remove_handler @message_handler if @message_handler
|
|
|
|
end
|
|
|
|
|
2025-08-15 17:03:12 -04:00
|
|
|
def current_lesson_running?
|
|
|
|
current_lesson.running?
|
|
|
|
end
|
|
|
|
|
|
|
|
def start_lesson!(message)
|
|
|
|
current_lesson.start!(message.channel)
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop_current_lesson!
|
|
|
|
current_lesson.stop!
|
|
|
|
end
|
|
|
|
|
|
|
|
def handle_message(message)
|
|
|
|
if command = Commands::Command.for(self, message)
|
|
|
|
command.execute
|
|
|
|
end
|
2025-08-15 16:25:29 -04:00
|
|
|
|
2025-08-15 17:03:12 -04:00
|
|
|
return current_session&.respond_to message
|
2025-08-15 16:25:29 -04:00
|
|
|
|
2025-08-15 17:03:12 -04:00
|
|
|
if message.message.content == "!init"
|
|
|
|
return message.respond("There's already a session running") unless current_session.nil?
|
2025-08-15 16:25:29 -04:00
|
|
|
|
2025-08-15 17:03:12 -04:00
|
|
|
return current_session = Session.new(message, event.message.author)
|
|
|
|
end
|
2025-08-15 16:25:29 -04:00
|
|
|
end
|
|
|
|
end
|