diff --git a/.gitignore b/.gitignore index 38a983f..64e6b50 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ levels.db* *.log govno_rutony.py /node_modules/ +/http \ No newline at end of file diff --git a/gui.py b/gui.py index 4cebfc5..d3ace48 100644 --- a/gui.py +++ b/gui.py @@ -226,9 +226,9 @@ def clear_changes(): main_tuple = [] for item, i_value in self.main_class.loaded_modules[split_keys[0]]['config'][split_keys[1]].iteritems(): if i_value: - main_tuple.append((item, i_value)) + main_tuple.append((item.decode('utf-8'), i_value.decode('utf-8'))) else: - main_tuple.append((item,)) + main_tuple.append((item.decode('utf-8'),)) if compare_2d_lists(value, main_tuple): clear_changes() @@ -821,7 +821,7 @@ def set_viewers(self, module, viewers): if isinstance(viewers, int): viewers = str(viewers) if len(viewers) >= 5: - viewers = '{0}k'.format(viewers[:2]) + viewers = '{0}k'.format(viewers[:-3]) self.chats[module]['label'].SetLabel(str(viewers)) self.Layout() @@ -859,14 +859,17 @@ def __init__(self, parent, title, url, **kwargs): vbox.Add(self.status_frame, 0, wx.EXPAND) if self.gui_settings['show_browser']: vbox.Add(chromectrl.ChromeCtrl(self, useTimer=False, url=str(url), hasNavBar=False), 1, wx.EXPAND) - else: - self.Fit() # Set events self.Bind(wx.EVT_CLOSE, self.on_close) # Show window after creation self.SetSizer(vbox) + + if not self.gui_settings['show_browser']: + self.Layout() + self.Fit() + self.Show(True) # Show update dialog if new version found diff --git a/modules/chat/goodgame.py b/modules/chat/goodgame.py index e5b992a..715e9b1 100644 --- a/modules/chat/goodgame.py +++ b/modules/chat/goodgame.py @@ -10,7 +10,7 @@ import logging from collections import OrderedDict from modules.helper.parser import load_from_config_file -from modules.helper.system import system_message, translate_key, remove_message_by_id, EMOTE_FORMAT +from modules.helper.system import system_message, translate_key, remove_message_by_id, EMOTE_FORMAT, NA_MESSAGE from modules.helper.module import ChatModule from ws4py.client.threadedclient import WebSocketClient from gui import MODULE_KEY @@ -347,7 +347,11 @@ def get_viewers(self): try: request = requests.get(streams_url) if request.status_code == 200: - return request.json().get('player_viewers') + json_data = request.json() + if json_data['status'] == 'Live': + return request.json().get('player_viewers') + else: + return NA_MESSAGE else: raise Exception("Not successful status code: {0}".format(request.status_code)) except Exception as exc: diff --git a/modules/chat/sc2tv.py b/modules/chat/sc2tv.py index e2b2117..5e555d6 100644 --- a/modules/chat/sc2tv.py +++ b/modules/chat/sc2tv.py @@ -318,12 +318,25 @@ def load_module(self, *args, **kwargs): self.fs_thread = fs fs.start() - @staticmethod - def get_viewers(ws): - request = [ - '/chat/channel/list', - { - 'channel': 'stream/{0}'.format(str(ws.channel_id)) - } - ] - ws.fs_send(request) + def get_viewers(self, ws): + user_data = {'name': ws.channel_name} + status_data = {'slug': ws.channel_name} + request = ['/chat/channel/list', {'channel': 'stream/{0}'.format(str(ws.channel_id))}] + + try: + user_request = requests.post('http://funstream.tv/api/user', timeout=5, data=user_data) + if user_request.status_code == 200: + status_data['slug'] = user_request.json()['slug'] + except requests.ConnectionError: + log.error("Unable to get smiles") + + try: + status_request = requests.post('http://funstream.tv/api/stream', timeout=5, data=status_data) + if status_request.status_code == 200: + if status_request.json()['online']: + ws.fs_send(request) + else: + self.set_viewers('N/A') + + except requests.ConnectionError: + log.error("Unable to get smiles") diff --git a/modules/chat/twitch.py b/modules/chat/twitch.py index a5dd3b5..aec1b67 100644 --- a/modules/chat/twitch.py +++ b/modules/chat/twitch.py @@ -11,7 +11,7 @@ import time from modules.helper.parser import load_from_config_file from modules.helper.module import ChatModule -from modules.helper.system import system_message, translate_key, remove_message_by_user, EMOTE_FORMAT +from modules.helper.system import system_message, translate_key, remove_message_by_user, EMOTE_FORMAT, NA_MESSAGE from gui import MODULE_KEY logging.getLogger('irc').setLevel(logging.ERROR) @@ -452,7 +452,10 @@ def get_viewers(self): try: request = requests.get(streams_url, headers=headers) if request.status_code == 200: - return request.json()['stream'].get('viewers') + json_data = request.json() + if json_data['stream']: + return request.json()['stream'].get('viewers', NA_MESSAGE) + return NA_MESSAGE else: raise Exception("Not successful status code: {0}".format(request.status_code)) except Exception as exc: diff --git a/modules/helper/system.py b/modules/helper/system.py index 441d1a8..53c3f38 100644 --- a/modules/helper/system.py +++ b/modules/helper/system.py @@ -13,6 +13,8 @@ SOURCE_USER = 'System' SOURCE_ICON = '/img/sources/lalka_cup.png' +NA_MESSAGE = 'N/A' + IGNORED_TYPES = ['command', 'system_message'] TRANSLATIONS = {} SPLIT_TRANSLATION = '=' diff --git a/modules/messaging/c2b.py b/modules/messaging/c2b.py index df190d2..3d5601f 100644 --- a/modules/messaging/c2b.py +++ b/modules/messaging/c2b.py @@ -68,8 +68,9 @@ def process_message(self, message, queue, **kwargs): return message for item, replace in self._conf_params['config']['config'].iteritems(): + item = item.decode('utf-8') if item in message['text']: - replace_word = random.choice(replace.split('/')) + replace_word = random.choice(replace.split('/')).decode('utf-8') if message['source'] == 'tw': message['emotes'] = twitch_replace_indexes(item, message['text'], len(item), len(replace_word), diff --git a/modules/messaging/webchat.py b/modules/messaging/webchat.py index e310691..d6358f3 100644 --- a/modules/messaging/webchat.py +++ b/modules/messaging/webchat.py @@ -18,6 +18,7 @@ from gui import MODULE_KEY from main import PYTHON_FOLDER, CONF_FOLDER +DEFAULT_STYLE = 'default' DEFAULT_PRIORITY = 9001 HISTORY_SIZE = 20 HISTORY_TYPES = ['system_message', 'message'] @@ -388,12 +389,11 @@ def start_webserver(self): @staticmethod def get_style_path(style): - fallback_style = 'czt' path = os.path.abspath(os.path.join(HTTP_FOLDER, style)) if os.path.exists(path): style_location = path else: - style_location = os.path.join(HTTP_FOLDER, fallback_style) + style_location = os.path.join(HTTP_FOLDER, DEFAULT_STYLE) return style_location def reload_chat(self): diff --git a/translations/en/main.key b/translations/en/main.key index 0384c3e..e9226e5 100644 --- a/translations/en/main.key +++ b/translations/en/main.key @@ -7,6 +7,7 @@ menu.reload = Reload WebChat *.list_remove = Remove *.descr_explain = Click on an item to view description of the item *.description = No description +*.show_pm = Mark messages for channel settings = Settings settings.main = Main Settings @@ -17,6 +18,8 @@ main = Main main.gui = GUI Settings main.gui.show_hidden = Show hidden items main.gui.gui = Is GUI enabled +main.gui.show_browser = Show browser window +main.gui.show_counters = Show channel view counters main.gui.on_top = Show window on top main.gui.very_big_parameter_with_really_big_name_and_a_lot_of_not_needed_stuff = Just a big parameter for test main.gui.reload = Reload WebChat diff --git a/translations/en/webchat.key b/translations/en/webchat.key index 810c058..faf2327 100644 --- a/translations/en/webchat.key +++ b/translations/en/webchat.key @@ -7,4 +7,11 @@ webchat.server.port = Port webchat.style = Available styles webchat.style.list_box = webchat.style_settings = Style Settings -webchat.style_settings.font_size = Font Size (pt) \ No newline at end of file +webchat.style_settings.font_size = Font Size (pt) +webchat.style_settings.show_system_msg = Show system messages +webchat.style_settings.remove_message = Replace deleted Messages +webchat.style_settings.remove_text = Replaced Message text +webchat.style_settings.timer = Message clear timer +webchat.style_settings.message_opacity = Background opacity +webchat.style_settings.smile_size = Smile Size (px) +webchat.style_settings.badge_size = Badge Size (px) \ No newline at end of file diff --git a/translations/ru/main.key b/translations/ru/main.key index 28b38df..78619d7 100644 --- a/translations/ru/main.key +++ b/translations/ru/main.key @@ -7,6 +7,7 @@ menu.reload = Перезагрузить Чат *.list_remove = Удалить *.descr_explain = Выберите вещь, описание которой вы хотите прочитать. *.description = Описание не предоставлено +*.show_pm = Выделять личные сообщения settings = Настройки settings.main = Главные Настройки @@ -17,6 +18,8 @@ main = Главные Настройки main.gui = Настройки Интерфейса main.gui.show_hidden = Показвать скрытые вещи main.gui.gui = Интерфейс Включен +main.gui.show_browser = Показывать окно браузера +main.gui.show_counters = Показывать счетчики зрителей main.gui.on_top = Окно поверх всех main.gui.very_big_parameter_with_really_big_name_and_a_lot_of_not_needed_stuff = Тестовый Параметр main.gui.reload = Перезагрузить ВебЧат diff --git a/translations/ru/webchat.key b/translations/ru/webchat.key index 14e5dd4..34065c0 100644 --- a/translations/ru/webchat.key +++ b/translations/ru/webchat.key @@ -8,4 +8,10 @@ webchat.style = Доступные Стили webchat.style.list_box = webchat.style_settings = Настройки Стиля webchat.style_settings.font_size = Размер шрифта - +webchat.style_settings.show_system_msg = Показывать системные сообщения +webchat.style_settings.remove_message = Заменять удалённые сообщения +webchat.style_settings.remove_text = Текст замещенного сообщения +webchat.style_settings.timer = Срок жизни сообщения +webchat.style_settings.message_opacity = Прозрачность фона +webchat.style_settings.smile_size = Размер смайлов (px) +webchat.style_settings.badge_size = Размер бейджей (px)