Exemplo n.º 1
0
    def reload_features(blacklist, existing_features):
        existing_features_str = []
        reloaded_features = []
        # existing features need to be reloaded
        for feature in existing_features:
            existing_features_str.append(type(feature).__name__)

        for module_name in SequelSpeare._find_features():
            class_name = module_name.split('.')[-1]
            # if the module is enabled, and not blacklisted, and already loaded:
            if prefs_singleton.read_with_default(
                    f'{class_name}_enabled',
                    True) and class_name not in blacklist and class_name:
                for feature in existing_features:
                    if type(feature).__name__ == module_name:
                        # reload it and re-instantiate it
                        importlib.reload(feature)
                module = importlib.import_module(module_name)
                clazz = getattr(module, class_name)
                reloaded_features.append(clazz())
            # if the module is enabled, and not blacklisted, but has not already been loaded:
            elif prefs_singleton.read_with_default(
                    f'{class_name}_enabled', True
            ) and class_name not in blacklist and class_name not in existing_features_str:
                # import it and instantiate it
                module = importlib.import_module(module_name)
                clazz = getattr(module, class_name)
                reloaded_features.append(clazz())
        return reloaded_features
Exemplo n.º 2
0
 def __init__(self):
     options = prefs_singleton.read_with_default('youtube', {'playlist_id': "",
                                                             'oauth_storage_filename': 'youtube-oauth2.json',
                                                             'client_secret_filename': 'client_secret.json'})
     self.playlist_id = options['playlist_id']
     self.oauth_storage_filename = options['oauth_storage_filename']
     self.client_secret_filename = options['client_secret_filename']
Exemplo n.º 3
0
    def __init__(self):
        self.printer_dev = prefs_singleton.read_with_default(
            type(self).__name__ + '_printer_dev', '')

        # defer initialization until the first message is seen.
        # This prevents try/catch on initialization, even when this feature is disabled
        self.epson = None
        self.failed_initialization = False
Exemplo n.º 4
0
    def load_features(blacklist):
        enabled_features = []

        for module_name in SequelSpeare._find_features():
            class_name = module_name.split('.')[-1]
            if prefs_singleton.read_with_default(
                    f'{class_name}_enabled',
                    True) and class_name not in blacklist:
                module = importlib.import_module(module_name)
                clazz = getattr(module, class_name)
                enabled_features.append(clazz())
        return enabled_features
Exemplo n.º 5
0
    def __init__(self):
        bot_nick = prefs_singleton.read_value('botnick')
        bot_real_name = prefs_singleton.read_value('botrealname')
        server_address = prefs_singleton.read_value('serveraddress')
        server_port = int(prefs_singleton.read_value('serverport'))
        self.channels_ = prefs_singleton.read_value('channels')
        self.PING_TIMEOUT = 185
        self.RECONNECT_MAX_ATTEMPTS = None  # always try to reconnect

        super().__init__(bot_nick, realname=bot_real_name)
        loop = asyncio.get_event_loop()
        asyncio.ensure_future(self.connect(server_address,
                                           server_port,
                                           tls=False,
                                           tls_verify=False),
                              loop=loop)

        self.preferences = prefs_singleton

        self.blacklist = [
            'AbstractFeature', 'Intelligence', 'Renameable', 'Remindable'
        ]
        self.plugins = self.load_features(self.blacklist)

        # brain is just an instance so it can be referenced again
        if prefs_singleton.read_with_default('Intelligence_enabled', True):
            from Features.Intelligence import Intelligence
            brain = Intelligence()
            self.plugins.append(brain)
            # renameable needs intelligence to rename itself
            if prefs_singleton.read_with_default('Renameable_enabled', True):
                from Features.Renameable import Renameable
                self.plugins.append(Renameable(brain))
        # Remindable needs access to the bot, so it can send a line at any time
        if prefs_singleton.read_with_default('Remindable_enabled', True):
            from Features.Remindable import Remindable
            self.plugins.append(Remindable(self))

        self.plugins.sort(key=lambda f: f.priority)
        loop.run_forever()
Exemplo n.º 6
0
 async def message_filter(self, bot, source, target, message, highlighted):
     if (message.startswith('remind') and highlighted) or message.startswith('!remind'):  # respond to !remind
         if target not in prefs_singleton.read_value('whitelistnicks'):
             wait_time, reminder_text = Remindable.parse_remind(message)
             if reminder_text:
                 await bot.message(source, target + ": I'll remind you about " + reminder_text)
                 reminder_object = {'channel': source, 'remindertext': f'{target}: {reminder_text}',
                                    'remindertime': int(time.time()) + wait_time}
                 existing_reminders = prefs_singleton.read_with_default('reminders', [])
                 existing_reminders.append(reminder_object)
                 prefs_singleton.write_value('reminders', existing_reminders)
             else:
                 await bot.message(source, target + ': Usage is "!remind [in] 5 (second[s]/minute[s]/hour[s]/day[s]) '
                                              'reminder text"')
         return True
     return False