Skip to content

Commit a4d4bbd

Browse files
authored
Merge pull request #98 from mxmeinhold/develop
Implements sending slack message upon 💯
2 parents 6a7b50c + f8d6136 commit a4d4bbd

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

config.env.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@
2121
# LDAP config
2222
LDAP_BIND_DN = environ.get("PACKET_LDAP_BIND_DN", None)
2323
LDAP_BIND_PASS = environ.get("PACKET_LDAP_BIND_PASS", None)
24+
25+
# Slack URL for pushing to #general
26+
SLACK_WEBHOOK_URL = environ.get("PACKET_SLACK_URL", None)

packet/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ def did_sign(self, username, is_csh):
103103
# The user must be a misc CSHer that hasn't signed this packet or an off-floor freshmen
104104
return False
105105

106+
107+
def is_100(self):
108+
"""
109+
Checks if this packet has reached 100%
110+
"""
111+
return self.signatures_required().total == self.signatures_recieved().total
112+
113+
106114
@classmethod
107115
def open_packets(cls):
108116
"""

packet/routes/api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from packet import app, db
2-
from packet.utils import before_request, packet_auth
2+
from packet.utils import before_request, packet_auth, notify_slack
33
from packet.models import Packet, MiscSignature
44

55

@@ -10,22 +10,29 @@ def sign(packet_id, info):
1010
packet = Packet.by_id(packet_id)
1111

1212
if packet is not None and packet.is_open():
13+
was_100 = packet.is_100()
1314
if app.config["REALM"] == "csh":
1415
# Check if the CSHer is an upperclassman and if so, sign that row
1516
for sig in filter(lambda sig: sig.member == info["uid"], packet.upper_signatures):
1617
sig.signed = True
1718
db.session.commit()
19+
if not was_100 and packet.is_100():
20+
notify_slack(packet.freshman.name)
1821
return "Success: Signed Packet: " + packet.freshman_username
1922

2023
# The CSHer is a misc so add a new row
2124
db.session.add(MiscSignature(packet=packet, member=info["uid"]))
2225
db.session.commit()
26+
if not was_100 and packet.is_100():
27+
notify_slack(packet.freshman.name)
2328
return "Success: Signed Packet: " + packet.freshman_username
2429
else:
2530
# Check if the freshman is onfloor and if so, sign that row
2631
for sig in filter(lambda sig: sig.freshman_username == info["uid"], packet.fresh_signatures):
2732
sig.signed = True
2833
db.session.commit()
34+
if not was_100 and packet.is_100():
35+
notify_slack(packet.freshman.name)
2936
return "Success: Signed Packet: " + packet.freshman_username
3037

3138
return "Error: Signature not valid. Reason: Unknown"

packet/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,13 @@ def wrapped_function(*args, **kwargs):
8585
return func(*args, **kwargs)
8686

8787
return wrapped_function
88+
89+
def notify_slack(name: str):
90+
"""
91+
Sends a congratulate on sight decree to Slack.
92+
"""
93+
if app.config["SLACK_WEBHOOK_URL"] is None:
94+
print("SLACK_WEBHOOK_URL not configured, not sending message to slack.")
95+
return
96+
msg = f'{name} got :100: on packet. Shower on sight.'
97+
requests.put(app.config["SLACK_WEBHOOK_URL"], json={'text':msg})

0 commit comments

Comments
 (0)