-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_notification.rb
102 lines (79 loc) · 3.02 KB
/
create_notification.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
def create_notification(json)
data = JSON.parse(json)
case data["type"]
when "favourite" then
user_name = if data["status"]["account"] ["display_name"].empty?
data["status"]["account"] ["username"]
else
data["status"]["account"] ["display_name"]
end
if !(data["status"]["spoiler_text"].empty?)
cw_body = Nokogiri::HTML.parse(data["status"]["spoiler_text"],nil,"UTF-8")
body = Nokogiri::HTML.parse(data["status"]["content"],nil,"UTF-8")
cw_body.search('br').each do |br|
br.replace("\n")
end
body.search('br').each do |br|
br.replace("\n")
end
toot_body = cw_body.text + "\n\n" + body.text
else
# HTMLのParse
body = Nokogiri::HTML.parse(data["status"]["content"],nil,"UTF-8")
body.search('br').each do |br|
br.replace("\n")
end
toot_body = body.text
end
activity :mstdn_fav, "#{parse_name(data)}さんにふぁぼられました。\n\n#{user_name}: #{toot_body}"
when "reblog" then
user_name = if data["status"]["account"] ["display_name"].empty?
data["status"]["account"] ["username"]
else
data["status"]["account"] ["display_name"]
end
if !(data["status"]["spoiler_text"].empty?)
cw_body = Nokogiri::HTML.parse(data["status"]["spoiler_text"],nil,"UTF-8")
body = Nokogiri::HTML.parse(data["status"]["content"],nil,"UTF-8")
cw_body.search('br').each do |br|
br.replace("\n")
end
body.search('br').each do |br|
br.replace("\n")
end
toot_body = cw_body.text + "\n\n" + body.text
else
# HTMLのParse
body = Nokogiri::HTML.parse(data["status"]["content"],nil,"UTF-8")
body.search('br').each do |br|
br.replace("\n")
end
toot_body = body.text
end
activity :mstdn_reblog, "#{parse_name(data)}さんにぶーすとされました。\n\n#{user_name}: #{toot_body}"
when "follow" then
activity :mstdn_follow, "#{parse_name(data)}(#{data["account"]["acct"]})にフォローされました"
when "mention" then
if !(data["status"]["spoiler_text"].empty?)
cw_body = Nokogiri::HTML.parse(data["status"]["spoiler_text"],nil,"UTF-8")
body = Nokogiri::HTML.parse(data["status"]["content"],nil,"UTF-8")
cw_body.search('br').each do |br|
br.replace("\n")
end
body.search('br').each do |br|
br.replace("\n")
end
toot_body = cw_body.text + "\n\n" + body.text
else
# HTMLのParse
body = Nokogiri::HTML.parse(data["status"]["content"],nil,"UTF-8")
body.search('br').each do |br|
br.replace("\n")
end
toot_body = body.text
end
activity :mstdn_mention, "#{parse_name(data)}から返信があります。\n\n#{toot_body}"
else
activity :mikutodon_debug_message, data
end
end