Ejemplo n.º 1
0
 def __init__(self):
     self.registry = dict()
     self.cmd_result = dict()
     subclasses = Command.__subclasses__()
     for s in subclasses:
         cmd = s()
         self.registry[cmd.get_name()] = cmd
Ejemplo n.º 2
0
def build_command_map():
    '''
        In order to decouple the commands from the rest of the codebase, 
        this util dynamically imports the commands classes from the Commands package.
        This allows us to build and store a map from command to functionality 
    '''
    for (module_loader, name, ispkg) in pkgutil.iter_modules(['Commands/']):
        importlib.import_module('Commands.' + name, package=Commands)

    command_classes = [cls() for cls in Command.__subclasses__()]

    cmd_map = {}
    [[
        cmd_map.update({keyword: cl.get_response})
        for keyword in cl.get_keywords()
    ] for cl in command_classes]

    cmd_list = [
        '[{cmds}] : {definition}'.format(
            cmds=', '.join([cmd for cmd in cl.get_keywords()]),
            definition=cl.get_description()) for cl in command_classes
    ]

    return cmd_map, cmd_list
Ejemplo n.º 3
0
    db_port = ''

# Initialise the database
if logging:
    print('Initialising database connection for driver: {driver}'.format(
        driver=CONFIG['DATABASE_CONNECTION']['DRIVER']))
db_engine = create_engine('{driver}://{user}{host}{port}'.format(
    driver=CONFIG['DATABASE_CONNECTION']['DRIVER'],
    user=db_user,
    host=CONFIG['DATABASE_CONNECTION']['HOST'],
    port=db_port),
                          echo=logging)

Base.metdata.create_all(db_engine)

commands = dict([(cls.__name__, cls) for cls in Command.__subclasses__()])
descriptions = dict([(cls.__name__, cls.desc())
                     for cls in Command.__subclasses__()])


def check_auth(user):
    # TODO: Refactor this to use SQLAlchemy
    for i in superusers:
        if i == user:
            return True
    return False


@bot.event
async def on_ready():
    print('Logged in as:')