more modules work
This commit is contained in:
@@ -5,16 +5,17 @@ from threading import Timer
|
||||
|
||||
import requests
|
||||
from mumo_module import (commaSeperatedIntegers, MumoModule)
|
||||
from tools.Utils import find_channel_with_name, get_empty_channels
|
||||
|
||||
|
||||
# noinspection PyPep8Naming
|
||||
class autochannel(MumoModule):
|
||||
default_config = {'autochannel': (
|
||||
('servers', commaSeperatedIntegers, []),
|
||||
('spare_channel', int, 1),
|
||||
('top_games_limit', int, 10),
|
||||
('root_channel_name', str, "Random Channel"),
|
||||
('check_timer_interval', int, 5)
|
||||
('check_timer_interval', int, 5),
|
||||
('game_channels_permament', str, "")
|
||||
)
|
||||
}
|
||||
|
||||
@@ -70,37 +71,16 @@ class autochannel(MumoModule):
|
||||
pass
|
||||
|
||||
def init_channels(self, server):
|
||||
channels = server.getChannels()
|
||||
self.root = find_channel_with_name(self.root_channel_name, server, 0)
|
||||
|
||||
if not self.root:
|
||||
for cid, channel in channels.items():
|
||||
if channel.name == self.root_channel_name and channel.parent == 0:
|
||||
self.root = channel
|
||||
|
||||
if not self.root:
|
||||
new_root_cid = server.addChannel(self.root_channel_name, 0)
|
||||
self.root = server.getChannelState(new_root_cid)
|
||||
new_root_cid = server.addChannel(self.root_channel_name, 0)
|
||||
self.root = server.getChannelState(new_root_cid)
|
||||
|
||||
self.check_channel(server)
|
||||
|
||||
@staticmethod
|
||||
def get_user_for_channel(cid, server):
|
||||
users = server.getUsers()
|
||||
users_in_channel = {}
|
||||
|
||||
for uid, user in users.items():
|
||||
if user.channel == cid:
|
||||
users_in_channel[uid] = user
|
||||
|
||||
return users_in_channel
|
||||
|
||||
def check_channel(self, server):
|
||||
empty_channels = []
|
||||
channels = server.getChannels()
|
||||
|
||||
for cid, channel in channels.items():
|
||||
if channel.parent == self.root.id and len(self.get_user_for_channel(cid, server)) == 0:
|
||||
empty_channels.append(cid)
|
||||
empty_channels = get_empty_channels(server, self.root.id)
|
||||
|
||||
for cid in empty_channels[1:]:
|
||||
server.removeChannel(cid)
|
||||
|
||||
Reference in New Issue
Block a user