Skip to content
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

refactor md functions into utils #67

Merged
merged 6 commits into from
Jan 20, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
minor changes
novanai committed Jan 20, 2025
commit 7850951101408d81d9e6b2951467db0089813901
4 changes: 2 additions & 2 deletions src/extensions/action_items.py
Original file line number Diff line number Diff line change
@@ -31,13 +31,13 @@ async def get_action_items(
content = await get_md_content(url, aiohttp_client)
except aiohttp.ClientResponseError as e:
await ctx.respond(
f"❌ **Error**: {e}",
f"❌ Failed to fetch the minutes. Status code: `{e.status}`",
flags=hikari.MessageFlag.EPHEMERAL,
)
return
except ValueError as e:
await ctx.respond(
f"❌ **Error**: {e}",
f"❌ {e}",
flags=hikari.MessageFlag.EPHEMERAL,
)
return
6 changes: 3 additions & 3 deletions src/extensions/agenda.py
Original file line number Diff line number Diff line change
@@ -103,13 +103,13 @@ async def gen_agenda(
content = await get_md_content(url, aiohttp_client)
except aiohttp.ClientResponseError as e:
await ctx.respond(
f"❌ **Error**: {e}",
f"❌ Failed to fetch the agenda template. Status code: `{e.status}`",
flags=hikari.MessageFlag.EPHEMERAL,
)
return
except ValueError as e:
await ctx.respond(
f"❌ **Error**: {e}",
f"❌ {e}",
flags=hikari.MessageFlag.EPHEMERAL,
)
return
@@ -124,7 +124,7 @@ async def gen_agenda(
new_agenda_url = await post_new_md_content(modified_content, aiohttp_client)
except aiohttp.ClientResponseError as e:
await ctx.respond(
f"❌ **Error**: {e}",
f"❌ Failed to generate the agenda. Status code: `{e.status}`",
flags=hikari.MessageFlag.EPHEMERAL,
)
return
5 changes: 4 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
@@ -34,19 +34,22 @@ async def get_md_content(url: str, aiohttp_client: aiohttp.ClientSession) -> str
"""
if "https://md.redbrick.dcu.ie" not in url:
raise ValueError(f"`{url}` is not a valid MD URL. Please provide a valid URL.")

await hedgedoc_login(aiohttp_client)

parsed_url = urlparse(url)
request_url = (
f"{parsed_url.scheme}://{parsed_url.hostname}{parsed_url.path}/download"
)

async with aiohttp_client.get(request_url) as response:
response.raise_for_status()
return await response.text()


async def post_new_md_content(
content: str, aiohttp_client: aiohttp.ClientSession
) -> str | None:
) -> str:
post_url = "https://md.redbrick.dcu.ie/new"
post_headers = {"Content-Type": "text/markdown"}