Example #1
0
def gather_commands(path, aliases, command_configs):
    commands = {}

    CommandHandlerProps = namedtuple('CommandHandlerProps', ['handler', 'use_notice'])

    for importer, name, _ in pkgutil.iter_modules([path]):
        f, filename, description = imp.find_module(name, [path])

        try:
            module = imp.load_module(name, f, filename, description)
            if hasattr(module, 'command_handler_properties'):
                json_file_name = name + '.json'
                schema_file_path = os.path.join(os.path.join(path, 'schema'), json_file_name)
                fallback_config_path = os.path.join(os.path.join(path, 'config'), json_file_name)

                if name in command_configs:
                    command_config = validate_default_json(schema_file_path, command_configs[name], 'utf-8')
                else:
                    command_config = validate_load_default_json(schema_file_path, fallback_config_path, 'utf-8')

                command_handler_type, keywords, use_notice = getattr(module, 'command_handler_properties')
                command_handler = command_handler_type(command_config)
                command_handler_props = CommandHandlerProps(command_handler, use_notice)

                for keyword in keywords:
                    aliases = [keyword] + (aliases[keyword] if keyword in aliases else [])
                    for alias in aliases:
                        commands[alias] = command_handler_props
        finally:
            f.close()

    return OrderedDict(sorted(commands.iteritems(), reverse=True, key=lambda t: len(t[0])))
Example #2
0
def gather_commands(path, aliases, command_configs, disabled):
    commands = {}

    CommandHandlerProps = namedtuple('CommandHandlerProps',
                                     ['handler', 'use_notice'])

    for importer, name, _ in pkgutil.iter_modules([path]):
        f, filename, description = imp.find_module(name, [path])

        if os.path.splitext(os.path.basename(filename))[0].lower() in disabled:
            continue

        try:
            module = imp.load_module(name, f, filename, description)
            if hasattr(module, 'command_handler_properties'):
                json_file_name = name + '.json'
                schema_file_path = os.path.join(os.path.join(path, 'schema'),
                                                json_file_name)
                fallback_config_path = os.path.join(
                    os.path.join(path, 'config'), json_file_name)

                if name in command_configs:
                    command_config = validate_default_json(
                        schema_file_path, command_configs[name], 'utf-8')
                else:
                    command_config = validate_load_default_json(
                        schema_file_path, fallback_config_path, 'utf-8')

                command_handler_type, keywords, use_notice = getattr(
                    module, 'command_handler_properties')
                command_handler = command_handler_type(command_config)
                command_handler_props = CommandHandlerProps(
                    command_handler, use_notice)

                for keyword in keywords:
                    aliases = [keyword] + (aliases[keyword]
                                           if keyword in aliases else [])
                    for alias in aliases:
                        commands[alias] = command_handler_props
        finally:
            f.close()

    return OrderedDict(
        sorted(commands.iteritems(), reverse=True, key=lambda t: len(t[0])))
Example #3
0
from twisted.internet.endpoints import clientFromString
from twisted.words.protocols.irc import IRCClient
from twisted.application.internet import ClientService
from twisted.internet import reactor

from markovbrain import MarkovBrain
from utilities.calendar import Calendar
from utilities.common import time_function
from utilities.jsonhelpers import validate_load_default_json, validate_default_json

#
# Setting some settings
#
try:
    config = validate_load_default_json(
        os.path.join(os.path.dirname(__file__), 'config_schema.json'),
        sys.argv[1], 'utf-8')
except jsonschema.ValidationError as e:
    print('Error validating config file (%s).' % sys.argv[1])
    print(e)
    sys.exit()

# Handle home directory
config['brain']['brain_file'] = config['brain']['brain_file'].replace(
    '~', os.path.expanduser('~'))

if not os.path.exists(config['brain']['brain_file']):
    sys.exit(
        'Error: Hoi! I need me some brains! Whaddya think I am, the Tin Man?')

Example #4
0
from twisted.internet.protocol import Factory
from twisted.internet.endpoints import clientFromString
from twisted.words.protocols.irc import IRCClient
from twisted.application.internet import ClientService
from twisted.internet import reactor

from markovbrain import MarkovBrain
from utilities.calendar import Calendar
from utilities.common import time_function
from utilities.jsonhelpers import validate_load_default_json, validate_default_json

#
# Setting some settings
#
try:
    config = validate_load_default_json(os.path.join(os.path.dirname(__file__), 'config_schema.json'), sys.argv[1], 'utf-8')
except jsonschema.ValidationError as e:
    print('Error validating config file (%s).' % sys.argv[1])
    print(e)
    sys.exit()

# Handle home directory
config['brain']['brain_file'] = config['brain']['brain_file'].replace('~', os.path.expanduser('~'))

if not os.path.exists(config['brain']['brain_file']):
    sys.exit('Error: Hoi! I need me some brains! Whaddya think I am, the Tin Man?')

def initialize_chan_props(props):
    quiet_hours = props['quiet_hours']
    if not quiet_hours:
        return props