Skip to content

Commit

Permalink
Merge pull request #16 from Xorboo/feature/channel-name
Browse files Browse the repository at this point in the history
Display space status in the category channel name
  • Loading branch information
DoomHammer authored Oct 24, 2024
2 parents 55375e8 + 35bc401 commit 3a863bf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

discord_token = os.getenv('DISCORD_TOKEN')
space_endpoint = os.getenv('SPACE_ENDPOINT')
channel_id = os.getenv('DISCORD_CHANNEL_ID')

avatars = {}
usernames = {
Expand All @@ -22,6 +23,7 @@
}

people_indicator = '🧙'
channel_name = 'INFORMACJA 📑'

current_state = None
current_persons = None
Expand All @@ -36,14 +38,17 @@
async def update_state(state, persons):
if client.user:
logging.info(f'Updating the presence to "{state}, {persons}"')
nick = f"{usernames[state]} ({persons} {people_indicator})" if state == 'open' and persons is not None \
else usernames[state]
for guild in client.guilds:
member = guild.get_member_named(client.user.name)
nick = usernames[state]
if state == 'open':
if persons is not None:
nick = f"{usernames[state]} ({persons} {people_indicator})"
await member.edit(nick=nick)

channel = guild.get_channel(channel_id)
if channel:
channel_state = "🔒" if state == "closed" else f"🔓/{persons or "?"}"
await channel.edit(name=f"{channel_name} [{channel_state}]")


async def update_presence(state, persons):
global current_state, current_persons
Expand Down

0 comments on commit 3a863bf

Please sign in to comment.