Skip to content

Commit

Permalink
feat: add /deletestatusrole
Browse files Browse the repository at this point in the history
- remove functionality from /setstatusrole
- fix: disallow @everyone for /setstatusrole

Closes: #88
  • Loading branch information
tippfehlr committed Aug 30, 2024
1 parent 1ea0154 commit 5ea3c1f
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 84 deletions.
9 changes: 9 additions & 0 deletions locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,14 @@
"reset": {
"description": "resets the bot for this guild",
"confirmationPrompt": ":warning: You are about to reset the whole bot including all your activity roles. Roles will not be removed from members, and the bot will not remove them even if you create a new Activity Role.\nThis is normally not necessary! Are you _**absolutely**_ sure?"
},
"deleteStatusRole": {
"description": "deletes a status role",
"eventOptionDescription": "the status role to delete",
"success": "Deleted status role for %s",
"noStatusRole": "There is no status role for %s"
},
"setStatusRole": {
"roleNotValid": "%s is not a valid role for status roles."
}
}
9 changes: 9 additions & 0 deletions locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,14 @@
"reset": {
"description": "resets the bot for this guild",
"confirmationPrompt": ":warning: You are about to reset the whole bot including all your activity roles. Roles will not be removed from members, and the bot will not remove them even if you create a new Activity Role.\nThis is normally not necessary! Are you _**absolutely**_ sure?"
},
"deleteStatusRole": {
"description": "deletes a status role",
"eventOptionDescription": "the status role to delete",
"success": "Deleted status role for %s",
"noStatusRole": "There is no status role for %s"
},
"setStatusRole": {
"roleNotValid": "%s is not a valid role for status roles."
}
}
9 changes: 9 additions & 0 deletions locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,14 @@
"reset": {
"description": "resets the bot for this guild",
"confirmationPrompt": ":warning: You are about to reset the whole bot including all your activity roles. Roles will not be removed from members, and the bot will not remove them even if you create a new Activity Role.\nThis is normally not necessary! Are you _**absolutely**_ sure?"
},
"deleteStatusRole": {
"description": "deletes a status role",
"eventOptionDescription": "the status role to delete",
"success": "Deleted status role for %s",
"noStatusRole": "There is no status role for %s"
},
"setStatusRole": {
"roleNotValid": "%s is not a valid role for status roles."
}
}
9 changes: 9 additions & 0 deletions locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,14 @@
"reset": {
"description": "resets the bot for this guild",
"confirmationPrompt": ":warning: You are about to reset the whole bot including all your activity roles. Roles will not be removed from members, and the bot will not remove them even if you create a new Activity Role.\nThis is normally not necessary! Are you _**absolutely**_ sure?"
},
"deleteStatusRole": {
"description": "deletes a status role",
"eventOptionDescription": "the status role to delete",
"success": "Deleted status role for %s",
"noStatusRole": "There is no status role for %s"
},
"setStatusRole": {
"roleNotValid": "%s is not a valid role for status roles."
}
}
9 changes: 9 additions & 0 deletions locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,14 @@
"reset": {
"description": "resets the bot for this guild",
"confirmationPrompt": ":warning: You are about to reset the whole bot including all your activity roles. Roles will not be removed from members, and the bot will not remove them even if you create a new Activity Role.\nThis is normally not necessary! Are you _**absolutely**_ sure?"
},
"deleteStatusRole": {
"description": "deletes a status role",
"eventOptionDescription": "the status role to delete",
"success": "Deleted status role for %s",
"noStatusRole": "There is no status role for %s"
},
"setStatusRole": {
"roleNotValid": "%s is not a valid role for status roles."
}
}
9 changes: 9 additions & 0 deletions locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,14 @@
"reset": {
"description": "resets the bot for this guild",
"confirmationPrompt": ":warning: You are about to reset the whole bot including all your activity roles. Roles will not be removed from members, and the bot will not remove them even if you create a new Activity Role.\nThis is normally not necessary! Are you _**absolutely**_ sure?"
},
"deleteStatusRole": {
"description": "deletes a status role",
"eventOptionDescription": "the status role to delete",
"success": "Deleted status role for %s",
"noStatusRole": "There is no status role for %s"
},
"setStatusRole": {
"roleNotValid": "%s is not a valid role for status roles."
}
}
9 changes: 9 additions & 0 deletions locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,14 @@
"reset": {
"description": "resets the bot for this guild",
"confirmationPrompt": ":warning: You are about to reset the whole bot including all your activity roles. Roles will not be removed from members, and the bot will not remove them even if you create a new Activity Role.\nThis is normally not necessary! Are you _**absolutely**_ sure?"
},
"deleteStatusRole": {
"description": "deletes a status role",
"eventOptionDescription": "the status role to delete",
"success": "Deleted status role for %s",
"noStatusRole": "There is no status role for %s"
},
"setStatusRole": {
"roleNotValid": "%s is not a valid role for status roles."
}
}
9 changes: 9 additions & 0 deletions locales/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,14 @@
"reset": {
"description": "resets the bot for this guild",
"confirmationPrompt": ":warning: You are about to reset the whole bot including all your activity roles. Roles will not be removed from members, and the bot will not remove them even if you create a new Activity Role.\nThis is normally not necessary! Are you _**absolutely**_ sure?"
},
"deleteStatusRole": {
"description": "deletes a status role",
"eventOptionDescription": "the status role to delete",
"success": "Deleted status role for %s",
"noStatusRole": "There is no status role for %s"
},
"setStatusRole": {
"roleNotValid": "%s is not a valid role for status roles."
}
}
2 changes: 2 additions & 0 deletions src/modules/bot.ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import activityStats from './commands/activityStats';
import addActivityRole from './commands/addActivityRole';
import checkRoles, { checkRolesStandalone } from './commands/checkRoles';
import deleteActivityRole from './commands/deleteActivityRole';
import deleteStatusRole from './commands/deleteStatusRole';
import _export from './commands/export';
import help from './commands/help';
import listRoles from './commands/listRoles';
Expand All @@ -32,6 +33,7 @@ export function initClientReady() {
.addCommand(addActivityRole)
.addCommand(checkRoles)
.addCommand(deleteActivityRole)
.addCommand(deleteStatusRole)
.addCommand(_export)
.addCommand(help)
.addCommand(listRoles)
Expand Down
77 changes: 77 additions & 0 deletions src/modules/commands/deleteStatusRole.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: AGPL-3.0-only

import { db, getLang } from './../db';
import { Command } from '../commandHandler';

import { __, discordTranslations, getEnumKey } from '../messages';
import {
ActivityType,
Colors,
EmbedBuilder,
PermissionsBitField,
SlashCommandBuilder,
} from 'discord.js';
export default {
data: new SlashCommandBuilder()
.setName('deletestatusrole')
.setDescription(__({ phrase: 'deleteStatusRole->description', locale: 'en-US' }))
.setDescriptionLocalizations(discordTranslations('deleteStatusRole->description'))
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles)
.addStringOption(option =>
option
.setName('event')
.setDescription(__({ phrase: 'deleteStatusRole->eventOptionDescription', locale: 'en-US' }))
.setDescriptionLocalizations(
discordTranslations('deleteStatusRole->eventOptionDescription'),
)
.setChoices(
{ name: 'Playing', name_localizations: discordTranslations('Playing'), value: '0' }, // value 0
{ name: 'Streaming', name_localizations: discordTranslations('Streaming'), value: '1' }, // value 1
{ name: 'Listening', name_localizations: discordTranslations('Listening'), value: '2' }, // value 2
{ name: 'Watching', name_localizations: discordTranslations('Watching'), value: '3' }, // value 3
{ name: 'Custom', name_localizations: discordTranslations('Custom'), value: '4' }, // value 4
{ name: 'Competing', name_localizations: discordTranslations('Competing'), value: '5' }, // value 5
)
.setRequired(true),
),
execute: async interaction => {
if (!interaction.guildId) return;
const locale = getLang(interaction);
const type = Number(interaction.options.get('event')?.value) as number;
const typeString = getEnumKey(ActivityType, type);
const currentStatusRole = await db
.selectFrom('statusRoles')
.selectAll()
.where('guildID', '=', interaction.guildId)
.where('type', '=', type)
.executeTakeFirst();

if (currentStatusRole) {
await db
.deleteFrom('statusRoles')
.where('guildID', '=', interaction.guildId)
.where('type', '=', type)
.execute();
interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
__({ phrase: 'deleteStatusRole->success', locale }, '`' + typeString + '`'),
)
.setColor(Colors.Green),
],
});
} else {
interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
__({ phrase: 'deleteStatusRole->noStatusRole', locale }, '`' + typeString + '`'),
)
.setColor(Colors.Red),
],
});
}
},
} as Command;
135 changes: 51 additions & 84 deletions src/modules/commands/setStatusRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { db, getLang } from './../db';
import { Command } from '../commandHandler';

import { __, discordTranslations, getEnumKey } from '../messages';
import { ActivityType, Colors, EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { ActivityType, APIRole, Colors, EmbedBuilder, Role, SlashCommandBuilder } from 'discord.js';
export default {
data: new SlashCommandBuilder()
.setName('setstatusrole')
Expand Down Expand Up @@ -34,104 +34,71 @@ export default {
.setDescription('the role to assign. To remove the role, omit this option')
.setDescriptionLocalizations(
discordTranslations('the role to assign. To remove the role, omit this option'),
),
)
.setRequired(true),
),

execute: async interaction => {
if (!interaction.guildId) return;
const locale = getLang(interaction);
const type = Number(interaction.options.get('event')?.value) as number;
const typeString = getEnumKey(ActivityType, type);
const role = interaction.options.get('role')?.role;
const role = interaction.options.get('role')?.role as Role | APIRole;
const currentStatusRole = await db
.selectFrom('statusRoles')
.selectAll()
.where('guildID', '=', interaction.guildId)
.where('type', '=', type)
.executeTakeFirst();

if (role) {
if (currentStatusRole && role.id === currentStatusRole.roleID) {
interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
__(
{
phrase: 'the status role for **%s** already is <@&%s>!',
locale,
},
typeString,
role.id,
),
)
.setColor(Colors.Green),
],
ephemeral: true,
});
} else {
if (currentStatusRole) {
await db
.updateTable('statusRoles')
.set({ roleID: role.id })
.where('guildID', '=', interaction.guildId)
.where('type', '=', type)
.execute();
} else {
db.insertInto('statusRoles')
.values({
guildID: interaction.guildId,
type,
roleID: role.id,
})
.execute();
}
interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
__(
{
phrase: 'The status role for **%s** is now <@&%s>!',
locale,
},
typeString,
role.id,
),
)
.setColor(Colors.Green),
],
ephemeral: true,
});
}
if (role.name === '@everyone') {
interaction.reply(
':x:' + __({ phrase: 'setStatusRole->roleNotValid', locale }, `<@&${role.id}>`),
);
return;
}

if (currentStatusRole && role.id === currentStatusRole.roleID) {
interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
__(
{
phrase: 'the status role for **%s** already is <@&%s>!',
locale,
},
typeString,
role.id,
),
)
.setColor(Colors.Green),
],
ephemeral: true,
});
} else {
if (currentStatusRole) {
db.deleteFrom('statusRoles')
.where('guildID', '=', interaction.guildId)
.where('type', '=', type)
.execute();
interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
__({ phrase: 'The status role for **%s** has been deleted.', locale }, typeString),
)
.setColor(Colors.Red),
],
ephemeral: true,
});
} else {
interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
__({ phrase: 'There is no status role set for **%s**', locale }, typeString),
)
.setColor(Colors.Red),
],
ephemeral: true,
});
}
db.insertInto('statusRoles')
.values({
guildID: interaction.guildId,
type,
roleID: role.id,
})
.onConflict(oc => oc.columns(['type', 'guildID']).doUpdateSet({ roleID: role.id }))
.execute();
interaction.reply({
embeds: [
new EmbedBuilder()
.setDescription(
__(
{ phrase: 'The status role for **%s** is now <@&%s>!', locale },
typeString,
role.id,
),
)
.setColor(Colors.Green),
],
ephemeral: true,
});
}
},
} as Command;

0 comments on commit 5ea3c1f

Please sign in to comment.