-
Notifications
You must be signed in to change notification settings - Fork 0
/
toot_operation.rb
122 lines (86 loc) · 2.73 KB
/
toot_operation.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
def mstdn_fav(id, account)
toot = toot_test(id, account)
if !(toot["body"] ["favourited"])
uri = URI.parse("https://#{account[:host]}/api/v1/statuses/#{id}/favourite")
else
uri = URI.parse("https://#{account[:host]}/api/v1/statuses/#{id}/unfavourite")
end
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
req = Net::HTTP::Post.new(uri.request_uri)
token = " Bearer " + account[:token]
req["Authorization"] = token
res = https.request(req)
activity :mikutodon_debug_message, "#{res.code}\n#{res.message}"
end
def mstdn_reblog(id, account)
toot = toot_test(id, account)
if !(toot["body"] ["reblogged"])
uri = URI.parse("https://#{account[:host]}/api/v1/statuses/#{id}/reblog")
else
uri = URI.parse("https://#{account[:host]}/api/v1/statuses/#{id}/unreblog")
end
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
req = Net::HTTP::Post.new(uri.request_uri)
token = " Bearer " + account[:token]
req["Authorization"] = token
res = https.request(req)
activity :mikutodon_debug_message, "#{res.code}\n#{res.message}"
end
def toot_test(id, account)
uri = URI.parse("https://#{account[:host]}/api/v1/statuses/#{id}")
token = " Bearer " + account[:token]
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
req = Net::HTTP::Get.new(uri.path)
req["Authorization"] = token
res = https.request(req)
return ({'code' => res.code,
'message' => res.message,
'body' => JSON.parse(res.body)})
end
def post_toot(text, cw, account, config)
vis =
case config
when 0 then
vis = "public"
when 1 then
vis = "unlisted"
when 2 then
vis = "private"
when 3 then
vis = "direct"
when 4 then
case rand(1..400)
when 1..100 then
vis = "public"
when 101..200 then
vis = "unlisted"
when 201..300 then
vis = "private"
when 301..400 then
vis = "direct"
else
activity :mikutodon_debug_message, "0から3までの乱数が0から3以外の数値を出したよ!\nすごいね!どう考えてもバグだね!"
end
else
vis = "public"
end
uri = URI.parse("https://#{account[:host]}/api/v1/statuses")
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
req = Net::HTTP::Post.new(uri.request_uri)
data = {
status: text,
visibility: vis,
spoiler_text: cw
}.to_json
token = " Bearer " + account[:token]
req["Content-Type"] = "application/json"
req["Authorization"] = token
req.body = data
res = https.request(req)
$toot_result = res.body
activity :mikutodon_debug_message, "#{res.code}\n#{res.message}"
end