Skip to content

Commit

Permalink
feat: add /reset command
Browse files Browse the repository at this point in the history
Resets the whole bot incl. activityStats for a guild

Closes: #89
  • Loading branch information
tippfehlr committed Aug 30, 2024
1 parent 92a5f45 commit 1ea0154
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 7 deletions.
10 changes: 9 additions & 1 deletion locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"description": "re-check all users/roles",
"success": "checked {{{usersChecked}}} users, added {{{added}}} and removed {{{removed}}} roles",
"in-progress": "IN PROGRESS: already checked {{{usersChecked}}}/{{{totalUsersToCheck}}} users, added {{{added}}} and removed {{{removed}}} roles.",
"askForManageRolesPermission": "I don’t have the `MANAGE_ROLES` permission but need it to assign roles.\n Please add the permission to the “Activity Roles” role. Otherwise the bot will leave the guild automatically."
"askForManageRolesPermission": "I don’t have the `MANAGE_ROLES` permission but need it to assign roles.\n Please add the permission to the “Activity Roles” role. Otherwise the bot will leave the guild automatically.",
"alreadyRunning": "A `/checkroles` request is already running for this guild."
},
"Cancelled": "Cancelled",
"deleteActivityRole": {
Expand All @@ -118,5 +119,12 @@
},
"deleteActivityRoles": {
"deleteAllConfirmation": "Are you sure you want to delete all activity roles?"
},
"presenceUpdate": {
"roleHigherThanBotRole": "I don’t have permission to manage %s because it is higher than my highest role.\nPlease move one of my roles above all Activity Roles."
},
"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?"
}
}
10 changes: 9 additions & 1 deletion locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"description": "re-check all users/roles",
"success": "checked {{{usersChecked}}} users, added {{{added}}} and removed {{{removed}}} roles",
"in-progress": "IN PROGRESS: already checked {{{usersChecked}}}/{{{totalUsersToCheck}}} users, added {{{added}}} and removed {{{removed}}} roles.",
"askForManageRolesPermission": "I don’t have the `MANAGE_ROLES` permission but need it to assign roles.\n Please add the permission to the “Activity Roles” role. Otherwise the bot will leave the guild automatically."
"askForManageRolesPermission": "I don’t have the `MANAGE_ROLES` permission but need it to assign roles.\n Please add the permission to the “Activity Roles” role. Otherwise the bot will leave the guild automatically.",
"alreadyRunning": "A `/checkroles` request is already running for this guild."
},
"Cancelled": "Cancelled",
"deleteActivityRole": {
Expand All @@ -118,5 +119,12 @@
},
"deleteActivityRoles": {
"deleteAllConfirmation": "Are you sure you want to delete all activity roles?"
},
"presenceUpdate": {
"roleHigherThanBotRole": "I don’t have permission to manage %s because it is higher than my highest role.\nPlease move one of my roles above all Activity Roles."
},
"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?"
}
}
4 changes: 4 additions & 0 deletions locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,9 @@
},
"presenceUpdate": {
"roleHigherThanBotRole": "I don’t have permission to manage %s because it is higher than my highest role.\nPlease move one of my roles above all Activity Roles."
},
"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?"
}
}
10 changes: 9 additions & 1 deletion locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"description": "re-vérifie tous les utilisateurs/rôles",
"success": "vérifié {{{usersChecked}}} utilisateurs, ajouté {{{added}}} et retiré {{{removed}}} rôles",
"in-progress": "EN COURS : a déjà vérifié {{{usersChecked}}}/{{{totalUsersToCheck}}} utilisateurs, a ajouté {{{added}}} et a supprimé {{{removed}}} rôles.",
"askForManageRolesPermission": "Je n'ai pas la permission `GERER_LES_RÔLES` mais j'en ai besoin pour assigner des rôles.\n Veuillez ajouter la permission au rôle \"Activity Roles\". Sinon, le robot quittera automatiquement le serveur."
"askForManageRolesPermission": "Je n'ai pas la permission `GERER_LES_RÔLES` mais j'en ai besoin pour assigner des rôles.\n Veuillez ajouter la permission au rôle \"Activity Roles\". Sinon, le robot quittera automatiquement le serveur.",
"alreadyRunning": "A `/checkroles` request is already running for this guild."
},
"Cancelled": "Annulé",
"deleteActivityRole": {
Expand All @@ -118,5 +119,12 @@
},
"deleteActivityRoles": {
"deleteAllConfirmation": "Êtes-vous sûr de vouloir supprimer tous les rôles d'activité ?"
},
"presenceUpdate": {
"roleHigherThanBotRole": "I don’t have permission to manage %s because it is higher than my highest role.\nPlease move one of my roles above all Activity Roles."
},
"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?"
}
}
10 changes: 9 additions & 1 deletion locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"description": "re-check all users/roles",
"success": "checked {{{usersChecked}}} users, added {{{added}}} and removed {{{removed}}} roles",
"in-progress": "IN PROGRESS: already checked {{{usersChecked}}}/{{{totalUsersToCheck}}} users, added {{{added}}} and removed {{{removed}}} roles.",
"askForManageRolesPermission": "I don’t have the `MANAGE_ROLES` permission but need it to assign roles.\n Please add the permission to the “Activity Roles” role. Otherwise the bot will leave the guild automatically."
"askForManageRolesPermission": "I don’t have the `MANAGE_ROLES` permission but need it to assign roles.\n Please add the permission to the “Activity Roles” role. Otherwise the bot will leave the guild automatically.",
"alreadyRunning": "A `/checkroles` request is already running for this guild."
},
"Cancelled": "Cancelled",
"deleteActivityRole": {
Expand All @@ -118,5 +119,12 @@
},
"deleteActivityRoles": {
"deleteAllConfirmation": "Are you sure you want to delete all activity roles?"
},
"presenceUpdate": {
"roleHigherThanBotRole": "I don’t have permission to manage %s because it is higher than my highest role.\nPlease move one of my roles above all Activity Roles."
},
"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?"
}
}
10 changes: 9 additions & 1 deletion locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"description": "re-verificar todos os usuários/cargos",
"success": "verificou {{{usersChecked}}} usuários, adicionou {{{added}}} e removeu cargos {{{removed}}}",
"in-progress": "EM PROGRESS: já verificou {{{usersChecked}}}/{{{totalUsersToCheck}}} usuários, adicionou {{{added}}} e removeu {{{removed}}} cargos.",
"askForManageRolesPermission": "I don’t have the `MANAGE_ROLES` permission but need it to assign roles.\n Please add the permission to the “Activity Roles” role. Otherwise the bot will leave the guild automatically."
"askForManageRolesPermission": "I don’t have the `MANAGE_ROLES` permission but need it to assign roles.\n Please add the permission to the “Activity Roles” role. Otherwise the bot will leave the guild automatically.",
"alreadyRunning": "A `/checkroles` request is already running for this guild."
},
"Cancelled": "Cancelado",
"deleteActivityRole": {
Expand All @@ -118,5 +119,12 @@
},
"deleteActivityRoles": {
"deleteAllConfirmation": "Tem certeza que deseja excluir todos os cargos de atividade?"
},
"presenceUpdate": {
"roleHigherThanBotRole": "I don’t have permission to manage %s because it is higher than my highest role.\nPlease move one of my roles above all Activity Roles."
},
"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?"
}
}
10 changes: 9 additions & 1 deletion locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"description": "re-check all users/roles",
"success": "checked {{{usersChecked}}} users, added {{{added}}} and removed {{{removed}}} roles",
"in-progress": "IN PROGRESS: already checked {{{usersChecked}}}/{{{totalUsersToCheck}}} users, added {{{added}}} and removed {{{removed}}} roles.",
"askForManageRolesPermission": "I don’t have the `MANAGE_ROLES` permission but need it to assign roles.\n Please add the permission to the “Activity Roles” role. Otherwise the bot will leave the guild automatically."
"askForManageRolesPermission": "I don’t have the `MANAGE_ROLES` permission but need it to assign roles.\n Please add the permission to the “Activity Roles” role. Otherwise the bot will leave the guild automatically.",
"alreadyRunning": "A `/checkroles` request is already running for this guild."
},
"Cancelled": "Cancelled",
"deleteActivityRole": {
Expand All @@ -118,5 +119,12 @@
},
"deleteActivityRoles": {
"deleteAllConfirmation": "Are you sure you want to delete all activity roles?"
},
"presenceUpdate": {
"roleHigherThanBotRole": "I don’t have permission to manage %s because it is higher than my highest role.\nPlease move one of my roles above all Activity Roles."
},
"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?"
}
}
10 changes: 9 additions & 1 deletion locales/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"description": "re-check all users/roles",
"success": "checked {{{usersChecked}}} users, added {{{added}}} and removed {{{removed}}} roles",
"in-progress": "IN PROGRESS: already checked {{{usersChecked}}}/{{{totalUsersToCheck}}} users, added {{{added}}} and removed {{{removed}}} roles.",
"askForManageRolesPermission": "I don’t have the `MANAGE_ROLES` permission but need it to assign roles.\n Please add the permission to the “Activity Roles” role. Otherwise the bot will leave the guild automatically."
"askForManageRolesPermission": "I don’t have the `MANAGE_ROLES` permission but need it to assign roles.\n Please add the permission to the “Activity Roles” role. Otherwise the bot will leave the guild automatically.",
"alreadyRunning": "A `/checkroles` request is already running for this guild."
},
"Cancelled": "Cancelled",
"deleteActivityRole": {
Expand All @@ -118,5 +119,12 @@
},
"deleteActivityRoles": {
"deleteAllConfirmation": "Are you sure you want to delete all activity roles?"
},
"presenceUpdate": {
"roleHigherThanBotRole": "I don’t have permission to manage %s because it is higher than my highest role.\nPlease move one of my roles above all Activity Roles."
},
"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?"
}
}
2 changes: 2 additions & 0 deletions src/modules/bot.ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import _export from './commands/export';
import help from './commands/help';
import listRoles from './commands/listRoles';
import requireRole from './commands/requireRole';
import reset from './commands/reset';
import setStatusRole from './commands/setStatusRole';
import stats from './commands/stats';
import toggleAutoRole from './commands/toggleAutoRole';
Expand All @@ -35,6 +36,7 @@ export function initClientReady() {
.addCommand(help)
.addCommand(listRoles)
.addCommand(requireRole)
.addCommand(reset)
.addCommand(setStatusRole)
.addCommand(stats)
.addCommand(toggleAutoRole);
Expand Down
86 changes: 86 additions & 0 deletions src/modules/commands/reset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// SPDX-License-Identifier: AGPL-3.0-only

import {
ActionRowBuilder,
ButtonBuilder,
ButtonInteraction,
ButtonStyle,
ComponentType,
PermissionsBitField,
SlashCommandBuilder,
} from 'discord.js';

import { Command } from '../commandHandler';
import { __, discordTranslations, log } from '../messages';
import { db, getLang } from '../db';

export default {
data: new SlashCommandBuilder()
.setName('reset')
.setDescription(__({ phrase: 'reset->description', locale: 'en-US' }))
.setDescriptionLocalizations(discordTranslations('reset->description'))
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles),

execute: async interaction => {
const locale = getLang(interaction);
await interaction.reply({
content: __({ phrase: 'reset->confirmationPrompt', locale }),
components: [
new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId('reset:confirm')
.setLabel(__({ phrase: 'Yes', locale }))
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId('reset:cancel')
.setLabel(__({ phrase: 'No', locale }))
.setStyle(ButtonStyle.Secondary),
),
],
ephemeral: true,
});

interaction.channel
?.createMessageComponentCollector({
componentType: ComponentType.Button,
filter: (btnInt: ButtonInteraction) => interaction.user.id === btnInt.user.id,
max: 1,
time: 3 * 60 * 1000,
})
.on('collect', async (int: ButtonInteraction) => {
switch (int.customId) {
case 'reset:confirm':
await int.deferUpdate();
await db
.deleteFrom('activityRoles')
.where('guildID', '=', interaction.guildId)
.execute();
await db
.deleteFrom('activityStats')
.where('guildID', '=', interaction.guildId)
.execute();
await db.deleteFrom('guilds').where('guildID', '=', interaction.guildId).execute();
await db.deleteFrom('statusRoles').where('guildID', '=', interaction.guildId).execute();
await db
.deleteFrom('activeTemporaryRoles')
.where('guildID', '=', interaction.guildId)
.execute();
await db
.deleteFrom('activeTemporaryRolesHashed')
.where('guildID', '=', interaction.guildId)
.execute();
await int.editReply({
content: __({ phrase: 'Success!', locale }),
components: [],
});
break;
case 'reset:cancel':
int.update({
content: __({ phrase: 'Cancelled', locale }),
components: [],
});
break;
}
});
},
} as Command;

0 comments on commit 1ea0154

Please sign in to comment.