Skip to content

Commit

Permalink
ADD: further custom metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Chr1s70ph committed Oct 31, 2022
1 parent d92f813 commit 1e34e9b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions events/messageReactionAdd.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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)

Expand Down Expand Up @@ -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) {
/**
Expand Down
9 changes: 9 additions & 0 deletions events/messageReactionRemove.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
/**
Expand Down
20 changes: 20 additions & 0 deletions scripts/iCalReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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 () => {
Expand All @@ -28,6 +41,11 @@ exports.run = async (client: DiscordClient) => {
* @returns {Promise<void>}
*/
async function fetchAndSend(client: DiscordClient): Promise<void> {
/**
* Reset variable for counting scheduled notifications
*/
created_notifications = 0

/**
* Date of current day.
*/
Expand Down Expand Up @@ -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)
}

/**
Expand Down

0 comments on commit 1e34e9b

Please sign in to comment.