-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathschedule_raid.rb
53 lines (42 loc) · 1.23 KB
/
schedule_raid.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'models/raid'
require 'repository'
##
# Create a new raid schedule or update an existing one.
# The raid will be owned by the given +current_guild+.
#
# A raid needs a location (+where+), a date (+raid_date+),
# a start time (+raid_time+) and optionally a hash of +roles+
# to define the types of characters needed in this raid.
#
# The start time for a raid by default is 15 minutes before the
# start time. This will eventually be configurable.
#
# To update an existing raid with new information, use
# +current_raid=+ to set that raid.
##
class ScheduleRaid
DEFAULT_INVITE_WINDOW = 15 * 60
attr_reader :current_guild
##
# Use this value to update an existing Raid instead of
# creating a new one.
##
attr_accessor :current_raid
def initialize(current_guild)
@current_guild = current_guild
end
def run(where, raid_date, raid_time, roles = nil)
raid = @current_raid || Raid.new
raid.where = where
raid.when = raid_date
raid.start_at = raid_time
raid.invite_at = raid_time - DEFAULT_INVITE_WINDOW
raid.owner = @current_guild
if roles
roles.each do |role, limit|
raid.set_role_limit(role, limit)
end
end
Repository.for(Raid).save raid
end
end