diff --git a/modules-available/autochannel.ini b/modules-available/autochannel.ini index 9038c42..5e56e25 100644 --- a/modules-available/autochannel.ini +++ b/modules-available/autochannel.ini @@ -13,4 +13,7 @@ top_games_limit = 10 root_channel_name = Random Channel ; Interval in sec between channel checks -check_timer_interval = 5 \ No newline at end of file +check_timer_interval = 5 + +; Additional game channels specified with steam AppIDs, comma seperated +game_channels_permament = \ No newline at end of file diff --git a/modules/autochannel.py b/modules/autochannel.py index 5306b84..30c407c 100644 --- a/modules/autochannel.py +++ b/modules/autochannel.py @@ -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) diff --git a/modules/chatparser.py b/modules/chatparser.py index 3d44489..5266db8 100644 --- a/modules/chatparser.py +++ b/modules/chatparser.py @@ -23,7 +23,6 @@ steam_genre_regex = re.compile("Genre:.*?(.+?)") # 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 (.*)$") @@ -121,8 +120,8 @@ class chatparser(MumoModule): t = isodate.parse_duration(v["contentDetails"]["duration"]) try: rate = "%.2f %%" % ( - (((float(v["statistics"]["dislikeCount"]) / float( - v["statistics"]["likeCount"])) - 1.0) * -1.0) * 100.0) + (((float(v["statistics"]["dislikeCount"]) / float( + v["statistics"]["likeCount"])) - 1.0) * -1.0) * 100.0) except ZeroDivisionError: rate = "No rating possible" self.sendMessage(server, user, message, diff --git a/tools/Utils.py b/tools/Utils.py new file mode 100644 index 0000000..8a6d57c --- /dev/null +++ b/tools/Utils.py @@ -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