-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to extension based Cogs #7
base: main
Are you sure you want to change the base?
Conversation
This lets us reload the modules with ease during development. The main entry point was also modified to accomodate this. The Git Cog was also calling bot.process_commands(), causing duplicate command invocations, which was removed.
Create an issue, with information about the author.
async with httpx.AsyncClient() as client: | ||
response = await client.post(url, data=data, headers=headers) | ||
if response.status_code == 200: | ||
await success_message(ctx, "Issue created\n" + response.json()["url"]) | ||
else: | ||
await failure_message(ctx, "An error occured: `" + response.json()["message"] + "`") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be premature for now, but it would be nice to abstract some of this into a GH client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be set up like so: /gh create issue
whereas issue lookup could be set up like: /gh issue 2559
and PRs /gh pr 352
, could display lists of issues/PRs with pagination: /gh issues 1
and /gh prs 1
from discord.ext import commands | ||
|
||
|
||
class Help(commands.Cog): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By switching to application (slash) commands, this cog becomes obsolete. A user simply needs to start typing /
to get a list of commands and their descriptions.
bot = commands.Bot(help_command=None, command_prefix='!') | ||
|
||
for ext in EXTENSIONS: | ||
bot.load_extension(ext) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By adding Cog classes using bot.add_cog
we can avoid adding setup() functions to the cog files. (see PR #8 for implementation). By extending the commands.Bot
class we have more control over the bot scope and can handle adding cogs more elegantly.
"Accept": "application/vnd.github.v3+json", | ||
"Authorization": "token " + config["SANIC"]["git_token"] | ||
} | ||
async with httpx.AsyncClient() as client: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by extending the commands.Bot class (see PR #8 for implementation) we can attach a bot-level httpclient
so we're not creating a new client each time a command is called.
@@ -44,6 +45,26 @@ async def retrieve_github_issue( | |||
repo = f"sanic-{repo}" | |||
await self.lookup(ctx, number, repo) | |||
|
|||
@commands.command() | |||
async def issue(self, ctx: Context, repo: str, title: str, *, content: str) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a worthwhile command, however it would be better implemented using slash sub-commands. Considering what @ahopkins mentioned about a GH client, sub-commands would make things easier.
This lets us reload the modules with ease during development.
The main entry point was also modified to accomodate this.
The Git Cog was also calling bot.process_commands(), causing duplicate command invocations, which was removed.
!issue command added.