-
Notifications
You must be signed in to change notification settings - Fork 8
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
add /agenda command #58
Open
wizzdom
wants to merge
10
commits into
main
Choose a base branch
from
agenda
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+202
−0
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
660c4dc
add /agenda command
wizzdom 096bc23
fix emoji reaction
wizzdom 2b7c283
really fix emoji reaction
wizzdom 3cebc2e
update envvars for nomad job
wizzdom 42d7975
make mentions actually mention
wizzdom 35d0e65
make command group, add template subcommand
wizzdom e5d273e
cleanup, restrict to proper channels
wizzdom 6e9319c
hooks: fix channel_ids list
wizzdom a6f382a
fix error message, remove incorrect use of constants
wizzdom ac0be4c
typing & formatting improvements
novanai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
import arc | ||
import hikari | ||
import aiohttp | ||
from urllib.parse import urlparse | ||
import datetime | ||
|
||
from src.utils import role_mention, hedgedoc_login | ||
from src.hooks import restrict_to_channels, restrict_to_roles | ||
from src.config import CHANNEL_IDS, ROLE_IDS, UID_MAPS, AGENDA_TEMPLATE_URL | ||
|
||
|
||
plugin = arc.GatewayPlugin(name="Agenda") | ||
|
||
agenda = plugin.include_slash_group("agenda", "Interact with the agenda.") | ||
|
||
|
||
def generate_date_choices() -> list[str]: | ||
"""Generate date options for the next 7 days.""" | ||
today = datetime.date.today() | ||
return [(today + datetime.timedelta(days=i)).strftime("%Y-%m-%d") for i in range(7)] | ||
|
||
|
||
def generate_time_choices() -> list[str]: | ||
"""Generate time options for every hour""" | ||
base_time = datetime.time(0, 0) | ||
times: list[str] = [] | ||
for hour in range(24): | ||
current_time = ( | ||
datetime.datetime.combine(datetime.date.today(), base_time) | ||
+ datetime.timedelta(hours=hour) | ||
).time() | ||
times.append(current_time.strftime("%H:%M")) | ||
return times | ||
|
||
|
||
@agenda.include | ||
@arc.with_hook( | ||
restrict_to_channels( | ||
channel_ids=[ | ||
CHANNEL_IDS["bots-cmt"], | ||
CHANNEL_IDS["committee-announcements"], | ||
CHANNEL_IDS["cowboys-and-cowgirls-committee"], | ||
] | ||
) | ||
) | ||
@arc.with_hook(restrict_to_roles(role_ids=[ROLE_IDS["committee"]])) | ||
@arc.slash_subcommand( | ||
"generate", | ||
"Generate a new agenda for committee meetings", | ||
autodefer=arc.AutodeferMode.EPHEMERAL, | ||
) | ||
async def gen_agenda( | ||
ctx: arc.GatewayContext, | ||
date: arc.Option[ | ||
str, | ||
arc.StrParams("Select a date", choices=generate_date_choices()), | ||
], | ||
time: arc.Option[ | ||
str, | ||
arc.StrParams( | ||
"Enter the time in HH:MM format", choices=generate_time_choices() | ||
), | ||
], | ||
room: arc.Option[ | ||
str, | ||
arc.StrParams("Select a Room"), | ||
], | ||
url: arc.Option[ | ||
str, arc.StrParams("URL of the agenda template from the MD") | ||
] = AGENDA_TEMPLATE_URL, | ||
aiohttp_client: aiohttp.ClientSession = arc.inject(), | ||
) -> None: | ||
"""Generate a new agenda for committee meetings""" | ||
|
||
parsed_date = datetime.datetime.strptime(date, "%Y-%m-%d").date() | ||
parsed_time = datetime.datetime.strptime(time, "%H:%M").time() | ||
|
||
parsed_datetime = datetime.datetime.combine(parsed_date, parsed_time) | ||
|
||
formatted_date = parsed_datetime.strftime("%Y-%m-%d") | ||
formatted_time = parsed_datetime.strftime("%H:%M") | ||
formatted_datetime = parsed_datetime.strftime("%A, %Y-%m-%d %H:%M") | ||
|
||
if "https://md.redbrick.dcu.ie" not in url: | ||
await ctx.respond( | ||
f"❌ `{url}` is not a valid MD URL. Please provide a valid URL.", | ||
flags=hikari.MessageFlag.EPHEMERAL, | ||
) | ||
return | ||
|
||
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: | ||
if response.status != 200: | ||
await ctx.respond( | ||
f"❌ Failed to fetch the agenda template. Status code: `{response.status}`", | ||
flags=hikari.MessageFlag.EPHEMERAL, | ||
) | ||
return | ||
|
||
content = await response.text() | ||
|
||
modified_content = content.format( | ||
DATE=formatted_date, TIME=formatted_time, ROOM=room | ||
) | ||
|
||
post_url = f"{parsed_url.scheme}://{parsed_url.hostname}/new" | ||
post_headers = {"Content-Type": "text/markdown"} | ||
|
||
async with aiohttp_client.post( | ||
url=post_url, | ||
headers=post_headers, | ||
data=modified_content, | ||
) as response: | ||
if response.status != 200: | ||
await ctx.respond( | ||
f"❌ Failed to generate the agenda. Status code: `{response.status}`", | ||
flags=hikari.MessageFlag.EPHEMERAL, | ||
) | ||
return | ||
|
||
new_agenda_url = response.url | ||
announce_text = f""" | ||
## 📣 Agenda for this week's meeting | {formatted_datetime} | {room} <:bigRed:634311607039819776> | ||
|
||
|
||
[{formatted_date} Agenda](<{new_agenda_url}>) | ||
|
||
- Please fill in your sections with anything you would like to discuss. | ||
- Put your Redbrick `username` beside any agenda items you add. | ||
- If you can't attend the meeting, please DM <@{UID_MAPS["kronos"]}> with your reason. | ||
- React with <:bigRed:634311607039819776> if you can make it. | ||
|
||
||{role_mention(ROLE_IDS["committee"])}|| | ||
""" | ||
|
||
announce = await plugin.client.rest.create_message( | ||
CHANNEL_IDS["committee-announcements"], | ||
mentions_everyone=False, | ||
user_mentions=True, | ||
role_mentions=True, | ||
content=announce_text, | ||
) | ||
|
||
await plugin.client.rest.add_reaction( | ||
channel=announce.channel_id, | ||
message=announce.id, | ||
emoji=hikari.CustomEmoji.parse("<:bigRed:634311607039819776>"), | ||
) | ||
|
||
# respond with success if it executes successfully | ||
await ctx.respond( | ||
"✅ Agenda generated. Announcement sent successfully!", | ||
flags=hikari.MessageFlag.EPHEMERAL, | ||
) | ||
return | ||
|
||
|
||
@agenda.include | ||
@arc.with_hook(restrict_to_roles(role_ids=[ROLE_IDS["committee"]])) | ||
@arc.slash_subcommand( | ||
"template", | ||
"View the agenda template", | ||
) | ||
async def view_template( | ||
ctx: arc.GatewayContext, | ||
) -> None: | ||
"""View the agenda template""" | ||
url = AGENDA_TEMPLATE_URL | ||
image = "https://cdn.redbrick.dcu.ie/hedgedoc-uploads/sonic-the-hedgedoc.png" | ||
|
||
embed = hikari.Embed( | ||
title="Agenda Template", | ||
url=url, | ||
description="Click the link above to view the agenda template.\n\n **NOTE:** Any edits made to this template will affect the generated agenda.", | ||
colour=0x5865F2, | ||
) | ||
embed = embed.set_image(image) | ||
|
||
await ctx.respond( | ||
embed, | ||
flags=hikari.MessageFlag.EPHEMERAL, | ||
) | ||
|
||
|
||
@arc.loader | ||
def loader(client: arc.GatewayClient) -> None: | ||
client.add_plugin(plugin) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These generated day options will never update, so
today
will always be the day blockbot was started on. The only way around this is using day names instead of dates, or generating options with autocomplete (such as something I've done here).