diff --git a/packet/commands.py b/packet/commands.py index 4237c61f..ccfc8e3a 100644 --- a/packet/commands.py +++ b/packet/commands.py @@ -8,6 +8,7 @@ import click from packet.mail import send_start_packet_mail +from packet.notifications import packet_starting_notification, packets_starting_notification from . import app, db from .models import Freshman, Packet, FreshSignature, UpperSignature, MiscSignature from .ldap import ldap_get_eboard_role, ldap_get_active_rtps, ldap_get_3das, ldap_get_webmasters, \ @@ -125,6 +126,9 @@ def create_packets(freshmen_csv): c_m = ldap_get_constitutional_maintainers() drink = ldap_get_drink_admins() + # Packet starting notifications + packets_starting_notification(start) + # Create the new packets and the signatures for each freshman in the given CSV freshmen_in_csv = parse_csv(freshmen_csv) print("Creating DB entries and sending emails...") @@ -132,6 +136,7 @@ def create_packets(freshmen_csv): packet = Packet(freshman=freshman, start=start, end=end) db.session.add(packet) send_start_packet_mail(packet) + packet_starting_notification(packet) for member in all_upper: sig = UpperSignature(packet=packet, member=member.uid) diff --git a/packet/notifications.py b/packet/notifications.py index 8d11449b..5eea9d73 100644 --- a/packet/notifications.py +++ b/packet/notifications.py @@ -39,7 +39,6 @@ def packet_signed_notification(packet, signer): def packet_100_percent_notification(packet): member_subscriptions = NotificationSubscription.query.filter(NotificationSubscription.member.isnot(None)) intro_subscriptions = NotificationSubscription.query.filter(NotificationSubscription.freshman_username.isnot(None)) - if member_subscriptions or intro_subscriptions: notification_body = post_body notification_body["contents"]["en"] = packet.freshman.name + ' got 💯 on packet!' @@ -49,3 +48,26 @@ def packet_100_percent_notification(packet): send_notification(notification_body, member_subscriptions, csh_onesignal_client) send_notification(notification_body, intro_subscriptions, intro_onesignal_client) + + +def packet_starting_notification(packet): + subscriptions = NotificationSubscription.query.filter_by(freshman_username=packet.freshman_username) + if subscriptions: + notification_body = post_body + notification_body["contents"]["en"] = 'Log into your packet, and get started meeting people!' + notification_body["headings"]["en"] = 'Your packet has begun!' + notification_body["url"] = app.config["PROTOCOL"] + app.config["PACKET_INTRO"] + notification_body["send_after"] = packet.start.strftime("%Y-%m-%d %H:%M:%S") + + send_notification(notification_body, subscriptions, intro_onesignal_client) + + +def packets_starting_notification(start_date): + member_subscriptions = NotificationSubscription.query.filter(NotificationSubscription.member.isnot(None)) + if member_subscriptions: + notification_body = post_body + notification_body["contents"]["en"] = 'New packets have started, visit packet to see them!' + notification_body["headings"]["en"] = 'Packets Start Today!' + notification_body["send_after"] = start_date.strftime("%Y-%m-%d %H:%M:%S") + + send_notification(notification_body, member_subscriptions, csh_onesignal_client)