feat(arabot): add user to database when they join the server

This commit is contained in:
Anthony Berg 2025-01-18 12:38:34 +01:00
parent c976905104
commit 8f60c3eac9
2 changed files with 24 additions and 0 deletions

View File

@ -28,6 +28,7 @@ import {
} from 'discord.js'; } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
import { checkActive } from '#utils/database/moderation/restriction'; import { checkActive } from '#utils/database/moderation/restriction';
import { addUser } from '#utils/database/dbExistingUser';
export class WelcomeButtonHandler extends InteractionHandler { export class WelcomeButtonHandler extends InteractionHandler {
public constructor( public constructor(
@ -117,6 +118,9 @@ export class WelcomeButtonHandler extends InteractionHandler {
return; return;
} }
// Add the user to the database
await addUser(member.id);
// Give the role to the member // Give the role to the member
const role = await member.roles const role = await member.roles
.add(IDs.roles.nonvegan.nonvegan) .add(IDs.roles.nonvegan.nonvegan)

View File

@ -66,6 +66,26 @@ function getRoles(roles: GuildMemberRoleManager) {
return rolesDict; return rolesDict;
} }
/**
* Adds a new user to the server
* @param userId the `User` snowflake to be added to the database
*/
export async function addUser(userId: Snowflake) {
// Uses upsert just in case the user has joined the server previously but has not gotten the roles previously
await container.database.user.upsert({
where: {
id: userId,
},
update: {
notVegan: true,
},
create: {
id: userId,
notVegan: true,
},
});
}
/** /**
* Add user to the database, if they have not been added beforehand * Add user to the database, if they have not been added beforehand
* @param {GuildMember} member GuildMember for the user to be added to the database * @param {GuildMember} member GuildMember for the user to be added to the database