Merge pull request #8 from r-Overwatch2/feature/5-rework-default-permissions-for-slash-commands

Feature/5 rework default permissions for slash commands
This commit is contained in:
Lukas | AstroGD 2022-11-25 18:55:36 +01:00 committed by GitHub
commit 6242c09e4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 27 deletions

View File

@ -2,12 +2,12 @@
A Discord bot that checks Discord channel names for banned words and prevents renaming of them
## Commands
### /logchanel [channel?]
### /logchanel [channel?] `Permission: MANAGE_GUILD`
Sets the channel where the bot will log if a channel meets the banned word criteria. If channel is omitted, the log channel will be disabled.
### /blocklist
### /blocklist `Permission: MANAGE_GUILD`
#### /blocklist get
Gets the global and server specific banned word list and returns it
Gets the global and server specific banned word list and returns it (Same behaviour as /showblocklist)
#### /blocklist add [word]
Adds the word to the server specific blocklist
@ -15,15 +15,18 @@ Adds the word to the server specific blocklist
#### /blocklist remove [word]
Removes the word from the server specific blocklist
### /info
### /info `Permission: EVERYONE`
Returns general information about the bot and the servers stats
### /preservesettings
### /preservesettings `Permission: ADMINISTRATOR`
Changes the behaviour when the bot leaves the server.
Options are:
- Keep settings persistent even if the bot leaves
- Delete setting when the bot leaves the server [default]
### /showblocklist `Permission: MANAGE_CHANNELS`
Gets the global and server specific banned word list and returns it
## Environment variables
| Name | Description | Required | Example |
| :--------------- | :------------------------------------------------------------------------------ | :------: | :------------------ |

View File

@ -5,6 +5,7 @@ import { getGuildSetting, isPremiumActive } from "../tools/data";
import getDefaultEmbed, { getFailedEmbed, getSuccessEmbed } from "../tools/defaultEmbeds";
import { getGuildChannel } from "../tools/discord";
import { Color, Emoji } from "../tools/design";
import { execute as showBlocklistRunner } from "./showblocklist";
const builder = new SlashCommandBuilder();
builder.setName("blocklist");
@ -51,24 +52,7 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
switch (interaction.options.getSubcommand(true)) {
case "get": {
const guildBadWords = await database.getRepository(Badword).find({
select: {
value: true
},
where: {
guildID: interaction.guildId
}
});
const globalBadWords = await database.getRepository(Badword).find({
where: {
guildID: IsNull()
}
});
interaction.reply({
content: `\`\`\`Global bad word list\`\`\`\n||${globalBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||\n\`\`\`Local server bad word list (${guildBadWords.length}/${isPremium ? 100 : 10})\`\`\`\n||${guildBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||`,
ephemeral: true
}).catch();
await showBlocklistRunner(interaction);
break;
}

View File

@ -1,9 +1,10 @@
import * as notification from "./notification";
import * as notification from "./logchannel";
import * as blocklist from "./blocklist";
import * as info from "./info";
import * as preserveSettings from "./preserveSettings";
import * as showBlocklist from "./showblocklist";
const array = [notification.builder.toJSON(), blocklist.builder.toJSON(), info.builder.toJSON(), preserveSettings.builder.toJSON()];
const array = [notification.builder.toJSON(), blocklist.builder.toJSON(), info.builder.toJSON(), preserveSettings.builder.toJSON(), showBlocklist.builder.toJSON()];
export {
array

View File

@ -1,8 +1,9 @@
import { ChatInputCommandInteraction, Collection, Events, SlashCommandBuilder } from "discord.js";
import * as notification from "./notification";
import * as notification from "./logchannel";
import * as blocklist from "./blocklist";
import * as info from "./info";
import * as preserveSettings from "./preserveSettings";
import * as showBlocklist from "./showblocklist";
import client from "../client";
import getDefaultEmbed from "../tools/defaultEmbeds";
@ -11,6 +12,7 @@ commands.set(notification.builder.name, notification);
commands.set(blocklist.builder.name, blocklist);
commands.set(info.builder.name, info);
commands.set(preserveSettings.builder.name, preserveSettings);
commands.set(showBlocklist.builder.name, showBlocklist);
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;

View File

@ -9,7 +9,7 @@ const builder = new SlashCommandBuilder();
builder.setName("logchannel");
builder.setDescription("Configures the log channel");
builder.setDMPermission(false);
builder.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels);
builder.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild);
builder.addChannelOption((option) => {
option.addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement);
option.setName("channel");

View File

@ -0,0 +1,41 @@
import { ChatInputCommandInteraction, PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
import { IsNull } from "typeorm";
import { Badword, database } from "../data";
import { getGuildSetting, isPremiumActive } from "../tools/data";
const builder = new SlashCommandBuilder();
builder.setName("showblocklist");
builder.setDescription("Shows the blocklist of this server");
builder.setDMPermission(false);
builder.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels);
async function execute(interaction: ChatInputCommandInteraction): Promise<void> {
if (!interaction.inGuild()) throw new Error("Command was executed outside guild context");
const settings = await getGuildSetting(interaction.guildId);
const isPremium = isPremiumActive(settings.isPremiumUntil);
const guildBadWords = await database.getRepository(Badword).find({
select: {
value: true
},
where: {
guildID: interaction.guildId
}
});
const globalBadWords = await database.getRepository(Badword).find({
where: {
guildID: IsNull()
}
});
interaction.reply({
content: `\`\`\`Global bad word list\`\`\`\n||${globalBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||\n\`\`\`Local server bad word list (${guildBadWords.length}/${isPremium ? 100 : 10})\`\`\`\n||${guildBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||`,
ephemeral: true
}).catch();
}
export {
builder,
execute
}