-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathattack.rb
More file actions
54 lines (38 loc) · 783 Bytes
/
attack.rb
File metadata and controls
54 lines (38 loc) · 783 Bytes
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
54
module NP
class Attack
NAMESPACE = "np:attack:acknowledged"
def self.acknowledge(code)
key = "#{NAMESPACE}:#{code}"
$redis.set(key, "yes")
end
def initialize(player:, fleet:, star:)
@star = star
@fleet = fleet
@player = player
end
def alert
if historic?
puts "#{_code} - already acknoweldged"
puts "\n"
else
alert = NP::Alert.new(
player: @player,
fleet: @fleet,
star: @star,
code: _code
)
alert.call
end
end
def historic?
$redis.get(_key) == "yes"
end
private
def _code
"#{@player.id}-#{@fleet.id}-#{@star.id}"
end
def _key
"#{NAMESPACE}:#{_code}"
end
end
end