mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-18 17:24: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';
|
} 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)
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user