[docs]classStatus(Enum):"""Goldy Bot enum class of discord status."""ONLINE="online"IDLE="idle"DND="dnd"INVISIBLE="invisible"# Aliases# ---------AWAY=IDLEDO_NOT_DISTURB=DND
# TODO: Create some sort of class to pass into presence methods for changing all status so we can handle the arguments in the methods better.
[docs]classActivityTypes(Enum):"""Goldy Bot enum class of different discord activity types."""PLAYING_GAME=0LIVE_ON_TWITCH=1LISTENING_TO=2WATCHING=3
[docs]classPresence():"""Class that allows you to control the status, game activity and more of Goldy Bot"""def__init__(self,goldy:Goldy)->None:self.goldy=goldyself.logger=LoggerAdapter(goldy_bot_logger,prefix=Colours.BLUE.apply_to_string("Presence"))self.shard_manager=self.goldy.shard_manager
[docs]asyncdefchange(self,status:Status|str=None,activity:Activity=None,afk:bool=None)->None:"""Updates the presence of Goldy Bot. Like e.g ``online, idle, dnd``."""self.logger.debug("Changing presence...")old_presence=self.shard_manager.presence.copy()presence=self.shard_manager.presenceifstatusisnotNone:ifisinstance(status,Status):presence["status"]=status.valueelifisinstance(status,str):presence["status"]=Status(status.lower()).valueelse:# TODO: Let's remove this.raiseInvalidTypeInMethod("status in 'presence.change()' has to be either Status enum or string.")ifactivityisnotNone:presence["activities"]=[PartialActivityData(name=activity.name,type=(lambdax:x.valueifisinstance(x,ActivityTypes)elsex)(activity.type),url=activity.url)]ifafkisnotNone:presence["afk"]=afkforshardinself.shard_manager.active_shards:awaitshard.presence_update(presence)self.logger.debug(f"Updated for shard {shard.shard_id}.")self.logger.info(f"Presence changed from {old_presence} to {self.shard_manager.presence}!")returnNone