more modules work
This commit is contained in:
@@ -14,3 +14,6 @@ root_channel_name = Random Channel
|
|||||||
|
|
||||||
; Interval in sec between channel checks
|
; Interval in sec between channel checks
|
||||||
check_timer_interval = 5
|
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
|
import requests
|
||||||
from mumo_module import (commaSeperatedIntegers, MumoModule)
|
from mumo_module import (commaSeperatedIntegers, MumoModule)
|
||||||
|
from tools.Utils import find_channel_with_name, get_empty_channels
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyPep8Naming
|
|
||||||
class autochannel(MumoModule):
|
class autochannel(MumoModule):
|
||||||
default_config = {'autochannel': (
|
default_config = {'autochannel': (
|
||||||
('servers', commaSeperatedIntegers, []),
|
('servers', commaSeperatedIntegers, []),
|
||||||
('spare_channel', int, 1),
|
('spare_channel', int, 1),
|
||||||
('top_games_limit', int, 10),
|
('top_games_limit', int, 10),
|
||||||
('root_channel_name', str, "Random Channel"),
|
('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
|
pass
|
||||||
|
|
||||||
def init_channels(self, server):
|
def init_channels(self, server):
|
||||||
channels = server.getChannels()
|
self.root = find_channel_with_name(self.root_channel_name, server, 0)
|
||||||
|
|
||||||
if not self.root:
|
if not self.root:
|
||||||
for cid, channel in channels.items():
|
new_root_cid = server.addChannel(self.root_channel_name, 0)
|
||||||
if channel.name == self.root_channel_name and channel.parent == 0:
|
self.root = server.getChannelState(new_root_cid)
|
||||||
self.root = channel
|
|
||||||
|
|
||||||
if not self.root:
|
|
||||||
new_root_cid = server.addChannel(self.root_channel_name, 0)
|
|
||||||
self.root = server.getChannelState(new_root_cid)
|
|
||||||
|
|
||||||
self.check_channel(server)
|
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):
|
def check_channel(self, server):
|
||||||
empty_channels = []
|
empty_channels = get_empty_channels(server, self.root.id)
|
||||||
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)
|
|
||||||
|
|
||||||
for cid in empty_channels[1:]:
|
for cid in empty_channels[1:]:
|
||||||
server.removeChannel(cid)
|
server.removeChannel(cid)
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ steam_genre_regex = re.compile("Genre:</b>.*?<a.*?>(.+?)</a>")
|
|||||||
|
|
||||||
# AMAZON
|
# AMAZON
|
||||||
amazon_regex = re.compile("ama?zo?n\.(?:de|com)/.*(?:dp|gp/product)/([A-Z0-9]{10})(?:(?:/+)|$)?")
|
amazon_regex = re.compile("ama?zo?n\.(?:de|com)/.*(?:dp|gp/product)/([A-Z0-9]{10})(?:(?:/+)|$)?")
|
||||||
# TODO: Make regex more general (de|com)
|
|
||||||
|
|
||||||
# Commands
|
# Commands
|
||||||
move_regex = re.compile("^moveall (.*)$")
|
move_regex = re.compile("^moveall (.*)$")
|
||||||
@@ -121,8 +120,8 @@ class chatparser(MumoModule):
|
|||||||
t = isodate.parse_duration(v["contentDetails"]["duration"])
|
t = isodate.parse_duration(v["contentDetails"]["duration"])
|
||||||
try:
|
try:
|
||||||
rate = "%.2f %%" % (
|
rate = "%.2f %%" % (
|
||||||
(((float(v["statistics"]["dislikeCount"]) / float(
|
(((float(v["statistics"]["dislikeCount"]) / float(
|
||||||
v["statistics"]["likeCount"])) - 1.0) * -1.0) * 100.0)
|
v["statistics"]["likeCount"])) - 1.0) * -1.0) * 100.0)
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
rate = "No rating possible"
|
rate = "No rating possible"
|
||||||
self.sendMessage(server, user, message,
|
self.sendMessage(server, user, message,
|
||||||
|
|||||||
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