Skip to content

Commit

Permalink
Merge branch 'main' into skelly/deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
SkellyBG committed Feb 20, 2024
2 parents 110cf67 + 443c17e commit ead3973
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 8 deletions.
7 changes: 5 additions & 2 deletions cogs/answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ def __init__(self, bot):
@app_commands.command(name="check")
# remember to add a check so that users can only check answers in their respective
# team channels
async def check_answer(self, puzz_name: str, answer: str):
pass
async def check_answer(self, interaction: discord.Interaction, puzz_name: str, answer: str):
pass

async def setup(bot: commands.Bot):
await bot.add_cog(Answers(bot))
43 changes: 43 additions & 0 deletions cogs/teams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import discord
from discord.ext import commands
from discord import app_commands
from discord import Guild

class Team(commands.GroupCog):
def __init__(self, bot):
self.bot = bot

@app_commands.command(name="create")
async def create_team(self, interaction: discord.Interaction, team_name: str):
# check that user is not already in a team
user = interaction.user
guild = interaction.guild

# include code to check that the name is not already taken
# will involve a call to the respective sql function


# if name not taken, add check for profanity and such

team_role = await Guild.create_role(guild, name=team_name)
overwrites = {
guild.default_role: discord.PermissionOverwrite(read_messages=False),
team_role: discord.PermissionOverwrite(read_messages=True)
}
category = await Guild.create_category(guild, team_name, overwrites=overwrites)
await category.create_text_channel(name=team_name)
await category.create_voice_channel(name=team_name)

# give role to user
await user.add_roles(team_role)
await interaction.response.send_message(f"Team \"{team_name}\" created successfully!")

@app_commands.command(name="leave")
async def leave_team(self, interaction: discord.Interaction, team_name: str):
# remove team role from user
# if there are no more people in the team, delete the role and channels

pass

async def setup(bot: commands.Bot):
await bot.add_cog(Team(bot))
44 changes: 38 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import discord
from discord.ext import commands
from src.config import config
import os

TOKEN = ""
EXEC_ID = "Executives"
COGS_DIR = "cogs"

intents = discord.Intents.all()

Expand All @@ -13,18 +16,47 @@
async def on_ready():
print(f"Connected as {bot.user}.")

try:
synced = await bot.tree.sync()
print(f"Synced {len(synced)} commands.")
except Exception as e:
print(e)

# load all available cogs on startup
@bot.command()
@commands.has_role(EXEC_ID)
async def startup(ctx: commands.context.Context):
for filename in os.listdir("cogs/"):
if filename.endswith(".py"):
await bot.load_extension(f"{COGS_DIR}.{filename[:-3]}")
print(f"Loaded {filename}")
await ctx.send(f"Loaded all cogs")


# command to load a cog
@bot.command()
@commands.has_role(EXEC_ID)
async def load(ctx: commands.context.Context, extension):
await bot.load_extension(f"{COGS_DIR}.{extension}")
await ctx.send(f"Loaded {extension} cog")


# command to unload a cog
@bot.command()
@commands.has_role(EXEC_ID)
async def unload(ctx: commands.context.Context, extension):
await bot.unload_extension(f"{COGS_DIR}.{extension}")
await ctx.send(f"Unloaded {extension} cog")


# command to reload a cog
@bot.command()
@commands.has_role(EXEC_ID)
async def reload(ctx: commands.context.Context, extension):
await bot.reload_extension(f"{COGS_DIR}.{extension}")
await ctx.send(f"Reloaded {extension} cog")


@bot.command()
async def sync(ctx: commands.context.Context):
try:
synced = await bot.tree.sync()
print(f"Synced {len(synced)} commands.")
await ctx.send(f"Synced {len(synced)} commands.")
except Exception as e:
print(e)

Expand Down

0 comments on commit ead3973

Please sign in to comment.