File tree Expand file tree Collapse file tree 8 files changed +97
-2
lines changed Expand file tree Collapse file tree 8 files changed +97
-2
lines changed Original file line number Diff line number Diff line change 9292 - name : Display the public key
9393 debug :
9494 msg : " For private repositories, make sure to put this key as deploy key on github: {{ deploy_key.content | b64decode }}"
95-
Original file line number Diff line number Diff line change 1515 minute : " 5"
1616 hour : " 6"
1717 job : " make prod/cron/pretix"
18+
19+ - name : " Schedule standup message on Monday morning"
20+ ansible.builtin.cron :
21+ name : " Send a standup message"
22+ minute : " 5"
23+ hour : " 9"
24+ weekday : " 1"
25+ job : " make prod/cron/standup"
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ prod/migrate:
77 $(MAKE_APP) in-container/migrate
88
99prod/shell:
10- $(MAKE_APP) in-container/shell
10+ $(MAKE_APP) in-container/manage ARG="shell_plus"
1111
1212prod/db_shell:
1313 $(MAKE_APP) in-container/db_shell
@@ -22,5 +22,8 @@ prod/cron/pretalx:
2222prod/cron/pretix:
2323 $(MAKE_APP) in-container/manage ARG="download_pretix_data --event=ep2025"
2424
25+ prod/cron/standup:
26+ $(MAKE_APP) in-container/manage ARG="send_scheduled_message --template=standup"
27+
2528logs:
2629 docker compose logs -f
Original file line number Diff line number Diff line change @@ -77,6 +77,12 @@ class Channels:
7777 channel_name = settings .DISCORD_GRANTS_CHANNEL_NAME ,
7878 )
7979
80+ # scheduled messages
81+ standup_channel = DiscordChannel (
82+ channel_id = settings .DISCORD_STANDUP_CHANNEL_ID ,
83+ channel_name = settings .DISCORD_STANDUP_CHANNEL_NAME ,
84+ )
85+
8086
8187def discord_channel_router (wh : Webhook ) -> DiscordChannel :
8288 if wh .source == "github" :
Original file line number Diff line number Diff line change 1+ """
2+ Configuration for all things discord related
3+ """
4+ from django .conf import settings
5+
6+ class Roles :
7+ # We keep this statically defined, because we want to use it in templates
8+ # for scheduled messages, and we want to make the scheduling available
9+ # withotu access to the discord server.
10+ board_member_role_id = settings .DISCORD_BOARD_MEMBER_ROLE_ID
Original file line number Diff line number Diff line change 1+ """
2+ Factory functions for scheduled messages
3+ """
4+
5+ from typing import Dict , Callable
6+
7+ from core .models import DiscordMessage
8+ from core .bot .channel_router import Channels
9+ from core .bot .config import Roles
10+
11+
12+ def standup_message_factory () -> DiscordMessage :
13+ """Factory for weekly standup message."""
14+ content = (
15+ f"## Happy Monday <@&{ Roles .board_member_role_id } >!\n \n "
16+ f"Let's keep everyone in the loop :)\n \n "
17+ f"(1) What you worked on last week\n "
18+ f"(2) What are you planning to work on this week\n "
19+ f"(3) Are there any blockers or where could you use some help?"
20+ )
21+
22+ # Using the test channel for now - replace with appropriate channel later
23+ channel = Channels .standup_channel
24+
25+ return DiscordMessage (
26+ channel_id = channel .channel_id ,
27+ channel_name = channel .channel_name ,
28+ content = content ,
29+ sent_at = None
30+ )
31+
32+
33+ # Registry of message factories
34+ MESSAGE_FACTORIES : Dict [str , Callable [[], DiscordMessage ]] = {
35+ "standup" : standup_message_factory ,
36+ }
Original file line number Diff line number Diff line change 1+ from core .bot .scheduled_messages import MESSAGE_FACTORIES
2+ from django .core .management .base import BaseCommand
3+
4+
5+ class Command (BaseCommand ):
6+ help = "Sends a scheduled message to Discord"
7+
8+ def add_arguments (self , parser ):
9+ parser .add_argument (
10+ "--template" ,
11+ required = True ,
12+ choices = MESSAGE_FACTORIES .keys (),
13+ help = "Message template to send" ,
14+ )
15+
16+ def handle (self , * args , ** options ):
17+ message_template = options ["template" ]
18+
19+ factory = MESSAGE_FACTORIES [message_template ]
20+ message = factory ()
21+ message .save ()
22+
23+ self .stdout .write (
24+ self .style .SUCCESS (
25+ f"Scheduled '{ message_template } ' message for channel { message .channel_name } "
26+ )
27+ )
Original file line number Diff line number Diff line change @@ -178,6 +178,12 @@ def get(name) -> str:
178178DISCORD_GRANTS_CHANNEL_ID = get ("DISCORD_GRANTS_CHANNEL_ID" )
179179DISCORD_GRANTS_CHANNEL_NAME = get ("DISCORD_GRANTS_CHANNEL_NAME" )
180180
181+ DISCORD_STANDUP_CHANNEL_ID = get ("DISCORD_STANDUP_CHANNEL_ID" )
182+ DISCORD_STANDUP_CHANNEL_NAME = get ("DISCORD_STANDUP_CHANNEL_NAME" )
183+
184+ # Discord Roles
185+ DISCORD_BOARD_MEMBER_ROLE_ID = get ("DISCORD_BOARD_MEMBER_ROLE_ID" )
186+
181187# Github
182188GITHUB_API_TOKEN = get ("GITHUB_API_TOKEN" )
183189GITHUB_WEBHOOK_SECRET_TOKEN = get ("GITHUB_WEBHOOK_SECRET_TOKEN" )
You can’t perform that action at this time.
0 commit comments