Last active
December 9, 2016 01:38
-
-
Save AmauryCarrade/84b9b82c97cacf5c0248ff1dd3bd2abd to your computer and use it in GitHub Desktop.
Mumble dump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"channels": [ | |
{ | |
"name": "Zcraft", | |
"path": [ | |
"Zcraft" | |
], | |
"position": 0, | |
"users": [ | |
{ | |
"deaf": false, | |
"mute": false, | |
"name": "Amaury", | |
"prioritySpeaker": false, | |
"recording": false | |
}, | |
{ | |
"deaf": false, | |
"mute": false, | |
"name": "Ichi", | |
"prioritySpeaker": false, | |
"recording": false | |
}, | |
{ | |
"deaf": false, | |
"mute": false, | |
"name": "ordstir", | |
"prioritySpeaker": false, | |
"recording": false | |
}, | |
{ | |
"deaf": true, | |
"mute": true, | |
"name": "Tyrano", | |
"prioritySpeaker": false, | |
"recording": false | |
} | |
] | |
}, | |
{ | |
"name": "Vaycoin", | |
"path": [ | |
"Zcraft", "Taverne", "Vaycoin" | |
], | |
"position": 0, | |
"users": [ | |
{ | |
"deaf": false, | |
"mute": false, | |
"name": "Vayquor", | |
"prioritySpeaker": false, | |
"recording": false | |
} | |
] | |
} | |
], | |
"current_users": 1, | |
"max_users": "100", | |
"updated": 1478174416, | |
"users": [ | |
"Amaury", "Ichi", "ordstir", "Tyrano", "Vayquor" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function # to use print('txt', file=f) | |
import mice | |
import time | |
import json | |
server = mice.m.getServer(1) | |
channels = server.getChannels() | |
users = server.getUsers() | |
server_name = server.getConf('registername') | |
max_users = server.getConf("users") | |
if not max_users: | |
max_users = '100' | |
users_names = [user.name for id, user in users.iteritems()] | |
users_names.sort(key=lambda username: username.lower()) | |
users_channels = {} | |
for id, user in users.iteritems(): | |
user_exposed = { | |
'name': user.name, | |
'mute': user.mute or user.selfMute, | |
'deaf': user.deaf or user.selfDeaf, | |
'recording': user.recording, | |
'prioritySpeaker': user.prioritySpeaker | |
} | |
if not user.channel in users_channels: | |
users_channels[user.channel] = [user_exposed] | |
else: | |
users_channels[user.channel].append(user_exposed) | |
for id in users_channels: | |
users_channels[id].sort(key=lambda user: user['name'].lower()) | |
users_channels_dump = [] | |
for channel_id, users in users_channels.iteritems(): | |
channel_name = channels[channel_id].name if channel_id != 0 else server_name | |
channel_path = [channel_name] | |
curr_channel_id = channel_id | |
while curr_channel_id: | |
if not curr_channel_id in channels: | |
break | |
curr_channel_id = channels[curr_channel_id].parent | |
channel_path.append(channels[curr_channel_id].name if curr_channel_id != 0 else server_name) | |
channel_path.reverse() | |
if channel_name: | |
users_channels_dump.append({ | |
'name': channel_name, | |
'path': channel_path, | |
'position': channels[channel_id].position, | |
'users': users | |
}) | |
users_channels_dump.sort(key=lambda chan: chan['position']) | |
dump = { | |
'updated': int(time.time()), | |
'current_users': len(users), | |
'max_users': max_users, | |
'users': users_names, | |
'channels': users_channels_dump | |
} | |
with open('mumble_state.json', 'w') as f: | |
print(json.dumps(dump), file=f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment