Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.
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: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RA_USER=
RA_TOKEN=
RA_WEB_API_KEY=

#role IDs for "self role management"
# always use role IDs (avoid problems if a role is renamed)
NEWS_ROLES=
ACHIEVEMENT_NEWS=
COMMUNITY_NEWS=
Expand All @@ -18,6 +18,7 @@ EVENT_NEWS=
DEVELOPER_NEWS=
REVISION_VOTING=
ROLE_MOD=
ROLE_AOTW=

YOUTUBE_API_KEY=

Expand Down
83 changes: 83 additions & 0 deletions commands/mod/removeaotw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const logger = require('pino')({
useLevelLabels: true,
timestamp: () => `,"time":"${new Date()}"`,
});

const { ROLE_MOD, AOTW_ROLE_ID } = process.env;
const Command = require('../../structures/Command.js');

module.exports = class RemoveAOTWCommand extends Command {
constructor(client) {
super(client, {
name: 'removeaotw',
group: 'mod',
memberName: 'removeaotw',
aliases: ['aotwremove'],
description: 'Removes the AOTW Winner role from designated user.',
examples:['!removeaotw @user', '!removeaotw'],
args: [
{
key: 'username',
prompt: 'Who would you like to have the role removed from?',
type: 'user',
default: '',
},
],
});
}

async run(msg, { username }) {
// check if AOTW WINNER role exists on the channel
const aotwRole = await msg.guild.roles.get(AOTW_ROLE_ID);
// check if requesting user is mod user
const isMod = await msg.member.roles.has(ROLE_MOD);

if(!isMod){
return;
}

if (username !== '') {
// check if the requested user to be given role exists
const user = await msg.guild.fetchMember(username);

const hasAOTW = await user.roles.has(AOTW_ROLE_ID);

// if the the user has the role, if not do nothing
if (!hasAOTW) {
return;
}

// if all checks pass give the role to the user
if (user && aotwRole) {
// remove role from the user
await user.removeRole(aotwRole).catch(logger.error);
logger.info({ msg: `@Mod ${msg.member.displayName} removed ${aotwRole.name} from ${user.displayName}` });
msg.say(`**${aotwRole.name}** has been removed from user **${user.displayName}**.`);
}
} else {
await msg.channel.send('Are you sure you want to remove from all users? Please confirm with `yes` or `y` if so.');

const filter = (res) => res.content.includes('yes') || res.content.toLowerCase() === 'y';

const msgs = await msg.channel.awaitMessages(filter, {
max: 1,
time: 3000,
});

if (msgs.size) {
const users = msg.guild.members;
let aotwUsers = 0;
users.forEach(async (user) => {
if (user.roles.has(AOTW_ROLE_ID)) {
aotwUsers += 1;
await user.removeRole(aotwRole);
}
});
logger.info({ msg: `@Mod ${msg.member.displayName} removed ${aotwRole.name} from ${aotwUsers} users` });
msg.say(`**${aotwRole.name}** role has been removed from **${aotwUsers}** users.`);
} else {
msg.say('Cancelled command.');
}
}
}
};
63 changes: 63 additions & 0 deletions commands/mod/setaotw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const logger = require('pino')({
useLevelLabels: true,
timestamp: () => `,"time":"${new Date()}"`,
});

const { ROLE_MOD, ROLE_AOTW } = process.env;
const Command = require('../../structures/Command.js');

module.exports = class SetAotwCommand extends Command {
constructor(client) {
super(client, {
name: 'setaotw',
group: 'mod',
guildOnly: true,
memberName: 'setaotw',
description: 'Offers AotW Winner role to designated user.',
examples: ['!setaotw @user'],
args: [
{
key: 'username',
prompt: 'Who would you like to give the role to?',
type: 'user',
},
],
});
}

async run(msg, { username }) {
const callerIsMod = await msg.member.roles.has(ROLE_MOD);
if (!callerIsMod) {
return msg.reply('Only moderators can use such command.');
}

const aotwRole = await msg.guild.roles.get(ROLE_AOTW);
if (!aotwRole) {
return msg.reply(
":warning: Looks like there's no role for AotW winners in this server (or maybe I just don't know the role ID).",
);
}

const user = await msg.guild.fetchMember(username);
// no need to check for success, the args config in the constructor guarantees that 'username' is valid.

const userHasAotw = await user.roles.has(ROLE_AOTW);
if (userHasAotw) {
return msg.reply(`The user **${user.displayName}** already has the **${aotwRole.name}** role.`);
}

return user.addRole(aotwRole)
.then(() => {
logger.info(
{ msg: `@Mod ${msg.member.displayName} added ${aotwRole.name} to ${user.displayName}` },
);
msg.say(
`:trophy: Congratulations **${user.displayName}**. You have been awarded **${aotwRole.name}** role!`,
);
})
.catch((err) => {
logger.error(err);
msg.reply(`I wasn't able to give the **${aotwRole.name}** role to **${user.displayName}**... :frowning2:`);
});
}
};