-
Notifications
You must be signed in to change notification settings - Fork 1
/
mumble.py
executable file
·173 lines (145 loc) · 4.87 KB
/
mumble.py
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python
"""
mumble.py - Phenny/Sopel Mumble Module
Copyright 2015, Steven Humphrey
Licensed under the Eiffel Forum License 2.
To get this to work, please add the following config section to your sopel
config.
[mumble]
ip = ...
slice = /path/to/slice/file
port = ...
secret = ...
slice should be the path to the Murmur.ice file.
http://mumble.sourceforge.net/Ice
"""
import Ice
import threading, time
def setup(self):
"""Sets up ICE"""
if self.config.mumble:
slicefile = self.config.mumble.slice
icesecret = self.config.mumble.secret
else:
slicefile = self.config.mumble_slice
icesecret = self.config.mumble_secret
Ice.loadSlice('', ['-I' + Ice.getSliceDir(), slicefile ] )
prop = Ice.createProperties([])
prop.setProperty('Ice.Default.EncodingVersion', '1.0')
prop.setProperty("Ice.ImplicitContext", "Shared")
prop.setProperty("Ice.MessageSizeMax", "65535")
idd = Ice.InitializationData()
idd.properties = prop
global ice
ice = Ice.initialize(idd)
ice.getImplicitContext().put("secret", icesecret.encode("utf-8"))
global Murmur
import Murmur
## Set up threaded checker
print "set up and now starting timer thread"
t = threading.Timer(20.0, mumble_auto_loop, [self])
t.start()
def mumble_auto_loop(bot):
"""Poll the mumble server every X seconds for new users"""
loop_timer = 30
if bot.config.mumble:
if bot.config.mumble.timer and bot.config.mumble.timer > 0:
loop_timer = bot.config.mumble.timer
recip = bot.config.mumble.channels.split(',')
else:
recip = bot.config.mumble_channels
if not recip:
return
server = get_server(bot)
users = server.getUsers()
## Populate an initial list of usernames and report that to channel
## when bot joins
usernames = []
for key in users:
name = users[key].name
usernames.append(name)
if len(usernames) == 1:
for r in recip:
bot.msg(r, ", ".join(usernames) + " is currently on mumble")
elif len(usernames) > 0:
for r in recip:
bot.msg(r, ", ".join(usernames) + " are currently on mumble")
## Loop forever, every 30s, checking for new users
## If there are new users, tell the channel about them
while(True):
time.sleep(loop_timer)
server = get_server(bot)
users = server.getUsers()
currentusers = []
joined_users = []
parted_users = []
for uk in users:
currentusers.append(users[uk].name)
for name in currentusers:
try:
usernames.index(name)
except:
joined_users.append(name)
usernames.append(name)
for name in usernames:
try:
currentusers.index(name)
except:
parted_users.append(name)
usernames.remove(name)
if len(parted_users) > 1 and len(usernames) == 0:
for r in recip:
bot.msg(r, + "There are no more users connected to mumble")
if joined_users:
message = ", ".join(joined_users)
if len(joined_users) > 1:
message = message + " have joined mumble"
else:
message = message + " has joined mumble"
for r in recip:
bot.msg(r, message)
def get_server(bot):
"""Returns the mumble server"""
if bot.config.mumble:
mumble_ip = bot.config.mumble.ip
mumble_port = bot.config.mumble.port
else:
mumble_ip = bot.config.mumble_ip
mumble_port = bot.config.mumble_port or "6502"
if not mumble_ip:
bot.say("mumble is not configured")
return
connstring = "Meta:tcp -h %s -p %s" % (mumble_ip, mumble_port)
global ice
proxy = ice.stringToProxy( connstring.encode("utf-8") )
global Murmur
meta = Murmur.MetaPrx.checkedCast(proxy)
server = meta.getServer(1)
return server
def mumble_send(bot, input):
"""Sends a message to mumble server"""
server = get_server(bot)
message = input.group(2)
if message:
server.sendMessageChannel(0, False, message)
bot.say("Message sent to first channel tree")
else:
bot.say("usage: .mumblesend some text")
mumble_send.commands = ['mumblesend']
mumble_send.priority = 'medium'
def mumble_users(phenny, input):
"""Shows the users connected to mumble"""
server = get_server(phenny)
users = server.getUsers()
if len(users) == 0:
phenny.say("No users connected to mumble")
return
names = []
for key in users:
name = users[key].name
names.append(name)
phenny.say("Mumble users: " + ", ".join(names))
mumble_users.commands = ['mumble']
mumble_users.priority = 'medium'
if __name__ == '__main__':
print __doc__.strip()