-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask4.rb
More file actions
99 lines (68 loc) · 1.87 KB
/
task4.rb
File metadata and controls
99 lines (68 loc) · 1.87 KB
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
require 'discordrb'
DISCORD_TOKEN = '..-'
CLIENT_ID =
CHANNEL_ID = 531643454846009344
CHANNEL_ID_DEBUG = 532940099412033537
USER_ID = 531657432544313345
ok = 0
hmm = 0
ng = 0
total = 0
time = "00:00"
timecode = 0
@bot = Discordrb::Commands::CommandBot.new token: DISCORD_TOKEN, client_id: CLIENT_ID, prefix: '!'
def start_typing(token, channel_id)
Discordrb::API.request(
:channels_cid_typing,
channel_id,
:post,
"#{Discordrb::API.api_base}/channels/#{channel_id}/typing",
nil,
Authorization: token
)
end
cn = @bot.channel(CHANNEL_ID)
last_ten_messages = cn.history(100)
last_ten_messages.each do | key |
#start_typing(DISCORD_TOKEN,cn.id)
sleep(1)
if key.user.id == USER_ID then
begin
ok = key.reactions["ok"].count - 1
hmm = key.reactions["hmm"].count - 1
ng = key.reactions["ng"].count - 1
total = ok + hmm + ng
puts total
next
rescue => e
end
end
end
if (total <= 0) then
@bot.send_message(CHANNEL_ID,"<@&532903286613999617> 自動招集に必要な票数に達していません、もしくは処理中に何らかのエラーが発生しました。")
timecode = 0
return
end
puts "ok:#{ok}"
puts "ng:#{ng}"
puts "hmm:#{hmm}"
total = ok + hmm + ng
ok = ok * 1
hmm = hmm * 0.85
ng = ng * -1
caled = (ok + ng + hmm) / (total * 1)
puts "評価値:#{caled}"
if total >= 8 && caled >= 0.7 then
time = "21:00"
timecode = 1
elsif caled >= 0.55 then
time = "21:30"
timecode = 2
else
time = "22:00"
timecode = 3
end
@bot.send_message(CHANNEL_ID,"<@&532903286613999617> 今夜、pugを開催します時間は **#{time}** (GMT+9)からです!\nWe will be holding a pug tonight at **#{time}** (GMT+9) come play!")
File.open("/home/daburutti/DKC_bot/time","w") do | b |
b.print(timecode)
end