-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep track of when helpers are last active and prune ones who have no…
…t had activity in the HR Center for 2 months (#851) * new users column & migration, helper activity tracking, timer for autopruning inactive helpers * fix: channel reference, kinder notification msg, compliant loops * Add default value for new column last_helper_activity
- Loading branch information
1 parent
29d4056
commit fc5531f
Showing
5 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
Message, TextChannel, | ||
} from 'discord.js'; | ||
|
||
export default helperActivityUpdate; | ||
|
||
// const F = f(__filename); | ||
|
||
/** | ||
* helperActivityUpdate | ||
* @param {Message} message The message that was sent | ||
* @return {Promise<void>} | ||
* */ | ||
export async function helperActivityUpdate(message: Message): Promise<void> { | ||
if (!message.guild) return; // If not in a guild then ignore all messages | ||
if (message.guild.id !== env.DISCORD_GUILD_ID) return; // If not in tripsit ignore all messages | ||
|
||
// Determine if the message was sent in a TextChannel | ||
if (!(message.channel instanceof TextChannel)) return; | ||
|
||
if (message.channel.parentId !== env.CATEGORY_HARMREDUCTIONCENTRE) return; | ||
|
||
const guildData = await db.discord_guilds.upsert({ | ||
where: { | ||
id: message.guild?.id, | ||
}, | ||
create: { | ||
id: message.guild?.id, | ||
}, | ||
update: {}, | ||
}); | ||
|
||
if (!guildData.role_helper) return; | ||
|
||
const role = await message.guild?.roles.fetch(guildData.role_helper); | ||
|
||
if (!message.member || !role || !message.member.roles.cache.has(role.id)) return; | ||
|
||
await db.users.upsert({ | ||
where: { | ||
discord_id: message.author.id, | ||
}, | ||
create: { | ||
discord_id: message.author.id, | ||
}, | ||
update: { | ||
last_helper_activity: new Date(), | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/prisma/tripbot/migrations/20240930194441_auto_prune_helper/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- AlterTable | ||
ALTER TABLE "users" | ||
ADD COLUMN "last_helper_activity" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters