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
|
end
|
||||||
|
|
||||||
def handle_join(message)
|
def handle_join(message)
|
||||||
|
return respond "The drill's already started!" if running?
|
||||||
|
|
||||||
if participants.include? message.author
|
if participants.include? message.author
|
||||||
respond "You've already joined"
|
respond "You've already joined"
|
||||||
else
|
else
|
||||||
@ -46,6 +48,8 @@ class Drill
|
|||||||
end
|
end
|
||||||
|
|
||||||
def handle_leave(message)
|
def handle_leave(message)
|
||||||
|
return respond "The drill's already started!" if running?
|
||||||
|
|
||||||
if participants.include? message.author
|
if participants.include? message.author
|
||||||
self.participants -= [message.author]
|
self.participants -= [message.author]
|
||||||
respond "#{message.author.display_name} has left"
|
respond "#{message.author.display_name} has left"
|
||||||
@ -56,6 +60,7 @@ class Drill
|
|||||||
|
|
||||||
def handle_start(message)
|
def handle_start(message)
|
||||||
return respond "The drill's already started!" if running?
|
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
|
@running = true
|
||||||
@time_is_up = false
|
@time_is_up = false
|
||||||
@ -68,9 +73,9 @@ class Drill
|
|||||||
def handle_stop(message)
|
def handle_stop(message)
|
||||||
return respond "The drill's not running yet" unless running?
|
return respond "The drill's not running yet" unless running?
|
||||||
|
|
||||||
@running = false
|
|
||||||
scheduler.unschedule(timer_job_id) if timer_job_id
|
scheduler.unschedule(timer_job_id) if timer_job_id
|
||||||
respond "Drill stopped!"
|
|
||||||
|
end_drill!
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_customize_length(message)
|
def handle_customize_length(message)
|
||||||
@ -105,6 +110,7 @@ class Drill
|
|||||||
def end_drill!
|
def end_drill!
|
||||||
respond "Time's up! Everyone did great!"
|
respond "Time's up! Everyone did great!"
|
||||||
@running = false
|
@running = false
|
||||||
|
@participants = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_question
|
def generate_question
|
||||||
|
Loading…
Reference in New Issue
Block a user