Skip to content

Commit

Permalink
Modularise Notification Processing
Browse files Browse the repository at this point in the history
  • Loading branch information
theAkito committed Aug 27, 2023
1 parent 493b893 commit d6c81ba
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ No need for manual invitations.
## How
First, check out [how to get access to Zoom's API](HOW-TO-ZOOM-API.md).

Second, prepare system for Redis.

```
option="vm.overcommit_memory=1"
sudo sysctl -w "{option}"
sudo echo "{option}" >> /etc/sysctl.conf
```

Run the `docker-compose.yml`, after adjusting its values & setting up your personalised Zoom Meetings configuration.

## Where
Expand All @@ -26,8 +34,7 @@ Linux via Docker
* Reliability

## Project Status
Beta.
Testing API.
Production

## TODO
* ~~Support E-Mail~~
Expand All @@ -48,6 +55,7 @@ Testing API.
* ~~Save Contexts in Database~~
* ~~Make Meta Options configurable via Configuration File~~
* ~~Fix ambiguous Identifier~~
* Publish Configuration File Documentation
* Publish via [Nimble](https://nimble.directory/)

## License
Expand Down
55 changes: 31 additions & 24 deletions src/zoominvitr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ when isMainModule:
logger.log(lvlInfo, &"""Loading Zoom response for "E-Mail: {auth.mail}; User ID: {auth.userID}" from database, because last response was received at "{respondedLast.formatWithTimezone(ctx.timeZone)}"!""")
databaseZoomResponseMeetings.parseJson
else:
logger.log(lvlInfo, &"""Loading Zoom response for ""E-Mail: {auth.mail}; User ID: {auth.userID}" from Zoom API, because last response was received at "{respondedLast.formatWithTimezone(ctx.timeZone)}"!""")
logger.log(lvlInfo, &"""Loading Zoom response for "E-Mail: {auth.mail}; User ID: {auth.userID}" from Zoom API, because last response was received at "{respondedLast.formatWithTimezone(ctx.timeZone)}"!""")
let
userMail = auth.mail
mailToID = {
Expand Down Expand Up @@ -172,32 +172,39 @@ when isMainModule:
logger.log lvlDebug, "===================meetingsMatchedYes==================="
logger.log lvlDebug, pretty %meetingsMatchedYes

if ctx.mail.enable:
proc processSendMail(topic: string, timeType: ConfigPushScheduleTimeType, timeAmount: int, dryRun = (dryRunMail or config.getSettingsDebug.dryRunMail.get(false))) =
let
timeTypeStr = $timeType
tplStrBefore = &"{timeAmount} {timeTypeStr} before the meeting"
duration = case timeType:
of ConfigPushScheduleTimeType.DAYS:
initDuration(days = timeAmount)
of ConfigPushScheduleTimeType.HOURS:
initDuration(hours = timeAmount)
of ConfigPushScheduleTimeType.MINUTES:
initDuration(minutes = timeAmount)
timeUnitsBefore = nextMeetingStartTime - duration
if timeUnitsBefore < now():
if timeUnitsBefore < notifiedLast.toDateTime:
logger.log(lvlInfo, &"""Meeting "{topic}" at "{nextMeetingStartTimeStr}" for the notification at "{tplStrBefore}" was already notified about!""")
return
else:
let debugEchoMail = config.getSettingsDebug.echoMail.get(false)
if dryRun: ctx.sendMailDryRun(nextMeeting, debugEchoMail)
else: ctx.sendMail(nextMeeting, debugEchoMail)
ctx.zoom.saveNotified
proc getTimeUnitsBefore(timeType: ConfigPushScheduleTimeType, timeAmount: int): DateTime =
let duration = case timeType:
of ConfigPushScheduleTimeType.DAYS:
initDuration(days = timeAmount)
of ConfigPushScheduleTimeType.HOURS:
initDuration(hours = timeAmount)
of ConfigPushScheduleTimeType.MINUTES:
initDuration(minutes = timeAmount)
nextMeetingStartTime - duration

proc process(topic: string, timeType: ConfigPushScheduleTimeType, timeAmount: int, notificationType: string, task: proc()) =
let
timeTypeStr = $timeType
tplStrBefore = &"{timeAmount} {timeTypeStr} before the meeting"
timeUnitsBefore = getTimeUnitsBefore(timeType, timeAmount)
if timeUnitsBefore < now():
if timeUnitsBefore < notifiedLast.toDateTime:
logger.log(lvlInfo, &"""Meeting "{topic}" at "{nextMeetingStartTimeStr}" for the notification of type "{notificationType}" at "{tplStrBefore}" was already notified about!""")
return
else:
logger.log(lvlInfo, &"""Meeting "{topic}" at "{nextMeetingStartTimeStr}" for the notification at "{tplStrBefore}" will not be notified about, yet, because the time has not yet arrived!""")
task()
else:
logger.log(lvlInfo, &"""Meeting "{topic}" at "{nextMeetingStartTimeStr}" for the notification of type "{notificationType}" at "{tplStrBefore}" will not be notified about, yet, because the time has not yet arrived!""")

if ctx.mail.enable:
proc processSendMail(topic: string, timeType: ConfigPushScheduleTimeType, timeAmount: int, dryRun = (dryRunMail or config.getSettingsDebug.dryRunMail.get(false))) =
let debugEchoMail = config.getSettingsDebug.echoMail.get(false)
process(topic, timeType, timeAmount, "E-Mail") do:
if dryRun: ctx.sendMailDryRun(nextMeeting, debugEchoMail)
else: ctx.sendMail(nextMeeting, debugEchoMail)
ctx.zoom.saveNotified
for sched in schedulesSorted:
processSendMail(nextMeeting.topic, sched.tType, sched.amount)

sleep 10000
sleep 60_000

0 comments on commit d6c81ba

Please sign in to comment.