Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign or re-assign level role on join. #877

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/discord/events/guildMemberAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
} from '../@types/eventDef';

import trust from '../utils/trust';
import { giveMilestone } from '../../global/utils/experience';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const F = f(__filename);
Expand All @@ -29,6 +30,8 @@ export const guildMemberAdd: GuildMemberAddEvent = {

if (!guildData.cooperative) return;

// Assign level role upon join. Re-assigns if they had a role previously.
await giveMilestone(member, true);
await trust(member);
} catch (err) {
log.error(F, `Error: ${err}`);
Expand Down
9 changes: 3 additions & 6 deletions src/global/utils/experience.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export async function getTotalLevel(

export async function giveMilestone(
member:GuildMember,
newMember = false,
) {
const userData = await db.users.upsert({
where: {
Expand Down Expand Up @@ -188,7 +189,7 @@ export async function giveMilestone(
if (!member.roles.cache.has(role.id)) {
// log.debug(F, `Giving ${member.displayName} role ${role.name} (${role.id})`);
await member.roles.add(role);
if (levelTier >= 2) {
if (levelTier >= 2 && !newMember) {
const channel = await member.guild?.channels.fetch(env.CHANNEL_VIPLOUNGE) as TextChannel;
await channel.send(`${emojis} **${member} has reached Total level ${levelTier}0!** ${emojis}`);
}
Expand Down Expand Up @@ -250,11 +251,7 @@ export async function experience(
await db.user_experience.create({
data: newUser,
});
if (type === 'TEXT') {
// Give the user the VIP 0 role the first time they talk
const role = await channel.guild?.roles.fetch(env.ROLE_VIP_0) as Role;
await member.roles.add(role);
}

return;
}

Expand Down
Loading