-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzelda_status.rb
47 lines (38 loc) · 945 Bytes
/
zelda_status.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
require 'cgi'
module ZURPG
class StatusHandler
CHECK = '✅'
TRASH = '🗑'
attr_reader :user_status
private :user_status
def initialize
@user_status = {}
end
def handle_save(status, event)
user_status[author_id(event)] = status
event.message.create_reaction(CHECK)
end
def handle_fetch(event)
author = author_id(event)
status = user_status[author]
author_name =
if event.author.respond_to?(:display_name)
then event.author.display_name
else event.author.username
end
if status
event << "**#{author_name}**: #{status}"
else
event << "**#{author_name}**: _No status recorded_"
end
end
def handle_clear(event)
user_status.delete(author_id(event))
event.message.create_reaction(TRASH)
end
private
def author_id(event)
event.author.distinct
end
end
end