Skip to content

Commit cef33ab

Browse files
committed
misc: docker ci to automatically push new images and update to accountinfo, more accurately showing membership statuses and correct time zone
1 parent 6ed3d16 commit cef33ab

File tree

3 files changed

+84
-15
lines changed

3 files changed

+84
-15
lines changed

.github/workflows/docker.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Build and publish new Docker image
2+
on:
3+
push:
4+
branches: main
5+
6+
jobs:
7+
# Build and push the latest image
8+
docker-publish:
9+
name: "Docker build and push image"
10+
runs-on: ubuntu-latest
11+
steps:
12+
- # Login to Docker Hub
13+
name: Login to Docker Hub
14+
uses: docker/login-action@v3
15+
with:
16+
username: ${{ secrets.USERNAME }}
17+
password: ${{ secrets.PAT }}
18+
19+
- # Docker Buildx
20+
name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v3
22+
23+
- # Build and push latest image
24+
name: Docker build and push
25+
uses: docker/build-push-action@v6
26+
with:
27+
push: true
28+
tags: ${{ secrets.USERNAME }}/ntnui-membership-bot:latest,${{ secrets.USERNAME }}/ntnui-membership-bot:${{ github.sha }}

commands/functionality/accountinfo.js

+53-15
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,72 @@ module.exports = {
2020

2121
const valid = accountInfo.get("has_valid_group_membership");
2222

23-
const expiry_date = DateTime.fromISO(
24-
accountInfo.get("ntnui_contract_expiry_date")
23+
const expiryDate = DateTime.fromISO(
24+
accountInfo.get("ntnui_contract_expiry_date"),
25+
{ setZone: true }
2526
)
2627
.setZone("Europe/Oslo")
27-
.setLocale("en")
28-
.toFormat("DDD");
28+
.setLocale("en");
29+
if (!expiryDate.isValid) {
30+
return interaction.editReply({
31+
content: `❌ There was an error processing your membership expiry date.`,
32+
flags: MessageFlags.Ephemeral,
33+
});
34+
}
35+
36+
const ntnuiExpiryDate = expiryDate.toFormat("DDD");
2937

30-
const registry_date = DateTime.fromISO(accountInfo.get("createdAt"))
38+
const registryDateTime = DateTime.fromISO(accountInfo.get("createdAt"), {
39+
setZone: true,
40+
})
3141
.setZone("Europe/Oslo")
32-
.setLocale("en")
33-
.toFormat("DDD', 'T");
42+
.setLocale("en");
43+
44+
if (!registryDateTime.isValid) {
45+
return interaction.editReply({
46+
content: `❌ There was an error processing your membership registry date.`,
47+
flags: MessageFlags.Ephemeral,
48+
});
49+
}
50+
51+
const registryDate = registryDateTime.toFormat("DDD', 'T");
3452

35-
const updateDateTime = DateTime.fromISO(accountInfo.get("updatedAt"))
53+
const updateDateTime = DateTime.fromISO(accountInfo.get("updatedAt"), {
54+
setZone: true,
55+
})
3656
.setZone("Europe/Oslo")
3757
.setLocale("en");
3858

39-
const update_date = updateDateTime.toFormat("DDD', 'T");
59+
if (!updateDateTime.isValid) {
60+
return interaction.editReply({
61+
content: `❌ There was an error processing your membership update date.`,
62+
flags: MessageFlags.Ephemeral,
63+
});
64+
}
65+
66+
const updateDate = updateDateTime.toFormat("DDD', 'T");
4067
const timestamp = updateDateTime.toFormat("X");
4168

42-
if (!valid) {
69+
const now = DateTime.now().setZone("Europe/Oslo");
70+
71+
if (expiryDate < now) {
72+
// Both memberships expired (until NTNUI membership is renewed)
4373
return interaction.editReply({
44-
content: `⌛ Your membership has expired.\n\n🕒 You registered at ${registry_date}.\n🔃 Updated at ${update_date} (${timestamp}).`,
74+
content: `⌛ Your **${process.env.GROUP_NAME}** and **NTNUI** membership have expired.\n\n🕒 You linked your Discord account to NTNUI at ${registryDate}.\n🔃 Updated at ${updateDate} (${timestamp}).`,
75+
flags: MessageFlags.Ephemeral,
76+
});
77+
} else if (!valid) {
78+
// Group membership expired
79+
return interaction.editReply({
80+
content: `⌛ Your **${process.env.GROUP_NAME}** membership has expired. Your **NTNUI** membership expires ${ntnuiExpiryDate}. \n\n🕒 You linked your Discord account to NTNUI at ${registryDate}.\n🔃 Updated at ${updateDate} (${timestamp}).`,
81+
flags: MessageFlags.Ephemeral,
82+
});
83+
} else {
84+
// Both memberships in good standing
85+
return interaction.editReply({
86+
content: `✅ Your **${process.env.GROUP_NAME}** membership is in good standing!\n⏳ Your **NTNUI** membership expires ${ntnuiExpiryDate}\n\n🕒 You linked your Discord account to NTNUI at ${registryDate}.\n🔃 Updated at ${updateDate} (${timestamp}).`,
4587
flags: MessageFlags.Ephemeral,
4688
});
4789
}
48-
return interaction.editReply({
49-
content: `⏳ Your membership expires ${expiry_date}\n\n🕒 You registered at ${registry_date}.\n🔃 Updated at ${update_date} (${timestamp}).`,
50-
flags: MessageFlags.Ephemeral,
51-
});
5290
},
5391
};

scheduler.js

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ function refreshSchedule(client) {
1010

1111
const membershipMap = await fetchMemberships();
1212
// iterate over every membership in group
13+
if (!membershipMap) {
14+
return console.log("Schedule could not run, membershipMap is empty.");
15+
}
1316
for (const membership of membershipMap.values()) {
1417
const currentRow = await Membership.findOne({
1518
ntnui_no: membership.ntnui_no,

0 commit comments

Comments
 (0)