-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttbot.rb
More file actions
82 lines (63 loc) · 1.54 KB
/
buttbot.rb
File metadata and controls
82 lines (63 loc) · 1.54 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
require 'mumble-ruby'
require 'slack-notifier'
class ButtBot
def mumble_url
ENV['MUMBLE_URL'] || 'localhost'
end
def mumble_username
ENV['MUMBLE_USERNAME'] || 'ButtBot'
end
def mumble_channel
ENV['MUMBLE_CHANNEL'] || '[BUTT]'
end
def mumble
@mumble ||=
Mumble::Client.new(mumble_url) do |conf|
conf.username = mumble_username
end
end
def slack_username
ENV['SLACK_USERNAME'] || 'ButtBot'
end
def notifier_url
ENV['WEBHOOK_URL']
end
def notifier
@notifier ||= Slack::Notifier.new notifier_url, username: slack_username
end
def notify message
notifier.ping message, icon_emoji: ":gremlin:"
end
def butt_channel_id
mumble.channels.values.detect{|c| c.name == mumble_channel }.channel_id
end
def butt_users
butt_channel_id = self.butt_channel_id
mumble.users.values.select{|u| u.channel_id == butt_channel_id }
end
def run
mumble.on_connected do
mumble.me.mute
mumble.me.deafen
mumble.join_channel(mumble_channel)
end
mumble.connect
last_users = []
loop do
sleep 2
next unless mumble.connected?
now_users = butt_users.map(&:name)
now_users -= [mumble_username]
joined_users = now_users - last_users
left_users = last_users - now_users
joined_users.each do |username|
notify "#{username} is back in the fight"
end
left_users.each do |username|
notify "#{username} was eliminated"
end
last_users = now_users
end
end
end
ButtBot.new.run