From 2d721775ace9e2ce4c02c1e5c3b922108e6af4f6 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Thu, 10 Jul 2025 14:16:05 +0100 Subject: Add new GitHub extension --- arthur/exts/github/__init__.py | 1 + arthur/exts/github/management.py | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 arthur/exts/github/__init__.py create mode 100644 arthur/exts/github/management.py diff --git a/arthur/exts/github/__init__.py b/arthur/exts/github/__init__.py new file mode 100644 index 0000000..78cc904 --- /dev/null +++ b/arthur/exts/github/__init__.py @@ -0,0 +1 @@ +"""Utilities for managing the GitHub organisation.""" diff --git a/arthur/exts/github/management.py b/arthur/exts/github/management.py new file mode 100644 index 0000000..202dd5b --- /dev/null +++ b/arthur/exts/github/management.py @@ -0,0 +1,42 @@ +"""Commands for managing the GitHub organisation and teams.""" + +from discord.ext.commands import Cog, Context, group + +from arthur.apis.github import GitHubException, add_staff_member +from arthur.bot import KingArthur +from arthur.config import CONFIG + + +class GitHubManagement(Cog): + """Ed is the standard text editor.""" + + def __init__(self, bot: KingArthur) -> None: + self.bot = bot + + async def cog_check(self, ctx: Context) -> bool: + """Check if the user has permission to use this cog.""" + return ( + CONFIG.admins_role in [r.id for r in ctx.author.roles] + or CONFIG.devops_role in [r.id for r in ctx.author.roles] + or await self.bot.is_owner(ctx.author) + ) + + @group(name="github", invoke_without_command=True) + async def github(self, ctx: Context) -> None: + """Group of commands for managing the GitHub organisation.""" + if ctx.invoked_subcommand is None: + await ctx.send_help(ctx.command) + + @github.command(name="add") + async def add_team_member(self, ctx: Context, username: str) -> None: + """Add a user to the default GitHub team.""" + try: + await add_staff_member(username) + await ctx.send(f":white_check_mark: Successfully invited {username} to the staff team.") + except GitHubException as e: + await ctx.send(f":x: Failed to add {username} to the staff team: {e}") + + +async def setup(bot: KingArthur) -> None: + """Add cog to bot.""" + await bot.add_cog(GitHubManagement(bot)) -- cgit v1.2.3