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:
commit
6242c09e4b
13
README.md
13
README.md
@ -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 |
|
||||
| :--------------- | :------------------------------------------------------------------------------ | :------: | :------------------ |
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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");
|
41
src/commands/showblocklist.ts
Normal file
41
src/commands/showblocklist.ts
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user