mirror of
https://github.com/yuzu-emu/Command-fix.git
synced 2024-12-22 13:35:40 +00:00
common: extract the grantRole function
This commit is contained in:
parent
ffb697c323
commit
c61fafdca0
|
@ -1,6 +1,6 @@
|
|||
import state from '../state';
|
||||
import logger from '../logging';
|
||||
import * as discord from 'discord.js';
|
||||
import { grantRole } from '../common';
|
||||
|
||||
export const roles = ['Admins', 'Moderators', 'CitraBot'];
|
||||
export async function command (message: discord.Message) {
|
||||
|
@ -12,26 +12,9 @@ export async function command (message: discord.Message) {
|
|||
}
|
||||
|
||||
return Promise.all(message.mentions.users.map(async (user) => {
|
||||
return message.guild?.members.fetch(user).then((member) => {
|
||||
const alreadyJoined = member.roles.cache.has(role);
|
||||
|
||||
if (alreadyJoined) {
|
||||
member.roles.remove(role).then(async () => {
|
||||
await message.channel.send(`${user.toString()}'s speech has been revoked in the #development channel.`);
|
||||
}).catch(async () => {
|
||||
await state.logChannel?.send(`Error revoking ${user.toString()}'s developer speech...`);
|
||||
logger.error(`Error revoking ${user.toString()} ${user.username}'s developer speech...`);
|
||||
});
|
||||
} else {
|
||||
member.roles.add(role).then(async () => {
|
||||
await message.channel.send(`${user.toString()} has been granted speech in the #development channel.`);
|
||||
}).catch(async () => {
|
||||
await state.logChannel?.send(`Error granting ${user.toString()}'s developer speech...`);
|
||||
logger.error(`Error granting ${user.toString()} ${user.username}'s developer speech...`);
|
||||
});
|
||||
}
|
||||
}).catch(async () => {
|
||||
await message.channel.send(`User ${user.toString()} was not found in the channel.`);
|
||||
});
|
||||
return message.guild?.members.fetch(user).then((member) => grantRole(member, role, message.channel))
|
||||
.catch(async () => {
|
||||
await message.channel.send(`User ${user.toString()} was not found in the channel.`);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -18,3 +18,26 @@ export async function ban (user: discord.User, moderator: discord.User, guild: d
|
|||
|
||||
data.flushBans();
|
||||
}
|
||||
|
||||
export async function grantRole (member: discord.GuildMember, role: string, channel: discord.TextBasedChannel) {
|
||||
const user = member.user;
|
||||
const roleDisplayName = role.toLowerCase();
|
||||
|
||||
const alreadyJoined = member.roles.cache.has(role);
|
||||
if (alreadyJoined) {
|
||||
member.roles.remove(role).then(async () => {
|
||||
await channel.send(`${user.toString()}'s ${roleDisplayName} role has been revoked.`);
|
||||
}).catch(async () => {
|
||||
await state.logChannel?.send(`Error revoking ${user.toString()}'s ${roleDisplayName} speech...`);
|
||||
logger.error(`Error revoking ${user.toString()} ${user.username}'s ${roleDisplayName} speech...`);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
member.roles.add(role).then(async () => {
|
||||
await channel.send(`${user.toString()} has been granted ${roleDisplayName} speech.`);
|
||||
}).catch(async () => {
|
||||
await state.logChannel?.send(`Error granting ${user.toString()}'s ${roleDisplayName} speech...`);
|
||||
logger.error(`Error granting ${user.toString()} ${user.username}'s ${roleDisplayName} speech...`);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue