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: self.guilds[data['id']].get_config(refresh=True) # Reload the guild entirely self.guilds[data['id']] = Guild.with_id(data['id']) 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)
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']))
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_config_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' and data['id'] in self.guilds: with self.send_config_message() as embed: embed.color = 0xff6961 embed.title = u'Guild Force Deleted {}'.format( self.guilds[data['id']].name, ) self.log.info(u'Leaving guild %s', self.guilds[data['id']].name) self.guilds[data['id']].leave()
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() # Update bot nickname if config.nickname: def set_nickname(): m = self.state.guilds.get( data['id']).members.select_one( id=self.state.me.id) if m and m.nick != config.nickname: try: m.set_nickname(config.nickname) except APIException as e: self.log.warning( 'Failed to set nickname for guild %s (%s)', event.guild, e.content) self.spawn_later(5, set_nickname) # 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' and data['id'] in self.guilds: _guild = self.state.guilds.get(data['id']) with self.send_control_message() as embed: embed.color = 0xff6961 embed.title = u'Guild Force Deleted {}'.format( _guild.name, ) self.log.info(u'Leaving guild %s', _guild.name) _guild.leave()