mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-18 13:34:14 +02:00
feat(arabot): add user to database when they join the server
This commit is contained in:
parent
c976905104
commit
8f60c3eac9
@ -28,6 +28,7 @@ import {
|
||||
} from 'discord.js';
|
||||
import IDs from '#utils/ids';
|
||||
import { checkActive } from '#utils/database/moderation/restriction';
|
||||
import { addUser } from '#utils/database/dbExistingUser';
|
||||
|
||||
export class WelcomeButtonHandler extends InteractionHandler {
|
||||
public constructor(
|
||||
@ -117,6 +118,9 @@ export class WelcomeButtonHandler extends InteractionHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add the user to the database
|
||||
await addUser(member.id);
|
||||
|
||||
// Give the role to the member
|
||||
const role = await member.roles
|
||||
.add(IDs.roles.nonvegan.nonvegan)
|
||||
|
@ -66,6 +66,26 @@ function getRoles(roles: GuildMemberRoleManager) {
|
||||
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
|
||||
* @param {GuildMember} member GuildMember for the user to be added to the database
|
||||
|
Loading…
x
Reference in New Issue
Block a user