コード例 #1
0
ファイル: __init__.py プロジェクト: chizu/fishbot
def bang(self, event):
    import re
    import importer
    pipes = [string.strip(i) for i in event.arguments.split('|')]
    pipein = ""
    for pipe in pipes:
        if pipe:
            postpipe = re.search(expression[0], pipe)
            if not postpipe:
                # invalid bang command syntax
                print "bang: invalid syntax - '" + pipe + "'"
                return
            name = postpipe.group(1)
            arguments = string.strip(postpipe.group(2))
            try:
                module = importer.__import__(name, globals(), locals(),
                                             'plugins.bang')
                if hasattr(module, 'bang'):
                    # New API
                    respond = self.respond_to(event.source, event.target)
                    (pubmsg, action) = module.bang(pipein, arguments, event)
                    if pubmsg and pipe is pipes[-1]:
                        if isinstance(pubmsg, (list, tuple)):
                            lines = list()
                            for line in pubmsg:
                                lines += line.split('\n')
                        else:
                            lines = pubmsg.split('\n')
                        if len(lines) > 13:
                            # Private message
                            respond = fishapi.getnick(event.source)
                        for each in lines:
                            if each != '':
                                event.server.message(respond, each)
                    elif pubmsg:
                        if isinstance(pubmsg, (list, tuple)):
                            pipein = string.join(pubmsg, '\n')
                        else:
                            pipein = pubmsg
                    if action:
                        if isinstance(action, (list, tuple)):
                            for each in action:
                                event.server.action(respond, each)
                        else:
                            event.server.action(respond, action)

                elif hasattr(module, 'handle_say'):
                    # Old API
                    module.handle_say(self, event.source, event.target,
                                      event.arguments)
            except ImportError:
                return
            except:
                raise
コード例 #2
0
ファイル: help.py プロジェクト: chizu/fishbot
def bang(pipein, arguments, event):
    if len(arguments) is 0:
        from glob import glob
        submodules = glob("plugins/bang/*.py")
        commands = set()
        for each in submodules:
            each = each.split('/')[-1].split('.')[0]
            commands.add(each)
        commands.remove('__init__')
        return (fishapi.version + ". Available commands are: !" + string.join(sorted(commands),', !') + ".", None)
    else:
        reply = []
        for each in arguments.split():
            try:
                if each[0] is "!":
                    each = each[1:]
                help_string = importer.__import__(each, globals(), locals(), 'plugins.bang').__doc__
                reply.append(help_string)
            except:
                reply.append("No help available for %s." % each)
                raise
        return (reply, None)
コード例 #3
0
ファイル: fishbot.py プロジェクト: chizu/fishbot
    def messaged(self, event):
        """As messages occur, call the appropriate hooks in the plugins.

        Any server message should call this method, this will execute the appropriate plugins."""
        # Re-exec fishbot if fishbot itself has changed.
        # This is disabled, it's slightly broken.
        #if os.stat(sys.argv[0]).st_mtime > fishapi.execution_time:
        #    for each in self.servers.values():
        #        each.disconnect("Fishbot has changed enough to require a restart.")
        #    os.execv(sys.argv[0], sys.argv[1:])
        # Execute the plugin tree as required.
        plugins = importer.__import__("plugins")
        print "Event: " + str(event)
        for each in sorted(plugins.expressions):
            match = re.search(each, event.arguments)
            if match:
                name = str(plugins.expressions[each])
                print "Expression: " + str(each)
                for each in plugins.expressions[each]:
                    print "Plugin: " + str(each)
                    thread = plugins.PluginThread(each, (self, event))
                    thread.start()
コード例 #4
0
ファイル: fishbot.py プロジェクト: chizu/fishbot
    def messaged(self, event):
        """As messages occur, call the appropriate hooks in the plugins.

        Any server message should call this method, this will execute the appropriate plugins."""
        # Re-exec fishbot if fishbot itself has changed.
        # This is disabled, it's slightly broken.
        #if os.stat(sys.argv[0]).st_mtime > fishapi.execution_time:
        #    for each in self.servers.values():
        #        each.disconnect("Fishbot has changed enough to require a restart.")
        #    os.execv(sys.argv[0], sys.argv[1:])
        # Execute the plugin tree as required.
        plugins = importer.__import__("plugins")
        print "Event: " + str(event)
        for each in sorted(plugins.expressions):
            match = re.search(each, event.arguments)
            if match:
                name = str(plugins.expressions[each])
                print "Expression: " + str(each)
                for each in plugins.expressions[each]:
                    print "Plugin: " + str(each)
                    thread = plugins.PluginThread(each, (self, event))
                    thread.start()
コード例 #5
0
ファイル: help.py プロジェクト: chizu/fishbot
def bang(pipein, arguments, event):
    if len(arguments) is 0:
        from glob import glob
        submodules = glob("plugins/bang/*.py")
        commands = set()
        for each in submodules:
            each = each.split('/')[-1].split('.')[0]
            commands.add(each)
        commands.remove('__init__')
        return (fishapi.version + ". Available commands are: !" +
                string.join(sorted(commands), ', !') + ".", None)
    else:
        reply = []
        for each in arguments.split():
            try:
                if each[0] is "!":
                    each = each[1:]
                help_string = importer.__import__(each, globals(), locals(),
                                                  'plugins.bang').__doc__
                reply.append(help_string)
            except:
                reply.append("No help available for %s." % each)
                raise
        return (reply, None)
コード例 #6
0
ファイル: wikipedia.py プロジェクト: chizu/fishbot
#!/usr/bin/python
"""!wikipedia - Search wikipedia"""
import re,importer
google = importer.__import__("google", globals(), locals(), "plugins/bang")

def bang(pipein, arguments, event):
    search = pipein or arguments
    return google.bang("site:en.wikipedia.org " + search, "", event)
コード例 #7
0
#!/usr/bin/python
"""!wikipedia - Search wikipedia"""
import re, importer
google = importer.__import__("google", globals(), locals(), "plugins/bang")


def bang(pipein, arguments, event):
    search = pipein or arguments
    return google.bang("site:en.wikipedia.org " + search, "", event)
コード例 #8
0
from glob import glob

expressions = {}

submodules = glob("plugins/*")
submodules.sort()
__all__ = set()
for each in submodules:
    each = each.split('/')[-1].split('.')[0]
    __all__.add(each)
__all__.remove('__init__')
__all__ = list(__all__)
__all__.sort()

for each in __all__:
    module = importer.__import__(name=each, path="plugins")
    expression = module.expression[0]
    if expression in expressions:
        expressions[expression].append(module.expression[1])
    else:
        expressions[expression] = [module.expression[1]]

class PluginThread(threading.Thread):
    def __init__(self, func, args):
        self.func = func
        self.args = args
        super(PluginThread, self).__init__()

    def run(self):
        self.func(*self.args)