Exemplo n.º 1
0
class DataParser(object):
    def __init__(self, bot):
        self.logger = LogHandler(__file__)
        self.logger.log("Class Initialized `DataParser`")

        self.bot = bot
        self.message = message.Message(self.bot.nick)

    def privmsg(self, channel, data):
        self.logger.log("[PRIVMSG] Sending '{0}' to '{1}'".format(data, channel), lt=1)
        self.bot.send("PRIVMSG {0} :{1}".format(channel, data))

    def parse(self, msg):
        self.message.define(msg)
        nick_access = self.bot.accessHandler.get_access(self.message.unparsedNick)
        
        for module in self.bot.moduleHandler.modules:
            module = self.bot.moduleHandler.modules[module]
            for hook in module.hooks:
                kw, func, argc, access = hook
                if argc <= self.message.command_argc:
                    if  nick_access >= access:
                        if kw.compare(self.bot.command_char, self.message):
                            try:
                                func(self.message)
                            except Exception, e:
                                self.privmsg(self.message.location, "Exception {0} found.".format(str(e)))
                                for item in traceback.format_exc().split("\n"):
                                    if item.strip().startswith("File"):
                                        self.privmsg(self.message.location, self.bot.moduleHandler.error_clean(item))
Exemplo n.º 2
0
Arquivo: web.py Projeto: Cam1337/PyIRC
class WebParser(object):
    def __init__(self, bot):
        self.bot = bot
        self.logger = LogHandler(__file__)
        self.logger.log("Class Initialized `WebParser`")
    def read(self, url):
        return urllib.urlopen(url).read()
    def garbage(self):
        pass
Exemplo n.º 3
0
class AccessHandler(object):
    def __init__(self, bot):
        self.bot = bot
        self.logger = LogHandler(__file__)
        self.logger.log("Class Initialized `AccessHandler`")
    def get_access(self, nick, nm=True):
        if nm: nick = nick.lower()
        return self.get_real_access(nick)
    def get_real_access(self, nick):
        if nick in ["Nox","Cam", "Waflel"]:
            return True
        else:
            retrurn False
    def garbage(self):
        pass
Exemplo n.º 4
0
class Event(object):
    def __init__(self, trigger_time, function, args=None, callback=None, title=None):
        self.logger = LogHandler(__file__)
        self.trigger_time = trigger_time
        self.function = function
        self.args = args
        self.callback = callback
        self.title = title

        self.result = None
    def call(self):
        self.logger.log("Executing {0} from events".format(self.title or self.function), lt=3)
        if self.args:
            self.result = self.function(*self.args)
        else:
            self.result = self.function()
        if self.callback:
            self.callback(self.result)
Exemplo n.º 5
0
    def __init__(self, trigger_time, function, args=None, callback=None, title=None):
        self.logger = LogHandler(__file__)
        self.trigger_time = trigger_time
        self.function = function
        self.args = args
        self.callback = callback
        self.title = title

        self.result = None
Exemplo n.º 6
0
class EventHandler(object):
    def __init__(self, bot):
        self.logger = LogHandler(__file__)
        self.logger.log("Class Initialized `EventHandler`")
        self.bot = bot
        self.events = []
        self.finished = []
    def schedule(self, in_seconds, function, args=None, callback=None, title=None):
        newEvent = Event(time.time() + in_seconds, function, args=args, callback=callback, title=title)
        self.events.append(newEvent)
    def check(self):
        for _event in self.events:
            if time.time() > _event.trigger_time:
                _event.call()
                self.finished.append(_event)
        for _event in self.finished:
            try:
                self.events.remove(_event)
            except ValueError:
                continue
Exemplo n.º 7
0
    def __init__(self, bot, load_on_init=True):
        self.logger = LogHandler(__file__)
        self.logger.log("Class Initialized `ModuleHandler`")
        self.bot = bot
        self.modules = {}
        self.raw = {}

        self.to_load = []
        self.to_unload = []

        self.module_path = os.path.abspath(__file__.replace(os.path.split(__file__)[1],"../../modules"))

        if load_on_init:
            self.load_all_modules()
Exemplo n.º 8
0
class Message(object):
    def __init__(self, nick):
        self.logger = LogHandler(__file__)
        self.logger.log("Class Initialized `Message`")

        self.bot_nick = nick

        self.args         = []
        self.argc        = len(self.args)
        self.command_argc = 0
        self.line         = ""
        self.unparsedNick = ""
        self.nick         = ""
        self.location     = ""
        self.destination  = ""
        self.command      = ""
        self.commandArgs  = ""
        self.hostName     = ""

    def arg(self, argNum):
        try:
            return self.args[argNum]
        except Exception, e:
            return None
Exemplo n.º 9
0
class ConnectionHandler(object):
    def __init__(self):
        self.logger = LogHandler(__file__)
        self.logger.log("Class Initialized `DataParser`")

        self.bots = []
        self.connections = []

    def add(self, bot):
        self.bots.append(bot)
    def remove(self, bot):
        self.bots.remove(bot)
    def connect(self, bot):
        self.logger.log("Connecting bot {0}".format(bot.nick), lt=1)
        try:
            bot.network.is_connected = True
            if bot.network.ssl:
                bot.network.socket = ssl.wrap_socket(bot.network.socket)
            bot.network.socket.connect((bot.network.host, bot.network.port))
            self.send(bot, "NICK {0}".format(bot.nick))
            self.send(bot, "USER {0} *** *** :{1}".format(bot.ident, bot.realname))
        except Exception, e:
            print e
            bot.network.is_connected = False
