Skip to content
Merged

Dev #261

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 57 additions & 4 deletions bot/cogs/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
from discord.ext import commands
from discord import app_commands

from bot.constants import accepting_team_invites_role_id, system_log_channel_id, success_emoji
from bot.constants import (
accepting_team_invites_role_id, system_log_channel_id, success_emoji,
teams_dashboard_message_id, join_a_team_channel_id
)
from bot.utils.embed_handler import success, failure, warning, info, authored_sm
from bot.utils.checks import tortoise_bot_developer_only



class CreateTeamModal(discord.ui.Modal, title="Create Team"):

name = discord.ui.TextInput(label="Team Name", max_length=50)
Expand Down Expand Up @@ -51,7 +55,7 @@ async def on_submit(self, interaction: discord.Interaction):
try:

role = await guild.create_role(name=name)
category = await guild.create_category(f"TEAM - {name}")
category = await guild.create_category(f"Team - {name}")

overwrites = {
guild.default_role: discord.PermissionOverwrite(
Expand All @@ -67,13 +71,13 @@ async def on_submit(self, interaction: discord.Interaction):
}

text = await guild.create_text_channel(
name=name,
name="team-chat",
category=category,
overwrites=overwrites
)

voice = await guild.create_voice_channel(
name=name,
name="team-voice",
category=category,
overwrites=overwrites
)
Expand Down Expand Up @@ -632,6 +636,55 @@ async def leave_team(self, interaction: discord.Interaction):
embed=success("You left the team.")
)

async def _build_team_embed(self, guild: discord.Guild):

teams = await self.team.get_all_teams(guild.id)

if not teams:
return info("No teams created yet.", self.bot.user, "Teams Dashboard")

desc = ""

for team in teams:
leader = guild.get_member(team["leader_id"])
members = await self.team.get_team_members(team["team_id"])

desc += (
f"**{team['name']}**\n"
f"Lead: {leader.mention if leader else 'Unknown'}\n"
f"Timezone: `{team['timezone']}`\n"
f"Members: {len(members)}\n\n"
)

return info(desc, self.bot.user, "Teams Dashboard", "powered by Tortoise Programming Community")

@app_commands.command(name="update_team_dashboard")
@app_commands.check(tortoise_bot_developer_only)
async def update_team_dashboard(self, interaction: discord.Interaction):

channel = self.bot.get_channel(join_a_team_channel_id)
if not channel:
return await interaction.response.send_message(
embed=failure("Channel not found."),
ephemeral=True
)

try:
msg = await channel.fetch_message(teams_dashboard_message_id)
except:
return await interaction.response.send_message(
embed=failure("Dashboard message not found."),
ephemeral=True
)

embed = await self._build_team_embed(interaction.guild)

await msg.edit(embed=embed)

await interaction.response.send_message(
embed=success("Dashboard updated."),
ephemeral=True
)

async def setup(bot):
await bot.add_cog(TeamCog(bot))
4 changes: 4 additions & 0 deletions bot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
challenges_channel_id = 780841435712716800
bait_channel_id = 1461666781612740750
introduction_channel_id = 1487413734056923236
join_a_team_channel_id = 1489254495522390186

# Message id
teams_dashboard_message_id = 1489259245282267208

# Roles
muted_role_id = 707007421066772530
Expand Down
Loading