more modules work
This commit is contained in:
@@ -14,3 +14,6 @@ root_channel_name = Random Channel
|
||||
|
||||
; Interval in sec between channel checks
|
||||
check_timer_interval = 5
|
||||
|
||||
; Additional game channels specified with steam AppIDs, comma seperated
|
||||
game_channels_permament =
|
||||
@@ -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,12 +71,7 @@ class autochannel(MumoModule):
|
||||
pass
|
||||
|
||||
def init_channels(self, server):
|
||||
channels = server.getChannels()
|
||||
|
||||
if not self.root:
|
||||
for cid, channel in channels.items():
|
||||
if channel.name == self.root_channel_name and channel.parent == 0:
|
||||
self.root = channel
|
||||
self.root = find_channel_with_name(self.root_channel_name, server, 0)
|
||||
|
||||
if not self.root:
|
||||
new_root_cid = server.addChannel(self.root_channel_name, 0)
|
||||
@@ -83,24 +79,8 @@ class autochannel(MumoModule):
|
||||
|
||||
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)
|
||||
|
||||
@@ -23,7 +23,6 @@ steam_genre_regex = re.compile("Genre:</b>.*?<a.*?>(.+?)</a>")
|
||||
|
||||
# AMAZON
|
||||
amazon_regex = re.compile("ama?zo?n\.(?:de|com)/.*(?:dp|gp/product)/([A-Z0-9]{10})(?:(?:/+)|$)?")
|
||||
# TODO: Make regex more general (de|com)
|
||||
|
||||
# Commands
|
||||
move_regex = re.compile("^moveall (.*)$")
|
||||
|
||||
35
tools/Utils.py
Normal file
35
tools/Utils.py
Normal file
@@ -0,0 +1,35 @@
|
||||
def find_channel_with_name(name: str, server, parent: int = None):
|
||||
channels = server.getChannels()
|
||||
|
||||
for cid, channel in channels.items():
|
||||
if parent:
|
||||
if channel.name == name and channel.parent == parent:
|
||||
return channel
|
||||
else:
|
||||
if channel.name == name:
|
||||
return channel
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_empty_channels(server, parent: int = None):
|
||||
empty_channels = []
|
||||
channels = server.getChannels()
|
||||
|
||||
for cid, channel in channels.items():
|
||||
if parent:
|
||||
if channel.parent == parent and len(get_user_for_channel(cid, server)) == 0:
|
||||
empty_channels.append(cid)
|
||||
|
||||
return empty_channels
|
||||
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user