-
Notifications
You must be signed in to change notification settings - Fork 3
Switch to extension based Cogs #7
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
from discord.ext import commands | ||
from discord.ext.commands import Context | ||
|
||
from sanicbot.core.config import config | ||
from sanicbot.core.utils import failure_message, success_message | ||
|
||
|
||
|
@@ -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: | ||
repo = repo if not repo.startswith("sanic") else "sanic-" + repo | ||
url = f"https://api.github.com/repos/sanic-org/{repo}/issues" | ||
body = f"Forwarded from discord (Author: {ctx.author}, ID: {ctx.author.id})\n" + content | ||
data = { | ||
"title": title, | ||
"body": body, | ||
} | ||
headers = { | ||
"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 commentThe 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 |
||
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"] + "`") | ||
Comment on lines
+61
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Could be set up like so: |
||
|
||
@commands.Cog.listener('on_message') | ||
async def github_issue_message_listener(self, message: Message): | ||
if not message.author.bot: | ||
|
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.