rewrite automod

This commit is contained in:
Jonny_Bro (Nikita) 2023-10-30 21:13:12 +05:00
parent 444a537f11
commit 3410fb2091
10 changed files with 84 additions and 114 deletions

View file

@ -235,10 +235,10 @@ class JaBa extends Client {
/** /**
* Finds or creates user in DB * Finds or creates user in DB
* @param {Array} param0 { id: User ID } * @param {String} userID User ID
* @returns {import("./User")} Mongoose model or JSON of this user * @returns {import("./User")} Mongoose model
*/ */
async findOrCreateUser({ id: userID }) { async findOrCreateUser(userID) {
if (this.databaseCache.users.get(userID)) return this.databaseCache.users.get(userID); if (this.databaseCache.users.get(userID)) return this.databaseCache.users.get(userID);
else { else {
let userData = await this.usersData.findOne({ id: userID }); let userData = await this.usersData.findOne({ id: userID });
@ -260,8 +260,8 @@ class JaBa extends Client {
/** /**
* Finds or creates member in DB * Finds or creates member in DB
* @param {Array} param0 { id: Member ID } * @param {Array} { id: Member ID, Guild ID }
* @returns {import("./Member")} Mongoose model or JSON of this member * @returns {import("./Member")} Mongoose model
*/ */
async findOrCreateMember({ id: memberID, guildId }) { async findOrCreateMember({ id: memberID, guildId }) {
let memberData = await this.membersData.findOne({ guildID: guildId, id: memberID }); let memberData = await this.membersData.findOne({ guildID: guildId, id: memberID });
@ -290,8 +290,8 @@ class JaBa extends Client {
/** /**
* Finds or creates guild in DB * Finds or creates guild in DB
* @param {Array} param0 { id: Guild ID } * @param {String} guildId Guild ID
* @returns {import("./Guild")} Mongoose model or JSON of this guild * @returns {import("./Guild")} Mongoose model
*/ */
async findOrCreateGuild(guildId) { async findOrCreateGuild(guildId) {
let guildData = await this.guildsData.findOne({ id: guildId }).populate("members"); let guildData = await this.guildsData.findOne({ id: guildId }).populate("members");

View file

@ -47,12 +47,7 @@ class Memes extends BaseCommand {
), ),
); );
const row = new ActionRowBuilder().addComponents( const row = new ActionRowBuilder().addComponents(new StringSelectMenuBuilder().setCustomId("memes_select").setPlaceholder(client.translate("common:NOTHING_SELECTED")).addOptions(tags));
new StringSelectMenuBuilder()
.setCustomId("memes_select")
.setPlaceholder(client.translate("common:NOTHING_SELECTED"))
.addOptions(tags),
);
const msg = await interaction.editReply({ const msg = await interaction.editReply({
content: interaction.translate("common:AVAILABLE_OPTIONS"), content: interaction.translate("common:AVAILABLE_OPTIONS"),

View file

@ -1,23 +0,0 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("rename")
.setDescription("Renames the ticket channel. Usage: /rename <new name>")
.addStringOption(option => option.setName("newname").setDescription("The new name for the ticket channel").setRequired(true))
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages),
async execute(interaction) {
try {
const newName = interaction.options.getString("newname");
if (!interaction.channel.name.includes("support")) {
interaction.reply("This command can only be used in a ticket channel.");
return;
}
await interaction.channel.setName(newName + "-" + interaction.channel.name.split("-")[1]);
interaction.reply(`Renamed the ticket channel to ${newName}`);
} catch (error) {
console.error(error);
interaction.reply("An error occurred while trying to rename the ticket channel.");
}
},
};

View file

@ -36,6 +36,7 @@ class Staff extends BaseCommand {
*/ */
async execute(client, interaction) { async execute(client, interaction) {
await interaction.guild.members.fetch(); await interaction.guild.members.fetch();
const administrators = interaction.guild.members.cache.filter(m => m.permissions.has(PermissionsBitField.Flags.Administrator) && !m.user.bot); const administrators = interaction.guild.members.cache.filter(m => m.permissions.has(PermissionsBitField.Flags.Administrator) && !m.user.bot);
const moderators = interaction.guild.members.cache.filter(m => !administrators.has(m.id) && m.permissions.has(PermissionsBitField.Flags.ManageMessages) && !m.user.bot); const moderators = interaction.guild.members.cache.filter(m => !administrators.has(m.id) && m.permissions.has(PermissionsBitField.Flags.ManageMessages) && !m.user.bot);
const embed = new EmbedBuilder() const embed = new EmbedBuilder()

View file

@ -17,6 +17,14 @@ class Automod extends BaseCommand {
}) })
.setDMPermission(false) .setDMPermission(false)
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageGuild) .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageGuild)
.addSubcommand(subcommand =>
subcommand
.setName("toggle")
.setDescription(client.translate("administration/automod:TOGGLE"))
.setDescriptionLocalizations({
uk: client.translate("administration/automod:TOGGLE", null, "uk-UA"),
ru: client.translate("administration/automod:TOGGLE", null, "ru-RU"),
})
.addBooleanOption(option => .addBooleanOption(option =>
option option
.setName("state") .setName("state")
@ -26,7 +34,16 @@ class Automod extends BaseCommand {
ru: client.translate("common:STATE", null, "ru-RU"), ru: client.translate("common:STATE", null, "ru-RU"),
}) })
.setRequired(true), .setRequired(true),
),
) )
.addSubcommand(subcommand =>
subcommand
.setName("ignore")
.setDescription(client.translate("administration/automod:IGNORE"))
.setDescriptionLocalizations({
uk: client.translate("administration/automod:IGNORE", null, "uk-UA"),
ru: client.translate("administration/automod:IGNORE", null, "ru-RU"),
})
.addChannelOption(option => .addChannelOption(option =>
option option
.setName("channel") .setName("channel")
@ -35,7 +52,9 @@ class Automod extends BaseCommand {
uk: client.translate("common:CHANNEL", null, "uk-UA"), uk: client.translate("common:CHANNEL", null, "uk-UA"),
ru: client.translate("common:CHANNEL", null, "ru-RU"), ru: client.translate("common:CHANNEL", null, "ru-RU"),
}) })
.addChannelTypes(ChannelType.GuildText), .addChannelTypes(ChannelType.GuildText)
.setRequired(true),
),
), ),
aliases: [], aliases: [],
dirname: __dirname, dirname: __dirname,
@ -57,19 +76,19 @@ class Automod extends BaseCommand {
*/ */
async execute(client, interaction, data) { async execute(client, interaction, data) {
const state = interaction.options.getBoolean("state"), const state = interaction.options.getBoolean("state"),
channel = interaction.options.getChannel("channel"); channel = interaction.options.getChannel("channel"),
command = interaction.options.getSubcommand();
if (state) { if (command === "toggle") {
data.guildData.plugins.automod = { data.guildData.plugins.automod = {
enabled: true, enabled: state,
ignored: [], ignored: [],
}; };
await data.guildData.save(); await data.guildData.save();
return interaction.success("administration/automod:ENABLED"); interaction.success(`administration/automod:${state ? "ENABLED" : "DISABLED"}`);
} else { } else if (command === "ignore") {
if (channel) {
data.guildData.plugins.automod.ignored.push(channel.id); data.guildData.plugins.automod.ignored.push(channel.id);
await data.guildData.save(); await data.guildData.save();
@ -77,16 +96,6 @@ class Automod extends BaseCommand {
interaction.success("administration/automod:DISABLED_CHANNEL", { interaction.success("administration/automod:DISABLED_CHANNEL", {
channel: channel.toString(), channel: channel.toString(),
}); });
} else {
data.guildData.plugins.automod = {
enabled: false,
ignored: [],
};
await data.guildData.save();
interaction.success("administration/automod:DISABLED");
}
} }
} }
} }

View file

@ -2,6 +2,8 @@
"DESCRIPTION": "Toggles automatic removal of invitation links", "DESCRIPTION": "Toggles automatic removal of invitation links",
"USAGE": "[state] (#channel)", "USAGE": "[state] (#channel)",
"EXAMPLES": "automod state:True\nautomod state:False channel:#general\nautomod state:False", "EXAMPLES": "automod state:True\nautomod state:False channel:#general\nautomod state:False",
"TOGGLE": "Toggle automod",
"IGNORE": "Ignore channel",
"ENABLED": "Invitation links will be automatically removed\nUse `automod false #channel` to ignore the channel", "ENABLED": "Invitation links will be automatically removed\nUse `automod false #channel` to ignore the channel",
"DISABLED_CHANNEL": "Automoderation will not be performed in {{channel}}", "DISABLED_CHANNEL": "Automoderation will not be performed in {{channel}}",
"DISABLED": "Automoderation is disabled", "DISABLED": "Automoderation is disabled",

View file

@ -2,6 +2,8 @@
"DESCRIPTION": "Включить или отключить автоудаление ссылок-приглашений", "DESCRIPTION": "Включить или отключить автоудаление ссылок-приглашений",
"USAGE": "[state] (#channel)", "USAGE": "[state] (#channel)",
"EXAMPLES": "automod state:True\nautomod state:False channel:#general\nautomod state:False", "EXAMPLES": "automod state:True\nautomod state:False channel:#general\nautomod state:False",
"TOGGLE": "Переключить автомод",
"IGNORE": "Игнорировать канал",
"ENABLED": "Ссылки-приглашения будут удаляться автоматически\nИспользуйте `automod false #channel` для игнорирования канала", "ENABLED": "Ссылки-приглашения будут удаляться автоматически\nИспользуйте `automod false #channel` для игнорирования канала",
"DISABLED_CHANNEL": "Автомодерация не будет выполняться в {{channel}}", "DISABLED_CHANNEL": "Автомодерация не будет выполняться в {{channel}}",
"DISABLED": "Автомодерация отключена", "DISABLED": "Автомодерация отключена",

View file

@ -2,6 +2,8 @@
"DESCRIPTION": "Увімкнути або вимкнути автовидалення посилань-запрошень", "DESCRIPTION": "Увімкнути або вимкнути автовидалення посилань-запрошень",
"USAGE": "[state] (#channel)", "USAGE": "[state] (#channel)",
"EXAMPLES": "automod state:True\nautomod state:False channel:#general\nautomod state:False", "EXAMPLES": "automod state:True\nautomod state:False channel:#general\nautomod state:False",
"TOGGLE": "Переключити автомод",
"IGNORE": "Ігнорувати канал",
"ENABLED": "Посилання-запрошення будуть видалятися автоматично\nВикористовуйте `automod false #channel` для ігнорування каналу", "ENABLED": "Посилання-запрошення будуть видалятися автоматично\nВикористовуйте `automod false #channel` для ігнорування каналу",
"DISABLED_CHANNEL": "Автомодерація не буде виконуватися в {{channel}}", "DISABLED_CHANNEL": "Автомодерація не буде виконуватися в {{channel}}",
"DISABLED": "Автомодерація відключена", "DISABLED": "Автомодерація відключена",

View file

@ -10,16 +10,16 @@
}, },
"author": "Discord: jonny_bro", "author": "Discord: jonny_bro",
"dependencies": { "dependencies": {
"@discord-player/extractor": "^4.4.4", "@discord-player/extractor": "^4.4.5",
"@discordjs/opus": "^0.9.0", "@discordjs/opus": "^0.9.0",
"@discordjs/rest": "^2.0.1", "@discordjs/rest": "^2.0.1",
"@discordjs/voice": "^0.16.0", "@discordjs/voice": "^0.16.0",
"canvas": "^2.10.2", "canvas": "^2.10.2",
"chalk": "^4.1.2", "chalk": "^4.1.2",
"cron": "^2.1.0", "cron": "^2.1.0",
"discord-api-types": "^0.37.60", "discord-api-types": "^0.37.62",
"discord-giveaways": "^6.0.1", "discord-giveaways": "^6.0.1",
"discord-player": "^6.6.4", "discord-player": "^6.6.6",
"discord.js": "^14.13.0", "discord.js": "^14.13.0",
"gamedig": "^4.0.2", "gamedig": "^4.0.2",
"i18next": "^21.9.1", "i18next": "^21.9.1",

View file

@ -6,8 +6,8 @@ settings:
dependencies: dependencies:
'@discord-player/extractor': '@discord-player/extractor':
specifier: ^4.4.4 specifier: ^4.4.5
version: 4.4.4 version: 4.4.5
'@discordjs/opus': '@discordjs/opus':
specifier: ^0.9.0 specifier: ^0.9.0
version: 0.9.0 version: 0.9.0
@ -27,14 +27,14 @@ dependencies:
specifier: ^2.1.0 specifier: ^2.1.0
version: 2.1.0 version: 2.1.0
discord-api-types: discord-api-types:
specifier: ^0.37.60 specifier: ^0.37.62
version: 0.37.60 version: 0.37.62
discord-giveaways: discord-giveaways:
specifier: ^6.0.1 specifier: ^6.0.1
version: 6.0.1(discord.js@14.13.0) version: 6.0.1(discord.js@14.13.0)
discord-player: discord-player:
specifier: ^6.6.4 specifier: ^6.6.6
version: 6.6.4(@discord-player/extractor@4.4.4)(@discordjs/opus@0.9.0)(discord.js@14.13.0)(youtube-sr@4.3.4) version: 6.6.6(@discord-player/extractor@4.4.5)(@discordjs/opus@0.9.0)
discord.js: discord.js:
specifier: ^14.13.0 specifier: ^14.13.0
version: 14.13.0 version: 14.13.0
@ -89,17 +89,17 @@ packages:
resolution: {integrity: sha512-71UAepYMbHTg2QQLXQAgyuXYHrgAYpJDxjg9dRWfTUNf+zfOAlyJEiRRk/WFhQyGu6m23iLR/H/JxgF4AW8Csg==} resolution: {integrity: sha512-71UAepYMbHTg2QQLXQAgyuXYHrgAYpJDxjg9dRWfTUNf+zfOAlyJEiRRk/WFhQyGu6m23iLR/H/JxgF4AW8Csg==}
dev: false dev: false
/@discord-player/extractor@4.4.4: /@discord-player/extractor@4.4.5:
resolution: {integrity: sha512-GO6GiZ+dccfAWVQxhz26TaxKEsKYwYE/MVmCkwCYAzaZ879nnG4so+OJi1l/uYbbZq0fjBCDX/2vkgm9gIw16Q==} resolution: {integrity: sha512-xy4PXrjYRF2VwLkxYFEB++Q6jutvAeLv58fHTW2HI2wbyiNYI8F6+dka1X0qd7ubKl8meE+bsfkmvJssAhsmyA==}
dependencies: dependencies:
file-type: 16.5.4 file-type: 16.5.4
genius-lyrics: 4.4.6 genius-lyrics: 4.4.6
isomorphic-unfetch: 4.0.2 isomorphic-unfetch: 4.0.2
node-html-parser: 6.1.5 node-html-parser: 6.1.10
reverbnation-scraper: 2.0.0 reverbnation-scraper: 2.0.0
soundcloud.ts: 0.5.2 soundcloud.ts: 0.5.2
spotify-url-info: 3.2.8 spotify-url-info: 3.2.8
youtube-sr: 4.3.4 youtube-sr: 4.3.9
transitivePeerDependencies: transitivePeerDependencies:
- encoding - encoding
dev: false dev: false
@ -198,7 +198,7 @@ packages:
engines: {node: '>=16.9.0'} engines: {node: '>=16.9.0'}
dependencies: dependencies:
'@types/ws': 8.5.5 '@types/ws': 8.5.5
discord-api-types: 0.37.60 discord-api-types: 0.37.62
prism-media: 1.3.5(@discordjs/opus@0.9.0) prism-media: 1.3.5(@discordjs/opus@0.9.0)
tslib: 2.6.0 tslib: 2.6.0
ws: 8.13.0 ws: 8.13.0
@ -714,8 +714,8 @@ packages:
resolution: {integrity: sha512-X4CDiMnDbA3s3RaUXWXmgAIbY1uxab3fqe3qwzg5XutR3wjqi7M3IkgQbsIBzpqBN2YWr/Qdv7JrFRqSgb4TFg==} resolution: {integrity: sha512-X4CDiMnDbA3s3RaUXWXmgAIbY1uxab3fqe3qwzg5XutR3wjqi7M3IkgQbsIBzpqBN2YWr/Qdv7JrFRqSgb4TFg==}
dev: false dev: false
/discord-api-types@0.37.60: /discord-api-types@0.37.62:
resolution: {integrity: sha512-5BELXTsv7becqVHrD81nZrqT4oEyXXWBwbsO/kwDDu6X3u19VV1tYDB5I5vaVAK+c1chcDeheI9zACBLm41LiQ==} resolution: {integrity: sha512-KpLQ6TiylGSSHj8AQW8Hz1ek1MkBbQUWs4gZhWH0rvSsWSj9tfav6EIitSxbFmqveqfu8oiPFI7vgFE4kBhTcQ==}
dev: false dev: false
/discord-giveaways@6.0.1(discord.js@14.13.0): /discord-giveaways@6.0.1(discord.js@14.13.0):
@ -729,22 +729,18 @@ packages:
serialize-javascript: 6.0.1 serialize-javascript: 6.0.1
dev: false dev: false
/discord-player@6.6.4(@discord-player/extractor@4.4.4)(@discordjs/opus@0.9.0)(discord.js@14.13.0)(youtube-sr@4.3.4): /discord-player@6.6.6(@discord-player/extractor@4.4.5)(@discordjs/opus@0.9.0):
resolution: {integrity: sha512-dXOCqgFD6Yc+gi/FHJ4J+AGtiMQ8NNxXYPKrhOLt0dQWHVQxpk2MwzNcukNi3OBPZ0f/U030rOIzmtZSkST9mg==} resolution: {integrity: sha512-XYQU4Vuy3H1aXgdaNPajzp8od7salL5cy2JIWoUdINKv5rCVXeu24BxkPj7QB5Db6uK3yKCOumfIWkL0Il1uVQ==}
peerDependencies: peerDependencies:
'@discord-player/extractor': ^4.4.4 '@discord-player/extractor': ^4.4.5
discord.js: 14.x
youtube-sr: 4.x
dependencies: dependencies:
'@discord-player/equalizer': 0.2.3 '@discord-player/equalizer': 0.2.3
'@discord-player/extractor': 4.4.4 '@discord-player/extractor': 4.4.5
'@discord-player/ffmpeg': 0.1.0 '@discord-player/ffmpeg': 0.1.0
'@discord-player/utils': 0.2.2 '@discord-player/utils': 0.2.2
discord-voip: 0.1.3(@discordjs/opus@0.9.0) discord-voip: 0.1.3(@discordjs/opus@0.9.0)
discord.js: 14.13.0
ip: 1.1.8 ip: 1.1.8
libsodium-wrappers: 0.7.11 libsodium-wrappers: 0.7.11
youtube-sr: 4.3.4
transitivePeerDependencies: transitivePeerDependencies:
- '@discordjs/opus' - '@discordjs/opus'
- bufferutil - bufferutil
@ -761,7 +757,7 @@ packages:
'@discord-player/ffmpeg': 0.1.0 '@discord-player/ffmpeg': 0.1.0
'@discord-player/opus': 0.1.2 '@discord-player/opus': 0.1.2
'@types/ws': 8.5.5 '@types/ws': 8.5.5
discord-api-types: 0.37.60 discord-api-types: 0.37.62
prism-media: 1.3.5(@discordjs/opus@0.9.0) prism-media: 1.3.5(@discordjs/opus@0.9.0)
tslib: 2.6.2 tslib: 2.6.2
ws: 8.13.0 ws: 8.13.0
@ -1111,7 +1107,7 @@ packages:
resolution: {integrity: sha512-TeSF4qXwLm+Nl8wUX+WUTJlEhPBanMw9EWpIHE2a/Qs4y2NBK99AHYfZJc73H1HVkZj4zPfscuGWlkQbbh0pDA==} resolution: {integrity: sha512-TeSF4qXwLm+Nl8wUX+WUTJlEhPBanMw9EWpIHE2a/Qs4y2NBK99AHYfZJc73H1HVkZj4zPfscuGWlkQbbh0pDA==}
dependencies: dependencies:
node-html-parser: 6.1.10 node-html-parser: 6.1.10
undici: 5.25.2 undici: 5.26.4
dev: false dev: false
/get-stream@6.0.1: /get-stream@6.0.1:
@ -1652,13 +1648,6 @@ packages:
he: 1.2.0 he: 1.2.0
dev: false dev: false
/node-html-parser@6.1.5:
resolution: {integrity: sha512-fAaM511feX++/Chnhe475a0NHD8M7AxDInsqQpz6x63GRF7xYNdS8Vo5dKsIVPgsOvG7eioRRTZQnWBrhDHBSg==}
dependencies:
css-select: 5.1.0
he: 1.2.0
dev: false
/nopt@5.0.0: /nopt@5.0.0:
resolution: {integrity: sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==} resolution: {integrity: sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==}
engines: {node: '>=6'} engines: {node: '>=6'}
@ -2004,7 +1993,7 @@ packages:
/soundcloud.ts@0.5.2: /soundcloud.ts@0.5.2:
resolution: {integrity: sha512-/pc72HWYJpSpup+mJBE9pT31JsrMcxJGBlip3Vem+0Fsscg98xh1/7I2nCpAKuMAeV6MVyrisI8TfjO6T7qKJg==} resolution: {integrity: sha512-/pc72HWYJpSpup+mJBE9pT31JsrMcxJGBlip3Vem+0Fsscg98xh1/7I2nCpAKuMAeV6MVyrisI8TfjO6T7qKJg==}
dependencies: dependencies:
undici: 5.22.1 undici: 5.26.4
dev: false dev: false
/sparse-bitfield@3.0.3: /sparse-bitfield@3.0.3:
@ -2163,13 +2152,6 @@ packages:
busboy: 1.6.0 busboy: 1.6.0
dev: false dev: false
/undici@5.25.2:
resolution: {integrity: sha512-tch8RbCfn1UUH1PeVCXva4V8gDpGAud/w0WubD6sHC46vYQ3KDxL+xv1A2UxK0N6jrVedutuPHxe1XIoqerwMw==}
engines: {node: '>=14.0'}
dependencies:
busboy: 1.6.0
dev: false
/undici@5.26.4: /undici@5.26.4:
resolution: {integrity: sha512-OG+QOf0fTLtazL9P9X7yqWxQ+Z0395Wk6DSkyTxtaq3wQEjIroVe7Y4asCX/vcCxYpNGMnwz8F0qbRYUoaQVMw==} resolution: {integrity: sha512-OG+QOf0fTLtazL9P9X7yqWxQ+Z0395Wk6DSkyTxtaq3wQEjIroVe7Y4asCX/vcCxYpNGMnwz8F0qbRYUoaQVMw==}
engines: {node: '>=14.0'} engines: {node: '>=14.0'}
@ -2282,6 +2264,6 @@ packages:
undici: 5.26.4 undici: 5.26.4
dev: false dev: false
/youtube-sr@4.3.4: /youtube-sr@4.3.9:
resolution: {integrity: sha512-olSYcR80XigutCrePEXBX3/RJJrWfonJQj7+/ggBiWU0CzTDLE1q8+lpWTWCG0JpzhzILp/IB/Bq/glGqqr1TQ==} resolution: {integrity: sha512-wPGEgVevSn32BJu5jiSHdvoryUCTCIM9LYT+yMDDpUfaev2Dh46dB+4qU31NgJ9XOsNxGlEKmc9qxUO5L0CE/Q==}
dev: false dev: false