diff --git a/events/messageReactionAdd.ts b/events/messageReactionAdd.ts index 3b14e1b..08f1632 100644 --- a/events/messageReactionAdd.ts +++ b/events/messageReactionAdd.ts @@ -1,4 +1,5 @@ import { GuildMember, MessageReaction, TextChannel } from 'discord.js' +import tx2 from 'tx2' import { colors } from '../types/colors' import { DiscordClient } from '../types/customTypes' @@ -19,6 +20,13 @@ const ROLE_REACTION_CHANNELS = [ */ const SDADISDIGEN = '827171746364784671' +/** + * Custom PM2 metric. + */ +const rolesAddedCounter = tx2.counter({ + name: 'Rolles added to users', +}) + exports.run = async (client: DiscordClient, reaction: MessageReaction, user: GuildMember) => { const USER = await reaction.message.guild.members.fetch(user.id) @@ -49,6 +57,7 @@ exports.run = async (client: DiscordClient, reaction: MessageReaction, user: Gui // eslint-disable-next-line max-len `User update: ${colors.fg.Green}Added${colors.special.Reset} role ${colors.special.Bright}${role.name}${colors.special.Reset} to ${USER.displayName}.`, ) + rolesAddedCounter.inc() } } catch (error) { /** diff --git a/events/messageReactionRemove.ts b/events/messageReactionRemove.ts index 63e0761..04287ca 100644 --- a/events/messageReactionRemove.ts +++ b/events/messageReactionRemove.ts @@ -1,4 +1,5 @@ import { GuildMember, MessageReaction, TextChannel } from 'discord.js' +import tx2 from 'tx2' import { colors } from '../types/colors' import { DiscordClient } from '../types/customTypes' @@ -19,6 +20,13 @@ const ROLE_REACTION_CHANNELS = [ */ const SDADISDIGEN = '827171746364784671' +/** + * Custom PM2 metric. + */ +const rolesRemovedCounter = tx2.counter({ + name: 'Rolles added to users', +}) + exports.run = async (client: DiscordClient, reaction: MessageReaction, user: GuildMember) => { const USER = await reaction.message.guild.members.fetch(user.id) if (ROLE_REACTION_CHANNELS.indexOf(reaction.message.channel.id) > -1) { @@ -48,6 +56,7 @@ exports.run = async (client: DiscordClient, reaction: MessageReaction, user: Gui // eslint-disable-next-line max-len `User update: ${colors.fg.Red}Removed${colors.special.Reset} role ${colors.special.Bright}${role.name}${colors.special.Reset} from ${USER.displayName}`, ) + rolesRemovedCounter.inc() } } catch (error) { /** diff --git a/scripts/iCalReader.ts b/scripts/iCalReader.ts index 459dde2..7bdad0b 100644 --- a/scripts/iCalReader.ts +++ b/scripts/iCalReader.ts @@ -2,6 +2,7 @@ import { ColorResolvable, Guild, EmbedBuilder, Snowflake, TextChannel } from 'discord.js' import moment from 'moment' import { RecurrenceRule, scheduleJob } from 'node-schedule' +import tx2 from 'tx2' import { extractZoomLinks, fetchAndCacheCalendars, filterEvents } from '../types/calendar_helper_functions' import { DiscordClient } from '../types/customTypes' @@ -14,6 +15,18 @@ const MS_PER_MINUTE = 60000 const SEND_NOTIFICATION_OFFSET = 20 const DELETE_NOTIFICATIONS_OFFSET = 115 +/** + * Custom PM2 metric. + */ +const scheduledNotifications = tx2.metric({ + name: 'Number of scheduled notifications today', +}) + +/** + * Variable for counting scheduled notifications + */ +let created_notifications = 0 + exports.run = async (client: DiscordClient) => { await fetchAndSend(client) scheduleJob(CRON_FETCH_EVENTS, async () => { @@ -28,6 +41,11 @@ exports.run = async (client: DiscordClient) => { * @returns {Promise} */ async function fetchAndSend(client: DiscordClient): Promise { + /** + * Reset variable for counting scheduled notifications + */ + created_notifications = 0 + /** * Date of current day. */ @@ -229,7 +247,9 @@ function scheduleNotifications(client: DiscordClient, today: Date, events: objec * Schedule notifications. */ createCron(recurrenceRule, channel, role, embed, client) + created_notifications += 1 } + scheduledNotifications.set(created_notifications) } /**