Skip to content

Commit 314c151

Browse files
committed
improved cron messages
1 parent 0c5e914 commit 314c151

File tree

8 files changed

+53
-36
lines changed

8 files changed

+53
-36
lines changed

deploy/playbooks/03_app.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,5 @@
4545
- name: Migrate on prod
4646
shell: "make prod/migrate"
4747

48-
- name: Configure scheduled message for standup
49-
become: yes
50-
cron:
51-
name: "Monday standup message"
52-
user: "{{ app_user }}"
53-
minute: "0"
54-
hour: "11"
55-
weekday: "1"
56-
job: "cd /home/{{ app_user }} && docker compose exec -T app make in-container/manage ARG='send_scheduled_message --type=standup'"
57-
state: present
58-
5948
- name: Restart everything and finish
6049
shell: "docker compose up -d"

deploy/playbooks/04_cron.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@
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"

deploy/templates/app/Makefile.app.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ prod/migrate:
77
$(MAKE_APP) in-container/migrate
88

99
prod/shell:
10-
$(MAKE_APP) in-container/shell
10+
$(MAKE_APP) in-container/manage ARG="shell_plus"
1111

1212
prod/db_shell:
1313
$(MAKE_APP) in-container/db_shell
@@ -22,5 +22,8 @@ prod/cron/pretalx:
2222
prod/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+
2528
logs:
2629
docker compose logs -f

intbot/core/bot/channel_router.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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

8187
def discord_channel_router(wh: Webhook) -> DiscordChannel:
8288
if wh.source == "github":

intbot/core/bot/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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

intbot/core/bot/scheduled_messages.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,23 @@
44

55
from typing import Dict, Callable
66

7-
from django.utils import timezone
8-
97
from core.models import DiscordMessage
108
from core.bot.channel_router import Channels
9+
from core.bot.config import Roles
1110

1211

1312
def standup_message_factory() -> DiscordMessage:
1413
"""Factory for weekly standup message."""
15-
today = timezone.now()
16-
week_number = today.isocalendar()[1]
17-
1814
content = (
19-
f"## Monday Standup - Week {week_number}\n\n"
20-
f"Good morning team! Please share:\n\n"
21-
f"1. What you accomplished last week\n"
22-
f"2. What you're planning for this week\n"
23-
f"3. Any blockers or assistance needed"
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?"
2420
)
2521

2622
# Using the test channel for now - replace with appropriate channel later
27-
channel = Channels.test_channel
23+
channel = Channels.standup_channel
2824

2925
return DiscordMessage(
3026
channel_id=channel.channel_id,
@@ -37,4 +33,4 @@ def standup_message_factory() -> DiscordMessage:
3733
# Registry of message factories
3834
MESSAGE_FACTORIES: Dict[str, Callable[[], DiscordMessage]] = {
3935
"standup": standup_message_factory,
40-
}
36+
}
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
from django.core.management.base import BaseCommand
2-
31
from core.bot.scheduled_messages import MESSAGE_FACTORIES
2+
from django.core.management.base import BaseCommand
43

54

65
class Command(BaseCommand):
76
help = "Sends a scheduled message to Discord"
8-
7+
98
def add_arguments(self, parser):
109
parser.add_argument(
11-
"--type",
10+
"--template",
1211
required=True,
1312
choices=MESSAGE_FACTORIES.keys(),
14-
help="Message type to send"
13+
help="Message template to send",
1514
)
16-
15+
1716
def handle(self, *args, **options):
18-
message_type = options["type"]
19-
20-
factory = MESSAGE_FACTORIES[message_type]
17+
message_template = options["template"]
18+
19+
factory = MESSAGE_FACTORIES[message_template]
2120
message = factory()
2221
message.save()
23-
22+
2423
self.stdout.write(
2524
self.style.SUCCESS(
26-
f"Scheduled '{message_type}' message for channel {message.channel_name}"
25+
f"Scheduled '{message_template}' message for channel {message.channel_name}"
2726
)
28-
)
27+
)

intbot/intbot/settings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ def get(name) -> str:
178178
DISCORD_GRANTS_CHANNEL_ID = get("DISCORD_GRANTS_CHANNEL_ID")
179179
DISCORD_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
182188
GITHUB_API_TOKEN = get("GITHUB_API_TOKEN")
183189
GITHUB_WEBHOOK_SECRET_TOKEN = get("GITHUB_WEBHOOK_SECRET_TOKEN")

0 commit comments

Comments
 (0)