-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiscord_notify_bot.rb
64 lines (57 loc) · 2.3 KB
/
discord_notify_bot.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
require 'uri'
require 'net/http'
require 'json'
def discord(msg)
Net::HTTP.post(
URI.parse(ENV.fetch('DISCORD_WEBHOOK_URL')),
{ content: msg.to_s }.to_json,
{ 'Content-Type' => 'application/json' },
)
end
mention_mappings = {
'ujihisa' => '<@349891868273672194>',
'お豆腐ニキ' => '<@312616968882618368>',
'pankona' => '<@372183319372103680>',
'あさり食堂' => '<@630782140224765952>',
'tattotatto0806' => '<@761750299118665728>',
'yshr446' => '<@731154668033409046>',
}
discord('Server restarted')
current_players = []
IO.popen('tail -f /7-days-to-die/output_log.txt') do |io|
loop do
line = io.readline.chomp
case line
when %r(^[^ ]+ [^ ]+ INF RequestToEnterGame: [^/]+/(.+)$)
# 2021-12-26T03:34:56 72.400 INF RequestToEnterGame: EOS_0002831795af4125b164741191188cab/ujihisa
discord("#{$1} is trying to join")
when %r(^[^ ]+ [^ ]+ INF GMSG: Player '(.+)' joined the game$)
# 2021-12-26T03:35:40 115.999 INF GMSG: Player 'ujihisa' joined the game
current_players << "#{$1}"
discord("#{$1} joined the game. (Current players: #{current_players.join(', ')})")
when %r(^[^ ]+ [^ ]+ INF GMSG: Player '(.+)' left the game$)
# 2021-12-26T03:35:46 121.808 INF GMSG: Player 'ujihisa' left the game
current_players.delete("#{$1}")
if current_players.empty?
discord("#{$1} left the game. (No other current players)")
else
discord("#{$1} left the game. (Current players: #{current_players.join(', ')})")
end
when %r(^[^ ]+ [^ ]+ INF GMSG: Player '(.+)' died$)
# 2021-12-27T15:14:33 127013.793 INF GMSG: Player 'ujihisa' died
discord("#{$1} died")
when %r(^[^ ]+ [^ ]+ INF Chat \([^\)]+\): '(.+)': (.*)$)
# 2021-12-27T16:42:13 132273.809 INF Chat (from 'Steam_76561198145251396', entity id '177', to 'Global'): 'pankona': ~A~J
(who, msg) = [$1, $2]
discord("#{who}「#{msg.strip}」")
case msg
when /^!here\b/
targets = mention_mappings.reject {|k, _| current_players.include?(k) }.values.shuffle.join(' ')
discord("#{targets} いま盛り上がってます。レッツ参加!")
end
when %r(^[^ ]+ [^ ]+ INF (BloodMoon starting for day .*)$)
# 2021-12-29T07:32:37 96581.661 INF BloodMoon starting for day 7
discord("#{$1}")
end
end
end