Skip to content

Commit

Permalink
fix(vote): update vote role
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Jan 29, 2024
1 parent aae6882 commit 495dbb0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
12 changes: 3 additions & 9 deletions src/managers/VoteManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { WebhookPayload } from '@top-gg/sdk';
import { stripIndents } from 'common-tags';
import { ClusterManager } from 'discord-hybrid-sharding';
import { WebhookClient, userMention, EmbedBuilder } from 'discord.js';
import { badgeEmojis, LINKS } from '../utils/Constants.js';
import { badgeEmojis, LINKS, SUPPORT_SERVER_ID, VOTER_ROLE_ID } from '../utils/Constants.js';
import { getOrdinalSuffix, getUsername, modifyUserRole } from '../utils/Utils.js';
import { EventEmitter } from 'events';

Expand Down Expand Up @@ -95,15 +95,9 @@ export class VoteManager extends EventEmitter {
}

async addVoterRole(userId: string) {
await modifyUserRole(this.cluster, 'add', userId, '853116027588051022', '1201369361391300719');
await modifyUserRole(this.cluster, 'add', userId, SUPPORT_SERVER_ID, VOTER_ROLE_ID);
}
async removeVoterRole(userId: string) {
await modifyUserRole(
this.cluster,
'remove',
userId,
'853116027588051022',
'1201369361391300719',
);
await modifyUserRole(this.cluster, 'remove', userId, SUPPORT_SERVER_ID, VOTER_ROLE_ID);
}
}
2 changes: 2 additions & 0 deletions src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const isDevBuild = process.env.NODE_ENV === 'development';

export const CLIENT_ID = isDevBuild ? '798748015435055134' : '769921109209907241';
export const SUPPORT_SERVER_ID = '770256165300338709';
export const VOTER_ROLE_ID = '985153241727770655';


// Regexp
export const REGEX = {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
TextChannel,
ThreadChannel,
} from 'discord.js';
import { DeveloperIds, REGEX, StaffIds, SupporterIds, LINKS, colors, emojis } from './Constants.js';
import { DeveloperIds, REGEX, StaffIds, SupporterIds, LINKS, colors, emojis, SUPPORT_SERVER_ID } from './Constants.js';
import { randomBytes } from 'crypto';
import { t } from './Locale.js';
import 'dotenv/config';
Expand Down Expand Up @@ -390,9 +390,9 @@ export const modifyUserRole = async (
const guild = client.guilds.cache.get(ctx.guildId);
const voterRole = guild?.roles.cache.find(({ id }) => id === ctx.roleId);
const member = await guild?.members.fetch(ctx.userId).catch(() => null);
if (!member || !voterRole) return;
if (!guild || !voterRole) return;

// add or remove role
await member.roles[ctx.action](voterRole);
}, { context: { userId, roleId, guildId, action } });
await member?.roles[ctx.action](voterRole).catch(() => null);
}, { guildId: SUPPORT_SERVER_ID, context: { userId, roleId, guildId, action } });
};

0 comments on commit 495dbb0

Please sign in to comment.