Skip to content

Commit

Permalink
emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
karlsbjorn committed Sep 28, 2024
1 parent 2ed6d3c commit e610562
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions wowtools/wowtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,20 @@ async def update_countdown_channels(self):
log.debug("Exception in countdown channel editing. {}".format(e))

@wowset.command(name="status", hidden=True)
async def wowset_status(self, ctx: commands.Context, guild_name: str, realm: str, region):
status_guild = [guild_name, realm, region]
async def wowset_status(
self,
ctx: commands.Context,
guild_name: str,
realm: str,
region,
emoji: Optional[discord.Emoji] = None,
):
status_guild = [
guild_name.replace("-", " ").lower(),
realm,
region,
emoji.id if emoji else None,
]
await self.config.status_guild.set(status_guild)
if await self.set_bot_status():
await ctx.send(_("Status guild set."))
Expand All @@ -369,7 +381,7 @@ async def wowset_status(self, ctx: commands.Context, guild_name: str, realm: str

async def set_bot_status(self) -> bool:
try:
guild, realm, region = await self.config.status_guild()
guild, realm, region, emoji = await self.config.status_guild()
except ValueError:
return False

Expand All @@ -385,34 +397,16 @@ async def set_bot_status(self) -> bool:
progress: str = guild_data["raid_progression"]["nerubar-palace"]["summary"]
except KeyError:
return False
activity = discord.CustomActivity(name=f"{guild}: {progress}")
activity = discord.CustomActivity(
name=f"{guild}: {progress}", emoji=self.bot.get_emoji(emoji)
)
await self.bot.change_presence(activity=activity)
return True

@tasks.loop(minutes=60)
async def update_bot_status(self):
try:
guild, realm, region = await self.config.status_guild()
except ValueError:
return

async with RaiderIO() as rio:
guild_data = await rio.get_guild_profile(
region,
realm,
guild,
fields=["raid_progression"],
)
try:
guild: str = guild_data["name"]
progress: str = guild_data["raid_progression"]["nerubar-palace"]["summary"]
except KeyError:
log.warning(
f"Unable to fetch info of guild ({guild}). Setting the bot's status failed."
)
return
activity = discord.CustomActivity(name=f"{guild}: {progress}")
await self.bot.change_presence(activity=activity)
if not self.set_bot_status():
log.warning(f"Setting the bot's status failed.")

def cog_unload(self):
self.bot.loop.create_task(self.session.close())
Expand Down

0 comments on commit e610562

Please sign in to comment.