async def set_presence( self, *, status_identifier=None, status_by_key=True, activity_identifier=None, activity_by_key=True, activity_message=None, ): activity = status = None if status_identifier is None: status_identifier = self.bot.config.get("status", None) status_by_key = False try: if status_by_key: status = Status[status_identifier] else: status = Status(status_identifier) except (KeyError, ValueError): if status_identifier is not None: msg = f"Invalid status type: {status_identifier}" logger.warning(error(msg)) if activity_identifier is None: if activity_message is not None: raise ValueError( "activity_message must be None " "if activity_identifier is None." ) activity_identifier = self.bot.config.get("activity_type", None) activity_by_key = False try: if activity_by_key: activity_type = ActivityType[activity_identifier] else: activity_type = ActivityType(activity_identifier) except (KeyError, ValueError): if activity_identifier is not None: msg = f"Invalid activity type: {activity_identifier}" logger.warning(error(msg)) else: url = None activity_message = ( activity_message or self.bot.config.get("activity_message", "") ).strip() if activity_type == ActivityType.listening: if activity_message.lower().startswith("to "): # The actual message is after listening to [...] # discord automatically add the "to" activity_message = activity_message[3:].strip() elif activity_type == ActivityType.streaming: url = self.bot.config.get( "twitch_url", "https://www.twitch.tv/discord-modmail/" ) if activity_message: activity = Activity(type=activity_type, name=activity_message, url=url) else: msg = "You must supply an activity message to use custom activity." logger.warning(error(msg)) await self.bot.change_presence(activity=activity, status=status) presence = { "activity": (None, "No activity has been set."), "status": (None, "No status has been set."), } if activity is not None: use_to = "to " if activity.type == ActivityType.listening else "" msg = f"Activity set to: {activity.type.name.capitalize()} " msg += f"{use_to}{activity.name}." presence["activity"] = (activity, msg) if status is not None: msg = f"Status set to: {status.value}." presence["status"] = (status, msg) return presence
async def set_presence(self, *, status_identifier=None, status_by_key=True, activity_identifier=None, activity_by_key=True, activity_message=None): activity = status = None if status_identifier is None: status_identifier = self.bot.config.get('status', None) status_by_key = False try: if status_by_key: status = Status[status_identifier] else: status = Status(status_identifier) except (KeyError, ValueError): if status_identifier is not None: msg = f'Invalid status type: {status_identifier}' logger.warning(error(msg)) if activity_identifier is None: if activity_message is not None: raise ValueError('activity_message must be None ' 'if activity_identifier is None.') activity_identifier = self.bot.config.get('activity_type', None) activity_by_key = False try: if activity_by_key: activity_type = ActivityType[activity_identifier] else: activity_type = ActivityType(activity_identifier) except (KeyError, ValueError): if activity_identifier is not None: msg = f'Invalid activity type: {activity_identifier}' logger.warning(error(msg)) else: url = None activity_message = (activity_message or self.bot.config.get( 'activity_message', '')).strip() if activity_type == ActivityType.listening: if activity_message.lower().startswith('to '): # The actual message is after listening to [...] # discord automatically add the "to" activity_message = activity_message[3:].strip() elif activity_type == ActivityType.streaming: url = self.bot.config.get( 'twitch_url', 'https://www.twitch.tv/discord-modmail/') if activity_message: activity = Activity(type=activity_type, name=activity_message, url=url) else: msg = 'You must supply an activity message to use custom activity.' logger.warning(error(msg)) await self.bot.change_presence(activity=activity, status=status) presence = { 'activity': (None, 'No activity has been set.'), 'status': (None, 'No status has been set.') } if activity is not None: to = 'to ' if activity.type == ActivityType.listening else '' msg = f'Activity set to: {activity.type.name.capitalize()} ' msg += f'{to}{activity.name}.' presence['activity'] = (activity, msg) if status is not None: msg = f'Status set to: {status.value}.' presence['status'] = (status, msg) return presence
async def set_presence(self, *, status_identifier=None, status_by_key=True, activity_identifier=None, activity_by_key=True, activity_message=None): activity = status = None if status_identifier is None: status_identifier = self.bot.config.get('status', None) status_by_key = False try: if status_by_key: status = Status[status_identifier] else: status = Status(status_identifier) except (KeyError, ValueError): if status_identifier is not None: msg = f'Invalid status type: {status_identifier}' logger.warning(error(msg)) if activity_identifier is None: if activity_message is not None: raise ValueError('activity_message doit être None ' 'si activity_identifier est None.') activity_identifier = self.bot.config.get('activity_type', None) activity_by_key = False try: if activity_by_key: activity_type = ActivityType[activity_identifier] else: activity_type = ActivityType(activity_identifier) except (KeyError, ValueError): if activity_identifier is not None: msg = f'Type d\'activité invalide: {activity_identifier}' logger.warning(error(msg)) else: url = None activity_message = (activity_message or self.bot.config.get( 'activity_message', '')).strip() if activity_type == ActivityType.listening: if activity_message.lower().startswith('to '): # The actual message is after listening to [...] # discord automatically add the "to" activity_message = activity_message[3:].strip() elif activity_type == ActivityType.streaming: url = self.bot.config.get('twitch_url', 'https://www.twitch.tv/discordfr_') if activity_message: activity = Activity(type=activity_type, name=activity_message, url=url) else: msg = 'Vous devez fournir un message d\'activité pour utiliser une activité personnalisée.' logger.warning(error(msg)) await self.bot.change_presence(activity=activity, status=status) presence = { 'activity': (None, 'Aucune activité n\'a été définie.'), 'status': (None, 'Aucun statut n\'a été défini.') } if activity is not None: to = 'à ' if activity.type == ActivityType.listening else '' msg = f'Activité réglée sur: {activity.type.name.capitalize()} ' msg += f'{to}{activity.name}.' presence['activity'] = (activity, msg) if status is not None: msg = f'Statut défini sur: {status.value}.' presence['status'] = (status, msg) return presence