Beispiel #1
0
 def guild_unwhitelist(self, event, guild):
     rdb.srem(GUILDS_WAITING_SETUP_KEY, str(guild))
     event.msg.reply(
         'Ok, I\'ve made sure guild %s is no longer in the whitelist' %
         guild)
     Guild.update(whitelist=[]).where(
         str(Guild.guild_id) == str(guild)).execute()
Beispiel #2
0
    def wait_for_actions(self):
        ps = rdb.pubsub()
        ps.subscribe('actions')

        for item in ps.listen():
            if item['type'] != 'message':
                continue

            data = json.loads(item['data'])
            if data['type'] == 'GUILD_UPDATE' and data['id'] in self.guilds:
                with self.send_control_message() as embed:
                    embed.title = u'Reloaded config for {}'.format(
                        self.guilds[data['id']].name)

                self.log.info(u'Reloading guild %s',
                              self.guilds[data['id']].name)

                # Refresh config, mostly to validate
                try:
                    config = self.guilds[data['id']].get_config(refresh=True)

                    # Reload the guild entirely
                    self.guilds[data['id']] = Guild.with_id(data['id'])

                    # Update guild access
                    self.update_rowboat_guild_access()

                    # Finally, emit the event
                    self.emitter.emit('GUILD_CONFIG_UPDATE',
                                      self.guilds[data['id']], config)
                except:
                    self.log.exception(u'Failed to reload config for guild %s',
                                       self.guilds[data['id']].name)
                    continue
            elif data['type'] == 'RESTART':
                self.log.info('Restart requested, signaling parent')
                os.kill(os.getppid(), signal.SIGUSR1)
            elif data['type'] == 'GUILD_DELETE':
                name = self.guilds[data['id']].name if self.guilds.has_key(
                    data['id']) else Guild.with_id(data['id']).name
                with self.send_control_message() as embed:
                    embed.color = 0xff6961
                    embed.title = u'Guild Force Deleted {}'.format(name, )

                try:
                    self.log.info(u'Leaving guild %s', name)
                    self.bot.client.api.users_me_guilds_delete(
                        guild=data['id'])
                except:
                    self.log.info(u'Cannot leave guild %s, bot not in guild',
                                  name)
                finally:
                    self.log.info(u'Disabling guild %s', name)
                    Guild.update(enabled=False).where(
                        Guild.guild_id == data['id']).execute()

                    self.log.info(u'Unwhilelisting guild %s', name)
                    rdb.srem(GUILDS_WAITING_SETUP_KEY, str(data['id']))