diff --git a/README.md b/README.md index 2a5b83b..3bafe54 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ # multichat_python + +Thanks to ftpud for fixing IE compatibility diff --git a/gui.py b/gui.py index 3fe6dde..d5f53eb 100644 --- a/gui.py +++ b/gui.py @@ -1,13 +1,9 @@ -from pprint import pprint import threading import wx import os -import ConfigParser import re from modules.helpers.parser import FlagConfigParser from wx import html2 -# import signal -# import thread # ToDO: Support customization of borders/spacings # ToDO: Exit by cancel button @@ -51,14 +47,12 @@ def load_translations(settings, language): conf_file = 'translations.cfg' config = FlagConfigParser(allow_no_value=True) config.read(os.path.join(settings['conf'], conf_file)) - # print config if not config.has_section(language): print "Warning, have not found language ", language language = 'english' for param, value in config.items(language): - # print param, value translations[param] = value @@ -154,8 +148,6 @@ def __init__(self, parent, configs, on_top=False, title=translate_language("menu self.configs = configs self.gui_settings = {} - # pprint(self.main_class.modules_configs) - self.main_grid = wx.BoxSizer(wx.VERTICAL) if on_top: @@ -165,9 +157,6 @@ def __init__(self, parent, configs, on_top=False, title=translate_language("menu self.SetSizer(self.main_grid) self.Layout() - # self.main_grid.Fit(self) - # print config_size_max - # self.SetSize(config_size_max) self.Show(True) def on_exit(self, event): @@ -230,11 +219,9 @@ def button_clicked(self, event): print ids[event.GetId()] module_groups = ids[event.GetId()].split('.') if module_groups[1] == 'apply_button': - # print "Got Apply Event" self.write_config(module_groups) self.on_close(event) elif module_groups[1] == 'cancel_button': - # print "Got Cancel Event" event.Skip() elif 'list_add' in module_groups: self.add_list_item(module_groups) @@ -279,7 +266,6 @@ def write_config(self, module_groups): if isinstance(window, wx.CheckBox): parser.set(section, param, str(window.IsChecked()).lower()) elif isinstance(window, wx.TextCtrl): - # print "Got TextCtrl, YAY", str(window.GetValue()) parser.set(section, param, window.GetValue().encode('utf-8')) with open(conf_file, 'w') as config_file: @@ -290,19 +276,13 @@ def create_and_load_config(self, main_panel): notebook_text = translate_language('config') notebook = wx.Notebook(main_panel, id=notebook_id, style=wx.NB_TOP, name=notebook_text) - # self.main_class.modules_configs = [self.main_class.modules_configs[0]] - for config in self.main_class.modules_configs: panel_id = wx.Window_NewControlId() config_name = config.keys()[0] panel_name = translate_language(config_name) panel = wx.Panel(notebook, id=panel_id) - # panel.SetScrollbars(5, 5, 10, 10) - - # print config[config_name] panel_sizer = self.load_config(config_params=config[config_name], panel=panel) panel.SetSizer(panel_sizer) - # panel.Fit() notebook.AddPage(panel, panel_name) @@ -310,7 +290,6 @@ def create_and_load_config(self, main_panel): def load_config(self, config_params=None, panel=None, **kwargs): conf_params = config_params - # print conf_params sizer = wx.BoxSizer(wx.VERTICAL) config = FlagConfigParser(allow_no_value=True) @@ -324,16 +303,13 @@ def load_config(self, config_params=None, panel=None, **kwargs): module_prefix = conf_params['filename'] sections = config._sections - # print sections for item in sections: # Check if it is GUI settings item_split = item.split('_') if len(item_split) > 1 and item_split[-1] == 'gui': - # print "found GUI settings ", '.'.join([module_prefix, '_'.join(item_split[:-1])]) for gui_item in config.get(item, 'for').split(','): gui_item = gui_item.strip() gui_item = self.module_key.join([module_prefix, gui_item]) - # print gui_item self.gui_settings[gui_item] = {} for param, value in config.get_items(item): if param != 'for': @@ -343,8 +319,6 @@ def load_config(self, config_params=None, panel=None, **kwargs): view = None gui_module = self.module_key.join([module_prefix, item]) if gui_module in self.gui_settings: - # print "Found Settings for this section", item - # print self.gui_settings[item] view = self.gui_settings[gui_module].get('view', None) # Create header for section @@ -383,7 +357,6 @@ def load_config(self, config_params=None, panel=None, **kwargs): list_box_name = '.'.join([module_prefix, item, 'list_box']) list_box_id = id_change_to_new(list_box_name) ids[list_box_id] = list_box_name - # list_box_text = translate_language(ids[list_box_id]) list_box = wx.ListBox(f_panel, id=list_box_id, style=wx.LB_EXTENDED) values = [] @@ -402,14 +375,12 @@ def load_config(self, config_params=None, panel=None, **kwargs): for param, value, flags in config.items_with_flags(item): item_sizer = wx.BoxSizer(wx.HORIZONTAL) rotate = False - # print param, flags # Creating item settings if flags: module_name = self.keyword.join(['.'.join([module_prefix, item, param]), self.flag_keyword.join(flags)]) else: module_name = '.'.join([module_prefix, item, param]) - # print module_name if 'hidden' in flags: if self.show_hidden: @@ -424,8 +395,6 @@ def load_config(self, config_params=None, panel=None, **kwargs): text_text = translate_language(module_name) text = wx.StaticText(f_panel, wx.ID_ANY, text_text, style=wx.ALIGN_RIGHT) - # text.SetBackgroundColour('red') - # text.SetMinSize(fix_sizes(text.GetSize(), self.labelMinSize)) # Creating item objects if value is not None: @@ -435,7 +404,6 @@ def load_config(self, config_params=None, panel=None, **kwargs): if module_name == 'config.gui.show_hidden' and value == 'true': self.show_hidden = True box = wx.CheckBox(f_panel, id=module_id) - # self.main_class.Bind(wx.EVT_CHECKBOX, self.check_box_clicked, id=module_id) if value == 'true': box.SetValue(True) else: @@ -443,7 +411,6 @@ def load_config(self, config_params=None, panel=None, **kwargs): # If not - it's text control else: box = wx.TextCtrl(f_panel, id=module_id, value=value.decode('utf-8')) - # box.AppendText(value) # If item doesn't have any values it's a button else: @@ -475,8 +442,6 @@ def load_config(self, config_params=None, panel=None, **kwargs): self.main_class.Bind(wx.EVT_BUTTON, self.button_clicked, id=button_id) buttons_sizer.Add(apply_button, 0, wx.ALIGN_RIGHT) - # buttons_sizer.AddSpacer(self.flex_horizontal_gap*2) - button_name = '.'.join([module_prefix, 'cancel_button']) button_id = id_change_to_new(button_name) ids[button_id] = button_name @@ -505,25 +470,19 @@ def __init__(self, parent, title, url, **kwds): print "Application is on top" styles = styles | wx.STAY_ON_TOP - # print styles self.SetWindowStyle(styles) vbox = wx.BoxSizer(wx.VERTICAL) toolbar = MainMenuToolBar(self, main_class=self) self.main_window = html2.WebView.New(parent=self, url=url, name='LalkaWebViewGui') - # self.main_window - # self.main_window = html2.WebView.New(parent=self, url=url, name='LalkaWebViewGui', size=(300, 600)) vbox.Add(toolbar, 0, wx.EXPAND) vbox.Add(self.main_window, 1, wx.EXPAND) self.Bind(wx.EVT_LEFT_DOWN, self.on_right_down, self.main_window) self.Bind(wx.EVT_CLOSE, self.on_exit) - # self.Bind(wx.EVT_TOOL, self.on_settings, id=get_id_from_name('settings')) - # self.Bind(wx.EVT_TOOL, self.on_about, id=ids['about']) - # vbox.Fit(self) self.SetSizer(vbox) self.Show(True) @@ -538,8 +497,6 @@ def on_right_down(self, event): print "RClick" def on_settings(self, event): - # print event - # print wx.STAY_ON_TOP, self.GetWindowStyle() if not self.settingWindow: if wx.STAY_ON_TOP & self.GetWindowStyle() == wx.STAY_ON_TOP: self.settingWindow = SettingsWindow(self, self.main_config, on_top=True, diff --git a/http/index.html b/http/index.html index 6cc46cb..a257d0f 100644 --- a/http/index.html +++ b/http/index.html @@ -1,10 +1,12 @@ -Lalkachat - - - + LalkaChat + + + + +
- \ No newline at end of file + diff --git a/main.py b/main.py index 388c113..bb618f7 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ import os import ConfigParser -import importlib +import imp import Queue import messaging import gui @@ -14,7 +14,7 @@ def init(): loaded_modules = {} gui_settings = {} - python_folder = os.path.dirname(os.path.abspath(__file__)) + python_folder = os.path.dirname(os.path.abspath('__file__')) conf_folder = os.path.join(python_folder, "conf") module_folder = os.path.join(python_folder, "modules") @@ -79,8 +79,6 @@ def init(): loaded_module_config += msg.modules_configs - # print loaded_module_config - print "Loading Chats Configuration File" module_tag = "chats" module_import_folder = "modules" @@ -99,7 +97,9 @@ def init(): # Class should be named as in config # Also passing core folder to module so it can load it's own # configuration correctly - tmp = importlib.import_module(module_import_folder + '.' + module[0]) + file_path = os.path.join(main_config['python'], module_import_folder, '{0}.py'.format(module[0])) + + tmp = imp.load_source(module[0], file_path) class_name = getattr(tmp, module[0]) loaded_modules[module[0]] = class_name(queue, python_folder) loaded_module_config.insert(module_id, {module[0]: loaded_modules[module[0]].conf_params}) @@ -114,14 +114,12 @@ def init(): print console if console == "exit": print "Exiting now!" - # exit() thread.interrupt_main() else: print "Incorrect Command" except (KeyboardInterrupt, SystemExit): print "Exiting now!" thread.interrupt_main() - # exit() except Exception as exc: print exc diff --git a/messaging.py b/messaging.py index fb9e3c8..a48dab0 100644 --- a/messaging.py +++ b/messaging.py @@ -3,7 +3,7 @@ import os import ConfigParser import threading -import importlib +import imp import codecs import sys @@ -15,7 +15,6 @@ def __init__(self, queue): self.modules = [] self.modules_configs = [] self.daemon = True - # self.modules = {} self.msg_counter = 0 print "Loading configuration file for messaging" @@ -33,9 +32,11 @@ def __init__(self, queue): # We load the module, and then we initalize it. # When writing your modules you should have class with the # same name as module name - tmp = importlib.import_module(module_tag + '.' + module[0]) + join_path = [python_folder] + module_tag.split('.') + ['{0}.py'.format(module[0])] + file_path = os.path.join(*join_path) + + tmp = imp.load_source(module[0], file_path) init = getattr(tmp, module[0]) - # self.modules[module[0]] = init(conf_folder) class_module = init(conf_folder) self.modules.append(class_module) self.modules_configs.append({module[0]: class_module.conf_params}) @@ -61,11 +62,6 @@ def msg_process(self, message): except Exception as exc: print exc - # if message is not None: - # print type(message['text']) - # print type(message['text'].encode('utf-8').decode('utf-8')) - # print "[%s] %s: %s" % (message['source'], message['user'], message['text']) - def run(self): while True: UTF8Writer = codecs.getwriter('utf8') diff --git a/modules/goodgame.py b/modules/goodgame.py index aa1c234..bbd458f 100644 --- a/modules/goodgame.py +++ b/modules/goodgame.py @@ -1,7 +1,6 @@ import json import threading import os -import ConfigParser import requests import Queue import re @@ -133,7 +132,6 @@ def __init__(self, queue, address, id, nick): self.smiles = [] def run(self): - # Get the fucking smiles try: smile_request = requests.get("http://api2.goodgame.ru/smiles") next_page = smile_request.json()['_links']['first']['href'] @@ -188,9 +186,7 @@ def __init__(self, queue, python_folder): try: request = requests.get("http://api2.goodgame.ru/streams/"+ch_id) if request.status_code == 200: - # print type(request.json()) channel_name = request.json()['channel']['key'] - # print request.json() except: print "Issue with goodgame" @@ -198,16 +194,14 @@ def __init__(self, queue, python_folder): try: request = requests.get("http://api2.goodgame.ru/streams/"+channel_name) if request.status_code == 200: - # print type(request.json()) ch_id = request.json()['channel']['id'] - # print request.json() except: print "Issue with goodgame" - # If any of the value are non-existent then exit the programm with error. + # If any of the value are non-existent then exit the program with error. if (address is None) or (ch_id is None): print "Config for goodgame is not correct!" exit() - # Creating new thread with queue in place for messaging tranfers + # Creating new thread with queue in place for messaging transfers gg = ggThread(queue, address, ch_id, channel_name) gg.start() diff --git a/modules/helpers/parser.py b/modules/helpers/parser.py index f43f585..8090dfc 100644 --- a/modules/helpers/parser.py +++ b/modules/helpers/parser.py @@ -14,7 +14,6 @@ def items_with_flags(self, section): items = self.items(section) for param, value in items: split_param = param.split(self.keyword) - # print split_param if len(split_param) > 1: yield split_param[0], value, split_param[1].split(self.flag_keyword) else: diff --git a/modules/messaging/blacklist.py b/modules/messaging/blacklist.py index 7501aa3..82d4264 100644 --- a/modules/messaging/blacklist.py +++ b/modules/messaging/blacklist.py @@ -56,7 +56,6 @@ def __init__(self, conf_folder): def get_message(self, message, queue): if message is None: - # print "Blackist recieved no message" return else: user = self.process_user(message) diff --git a/modules/messaging/c2b.py b/modules/messaging/c2b.py index c331f6d..0ae5b59 100644 --- a/modules/messaging/c2b.py +++ b/modules/messaging/c2b.py @@ -1,7 +1,6 @@ # This Python file uses the following encoding: utf-8 # -*- coding: utf-8 -*- import os -import ConfigParser import random import re from modules.helpers.parser import FlagConfigParser @@ -33,7 +32,6 @@ def get_message(self, message, queue): # Replacing the message if needed. # Please do the needful if message is None: - # print "C2B recieved empty message" return else: for replace in self.f_items: diff --git a/modules/messaging/df.py b/modules/messaging/df.py index 97b5c06..4598b53 100644 --- a/modules/messaging/df.py +++ b/modules/messaging/df.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- import re import os -import ConfigParser from modules.helpers.parser import FlagConfigParser @@ -40,24 +39,22 @@ def __init__(self, conf_folder): comp = [prof[0].capitalize(), self.symbol + prof[1].decode('utf-8')] self.prof.append(comp) - def write_to_tile(self, message): + def write_to_file(self, message): with open(self.file, 'r') as f: for line in f.readlines(): if message['user'] == line.split(',')[0]: return - text = "%s,%s\n" %(message['user'], message['text']) + text = "{user},{text}\n".format(message['user'], message['text']) with open(self.file, 'a') as f: f.write(text) def get_message(self, message, queue): if message is None: - # print "df received empty message" return else: for regexp in self.prof: if re.search(regexp[1], message['text']): - # print "Got Hit %s" % regexp[0] comp = {'user': message['user'], 'text': regexp[0]} - self.write_to_tile(comp) + self.write_to_file(comp) break return message diff --git a/modules/messaging/levels.py b/modules/messaging/levels.py index 7b6d8ef..6a2f174 100644 --- a/modules/messaging/levels.py +++ b/modules/messaging/levels.py @@ -1,7 +1,6 @@ # This Python file uses the following encoding: utf-8 # -*- coding: utf-8 -*- import os -import ConfigParser import random import sqlite3 import math @@ -60,7 +59,6 @@ def __init__(self, conf_folder): self.db = None # Load levels - if not os.path.exists(os.path.join(conf_folder, self.filename)): print "Levels.xml not found, exiting" exit() @@ -77,13 +75,9 @@ def __init__(self, conf_folder): if self.experience == 'static': level_exp = eval('self.exp_for_level * level_c') level_c += 1 - # print level_exp elif self.experience == 'geometrical': - lvl_old = level_exp level_exp = math.floor(eval('self.exp_for_level * (pow(level_c, 1.8)/2.0)')) level_c += 1 - # print level_exp - lvl_old - # print level_exp elif self.experience == 'random': level_exp = eval('self.exp_for_level * level_c') level_c += 1 @@ -141,7 +135,6 @@ def set_level(self, user, queue): def get_message(self, message, queue): if message is None: - # print "levels recieved empty message" return else: message['s_levels'] = [] diff --git a/modules/messaging/logger.py b/modules/messaging/logger.py index de141c8..d432395 100644 --- a/modules/messaging/logger.py +++ b/modules/messaging/logger.py @@ -1,7 +1,6 @@ # This Python file uses the following encoding: utf-8 # -*- coding: utf-8 -*- import os -import ConfigParser import datetime from modules.helpers.parser import FlagConfigParser @@ -38,7 +37,6 @@ def __init__(self, conf_folder): def get_message(self, message, queue): if message is None: - # print "Logger recieved empty message" return else: with open('{0}.txt'.format( diff --git a/modules/messaging/mentions.py b/modules/messaging/mentions.py index 58ade80..d7efea8 100644 --- a/modules/messaging/mentions.py +++ b/modules/messaging/mentions.py @@ -1,10 +1,10 @@ # This Python file uses the following encoding: utf-8 # -*- coding: utf-8 -*- import os -import ConfigParser import re from modules.helpers.parser import FlagConfigParser + class mentions(): def __init__(self, conf_folder): # Creating filter and replace strings. @@ -41,7 +41,6 @@ def get_message(self, message, queue): # Replacing the message if needed. # Please do the needful if message is None: - # print "C2B recieved empty message" return else: for mention in self.mentions: diff --git a/modules/messaging/webchat.py b/modules/messaging/webchat.py index 6f59eca..41617a9 100644 --- a/modules/messaging/webchat.py +++ b/modules/messaging/webchat.py @@ -1,4 +1,3 @@ -import ConfigParser import os import threading import json @@ -93,9 +92,6 @@ def get_history(self): class HttpRoot(object): @cherrypy.expose - # @cherrypy.tools.response_headers([("Expires", '-1')]) - # @cherrypy.tools.response_headers([("Pragma", "no-cache")]) - # @cherrypy.tools.response_headers([("Cache-Control", "private, max-age=0, no-cache, no-store, must-revalidate")]) def index(self): cherrypy.response.headers["Expires"] = -1 cherrypy.response.headers["Pragma"] = "no-cache" @@ -109,7 +105,7 @@ def ws(self): class SocketThread(threading.Thread): - def __init__(self, host, port, root_folder): + def __init__(self, host, port, root_folder, **kwargs): super(self.__class__, self).__init__() self.daemon = True self.host = host @@ -133,9 +129,6 @@ def run(self): 'tools.staticdir.dir': os.path.join(http_folder, 'css')}, '/img': {'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(http_folder, 'img')}}) - # '/': {'tools.staticdir.on': True, - # 'tools.staticdir.dir': http_folder, - # 'tools.staticdir.index': "index.html"}}) class webchat(): diff --git a/modules/sc2tv.py b/modules/sc2tv.py index e8b650f..764e187 100644 --- a/modules/sc2tv.py +++ b/modules/sc2tv.py @@ -4,7 +4,6 @@ import re import requests import os -import ConfigParser from ws4py.client.threadedclient import WebSocketClient from modules.helpers.parser import FlagConfigParser @@ -24,10 +23,10 @@ def __init__(self, ws, queue, nick, protocols=None, smiles=[]): # requests in "proper" format: # # 42Iterator["command",{"params":"param"}] - #ex: 420["/chat/join",{'channel':"stream/30000"} - #ex: 421["/chat/join",{'channel':"stream/30000"} - #ex: 429["/chat/join",{'channel':"stream/30000"} - #ex: 4210["/chat/join",{'channel':"stream/30000"} + # ex: 420["/chat/join",{'channel':"stream/30000"} + # ex: 421["/chat/join",{'channel':"stream/30000"} + # ex: 429["/chat/join",{'channel':"stream/30000"} + # ex: 4210["/chat/join",{'channel':"stream/30000"} # # Also, funstream API send duplicates of the messages # so we have to ignore the duplicates. diff --git a/modules/twitch.py b/modules/twitch.py index b2d65e1..318706f 100644 --- a/modules/twitch.py +++ b/modules/twitch.py @@ -2,7 +2,6 @@ import threading import os import re -import ConfigParser import random import requests from modules.helpers.parser import FlagConfigParser @@ -40,7 +39,6 @@ def on_pubmsg(self, connection, event): # Also, there is slight problem with some users, they dont have # the display-name tag, so we have to check their "real" username # and capitalize it because twitch does so, so we do the same. - # print event comp = {'source': self.source} badges = [] emotes = [] @@ -131,8 +129,6 @@ def run(self): ircClient = IRC(self.queue, self.channel, self.badges, bttv_smiles) ircClient.connect(self.host, self.port, self.nickname) ircClient.start() - # print dir(IRCCat) - # irc.connect() class twitch: @@ -170,9 +166,7 @@ def __init__(self, queue, pythonFolder): try: request = requests.get("http://tmi.twitch.tv/servers?channel="+channel) if request.status_code == 200: - # print type(request.json()) host = random.choice(request.json()['servers']).split(':')[0] - # print request.json()['servers'][0].split(':')[0] except: print "Issue with twitch" exit() diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..7e83d86 --- /dev/null +++ b/setup.py @@ -0,0 +1,13 @@ +from distutils.core import setup + +setup( + name='LalkaChat', + version='0.0.1', + packages=['', 'modules', 'modules.helpers', 'modules.messaging'], + requires=['requests', 'cherrypy', 'ws4py', 'irc', 'wxpython'], + url='https://github.com/DeForce/multichat_python', + license='', + author='CzT/DeForce', + author_email='vlad@czt.lv', + description='' +)