-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyuzu.rb
100 lines (82 loc) · 2.35 KB
/
yuzu.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
class Yuzu
def initialize
ENV['TZ'] = 'Asia/Tokyo'
@keywords = {}
File.open("yuzu_keywords.txt", 'r') do |f|
f.each_line do |line|
next if /^(\n|#)/ =~ line
s = line.split(",", 2)
@keywords[s[0]] = s[1].chomp.split("\t")
end
end
@fallback_words = []
File.open("yuzu_fallback_words.txt", 'r') do |f|
f.each_line do |line|
next if /^(\n|#)/ =~ line
@fallback_words << line.chomp
end
end
end
def current_jst_time
Time.now.to_s.gsub(" +0900", "")
end
def profile_actived
{
name: "yuzu🍬",
location: "柚子、登場!☀(#{current_jst_time})",
profile_link_color: "#fdc823"
}
end
def profile_sleeped
{
name: "yuzu💤🍬",
location: logout_status_message,
profile_link_color: "#f1c8d0"
}
end
def set_maintenance_status
@maintenance = true
end
def maintenance_mark
"💓"
end
def user_profile(client)
"@#{client.user.screen_name}こと#{client.user.name}登場! #{client.user.description} さっきまでは、#{client.user.location}"
end
def login_message
"おっまたせ〜!✌(#{current_jst_time})"
end
def error_message
"しょぼ〜ん💔(#{current_jst_time})"
end
def logout_message
"まったね〜。ばいばーい🍭(#{current_jst_time})"
end
def logout_status_separator
"💤"
end
def logout_status_message
"お布団の中#{logout_status_separator}(#{current_jst_time})#{@maintenance ? maintenance_mark : ""}"
end
def replace_command(message, tweet)
message.gsub("</user_name>", tweet.user.name)
end
def reply_message(tweet)
received_message = tweet.text.gsub(/@\w+/,"").strip
base_message = reply_message_from_received_message(received_message)
formatted_message = replace_command(base_message, tweet)
"@#{tweet.user.screen_name} #{formatted_message}"
end
def reply_message_from_received_message(received_message)
found_key = @keywords.keys.find{|key| /#{key}/ === received_message }
return @keywords[found_key].sample if found_key
@fallback_words.sample
end
end
return unless $0 == __FILE__
yuzu = Yuzu.new
p yuzu.login_message
received_message = ARGV[0]
reply_message = yuzu.reply_message_from_received_message(received_message)
p "#{received_message} -> #{reply_message}"
p yuzu.logout_message