Exemplo n.º 10
0
    def __init__(self, nick):
        self.logger = LogHandler(__file__)
        self.logger.log("Class Initialized `Message`")

        self.bot_nick = nick

        self.args         = []
        self.argc        = len(self.args)
        self.command_argc = 0
        self.line         = ""
        self.unparsedNick = ""
        self.nick         = ""
        self.location     = ""
        self.destination  = ""
        self.command      = ""
        self.commandArgs  = ""
        self.hostName     = ""
Exemplo n.º 11
0
    def __init__(self):
        self.logger = LogHandler(__file__)
        self.logger.log("Class Initialized `DataParser`")

        self.bots = []
        self.connections = []
Exemplo n.º 12
0
class ModuleHandler(object):
    def __init__(self, bot, load_on_init=True):
        self.logger = LogHandler(__file__)
        self.logger.log("Class Initialized `ModuleHandler`")
        self.bot = bot
        self.modules = {}
        self.raw = {}

        self.to_load = []
        self.to_unload = []

        self.module_path = os.path.abspath(__file__.replace(os.path.split(__file__)[1],"../../modules"))

        if load_on_init:
            self.load_all_modules()

    def load_all_modules(self):
        ignore = ["__init__.py","__init__.pyc","_template"]
        modules = [f for f in os.listdir(self.module_path) if f not in ignore]
        for module in modules:
            self.load_module(module)

    def load_module(self, name):
        self.to_load.append(name)

    def load_module_actual(self, name):
        raw_import = __import__("pyirc.modules.{0}".format(name), fromlist=["module","configuration"], level=-1)
        module = raw_import.module.Module(self.bot, raw_import.configuration.Configuration)
        module.on_load()
        self.raw[name] = raw_import
        self.modules[name] = module

    def unload_module(self, name):
        self.to_unload.append(name)

    def unload_module_actual(self, name):
        if self.modules.get(name,None):
            if  self.modules[name].on_unload():
                del self.modules[name]
                del self.raw[name]

    def reload_module(self, name):
        if self.modules[name].on_reload():
            reload(self.raw[name].module)
            reload(self.raw[name].configuration)
            self.modules[name] = self.raw[name].module.Module(self.bot, self.raw[name].configuration.Configuration)

    def reload_all(self):
        for module in self.modules:
            self.reload_module(module)

    def garbage(self):
        for mod in self.to_unload:
            self.unload_module_actual(mod)
        for mod in self.to_load:
            self.load_module_actual(mod)
        self.to_unload, self.to_load = [], []
        for module in self.modules:
            self.modules[module].garbage()

    def error_clean(self, err):
        return err.split(os.path.split(os.path.split(self.module_path)[0])[0])[1][1:]
Exemplo n.º 13
0
    def __init__(self, bot):
        self.logger = LogHandler(__file__)
        self.logger.log("Class Initialized `DataParser`")

        self.bot = bot
        self.message = message.Message(self.bot.nick)
Exemplo n.º 14
0
 def __init__(self, path):
     self.dbpath = path
     self.logger = LogHandler(__file__)
     self.logger.log("HelperClass Initialized `Database`")
Exemplo n.º 15
0
 def __init__(self, bot):
     self.logger = LogHandler(__file__)
     self.logger.log("Class Initialized `EventHandler`")
     self.bot = bot
     self.events = []
     self.finished = []
Exemplo n.º 16
0
Arquivo: web.py Projeto: Cam1337/PyIRC
 def __init__(self, bot):
     self.bot = bot
     self.logger = LogHandler(__file__)
     self.logger.log("Class Initialized `WebParser`")
Exemplo n.º 17
0
class BaseModule(object):
    def __init__(self, bot, configuration):
        self.logger = LogHandler(__file__)
        self.bot = bot
        self.configuration = configuration
        self.hooks = []
    def hook(self, keyword, function, argc, access):
        keyword.prefix = self.configuration.command_prefix
        self.logger.log("Added hook '{0}'".format(keyword), lt=3)
        self.hooks.append((keyword, function, argc, access))
    def on_load(self):
        self.logger.log("on_load() for '{0}'".format(self.configuration.command_prefix), lt=3)
        return True
    def on_unload(self):
        self.logger.log("on_unload() for '{0}'".format(self.configuration.command_prefix), lt=3)
        return True
    def on_reload(self):
        self.logger.log("on_reload() for '{0}'".format(self.configuration.command_prefix), lt=3)
        return True
    def send(self, data):
        self.bot.send(data)
    def privmsg(self, channel, data):
        self.logger.log("[PRIVMSG] Sending '{0}' to '{1}'".format(data, channel), lt=1)
        self.bot.send("PRIVMSG {0} :{1}".format(channel, data))
    def action(self, channel, data):
        self.logger.log("[ACTION] Sending '{0}' to '{1}'".format(data, channel), lt=1)
        self.bot.send("PRIVMSG {0} :\x01ACTION {1}\x01".format(channel, data))
    def notice(self, channel, data):
        self.logger.log("[NOTICE] Sending '{0}' to '{1}'".format(data, channel), lt=1)
        self.bot.send("NOTICE {0} :{1}".format(channel, data))
    def garbage(self):
        pass
Exemplo n.º 18
0
 def __init__(self, bot, configuration):
     self.logger = LogHandler(__file__)
     self.bot = bot
     self.configuration = configuration
     self.hooks = []