Skip to content

Feature/scheduled messages #37

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

Merged
merged 3 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion deploy/playbooks/01_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,3 @@
- name: Display the public key
debug:
msg: "For private repositories, make sure to put this key as deploy key on github: {{ deploy_key.content | b64decode }}"

8 changes: 8 additions & 0 deletions deploy/playbooks/04_cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@
minute: "5"
hour: "6"
job: "make prod/cron/pretix"

- name: "Schedule standup message on Monday morning"
ansible.builtin.cron:
name: "Send a standup message"
minute: "5"
hour: "9"
weekday: "1"
job: "make prod/cron/standup"
5 changes: 4 additions & 1 deletion deploy/templates/app/Makefile.app.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ prod/migrate:
$(MAKE_APP) in-container/migrate

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

prod/db_shell:
$(MAKE_APP) in-container/db_shell
Expand All @@ -22,5 +22,8 @@ prod/cron/pretalx:
prod/cron/pretix:
$(MAKE_APP) in-container/manage ARG="download_pretix_data --event=ep2025"

prod/cron/standup:
$(MAKE_APP) in-container/manage ARG="send_scheduled_message --template=standup"

logs:
docker compose logs -f
6 changes: 6 additions & 0 deletions intbot/core/bot/channel_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class Channels:
channel_name=settings.DISCORD_GRANTS_CHANNEL_NAME,
)

# scheduled messages
standup_channel = DiscordChannel(
channel_id=settings.DISCORD_STANDUP_CHANNEL_ID,
channel_name=settings.DISCORD_STANDUP_CHANNEL_NAME,
)


def discord_channel_router(wh: Webhook) -> DiscordChannel:
if wh.source == "github":
Expand Down
10 changes: 10 additions & 0 deletions intbot/core/bot/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
Configuration for all things discord related
"""
from django.conf import settings

class Roles:
# We keep this statically defined, because we want to use it in templates
# for scheduled messages, and we want to make the scheduling available
# withotu access to the discord server.
board_member_role_id = settings.DISCORD_BOARD_MEMBER_ROLE_ID
36 changes: 36 additions & 0 deletions intbot/core/bot/scheduled_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Factory functions for scheduled messages
"""

from typing import Dict, Callable

from core.models import DiscordMessage
from core.bot.channel_router import Channels
from core.bot.config import Roles


def standup_message_factory() -> DiscordMessage:
"""Factory for weekly standup message."""
content = (
f"## Happy Monday <@&{Roles.board_member_role_id}>!\n\n"
f"Let's keep everyone in the loop :)\n\n"
f"(1) What you worked on last week\n"
f"(2) What are you planning to work on this week\n"
f"(3) Are there any blockers or where could you use some help?"
)

# Using the test channel for now - replace with appropriate channel later
channel = Channels.standup_channel

return DiscordMessage(
channel_id=channel.channel_id,
channel_name=channel.channel_name,
content=content,
sent_at=None
)


# Registry of message factories
MESSAGE_FACTORIES: Dict[str, Callable[[], DiscordMessage]] = {
"standup": standup_message_factory,
}
27 changes: 27 additions & 0 deletions intbot/core/management/commands/send_scheduled_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from core.bot.scheduled_messages import MESSAGE_FACTORIES
from django.core.management.base import BaseCommand


class Command(BaseCommand):
help = "Sends a scheduled message to Discord"

def add_arguments(self, parser):
parser.add_argument(
"--template",
required=True,
choices=MESSAGE_FACTORIES.keys(),
help="Message template to send",
)

def handle(self, *args, **options):
message_template = options["template"]

factory = MESSAGE_FACTORIES[message_template]
message = factory()
message.save()

self.stdout.write(
self.style.SUCCESS(
f"Scheduled '{message_template}' message for channel {message.channel_name}"
)
)
6 changes: 6 additions & 0 deletions intbot/intbot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ def get(name) -> str:
DISCORD_GRANTS_CHANNEL_ID = get("DISCORD_GRANTS_CHANNEL_ID")
DISCORD_GRANTS_CHANNEL_NAME = get("DISCORD_GRANTS_CHANNEL_NAME")

DISCORD_STANDUP_CHANNEL_ID = get("DISCORD_STANDUP_CHANNEL_ID")
DISCORD_STANDUP_CHANNEL_NAME = get("DISCORD_STANDUP_CHANNEL_NAME")

# Discord Roles
DISCORD_BOARD_MEMBER_ROLE_ID = get("DISCORD_BOARD_MEMBER_ROLE_ID")

# Github
GITHUB_API_TOKEN = get("GITHUB_API_TOKEN")
GITHUB_WEBHOOK_SECRET_TOKEN = get("GITHUB_WEBHOOK_SECRET_TOKEN")
Expand Down