Add safeguards around invalid drill states
This commit is contained in:
parent
5970841784
commit
f2870ae4f6
10
lib/drill.rb
10
lib/drill.rb
@ -37,6 +37,8 @@ class Drill
|
||||
end
|
||||
|
||||
def handle_join(message)
|
||||
return respond "The drill's already started!" if running?
|
||||
|
||||
if participants.include? message.author
|
||||
respond "You've already joined"
|
||||
else
|
||||
@ -46,6 +48,8 @@ class Drill
|
||||
end
|
||||
|
||||
def handle_leave(message)
|
||||
return respond "The drill's already started!" if running?
|
||||
|
||||
if participants.include? message.author
|
||||
self.participants -= [message.author]
|
||||
respond "#{message.author.display_name} has left"
|
||||
@ -56,6 +60,7 @@ class Drill
|
||||
|
||||
def handle_start(message)
|
||||
return respond "The drill's already started!" if running?
|
||||
return respond "Nobody has joined the drill! Type `join` to join it!" if participants.empty?
|
||||
|
||||
@running = true
|
||||
@time_is_up = false
|
||||
@ -68,9 +73,9 @@ class Drill
|
||||
def handle_stop(message)
|
||||
return respond "The drill's not running yet" unless running?
|
||||
|
||||
@running = false
|
||||
scheduler.unschedule(timer_job_id) if timer_job_id
|
||||
respond "Drill stopped!"
|
||||
|
||||
end_drill!
|
||||
end
|
||||
|
||||
def handle_customize_length(message)
|
||||
@ -105,6 +110,7 @@ class Drill
|
||||
def end_drill!
|
||||
respond "Time's up! Everyone did great!"
|
||||
@running = false
|
||||
@participants = []
|
||||
end
|
||||
|
||||
def generate_question
|
||||
|
Loading…
Reference in New Issue
Block a user