mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 18:59:19 +00:00
✨ feat: Purge limit settings command
This commit is contained in:
@@ -172,7 +172,7 @@ export default class Purge extends DiscordModule {
|
||||
query = args.join(' ');
|
||||
} else if (data.isApplicationCommand()) {
|
||||
const interaction = data.getSlashCommand();
|
||||
query = interaction.options.get('message', true).value?.toString();
|
||||
query = interaction.options.get('amount', true).value?.toString();
|
||||
}
|
||||
|
||||
const purgeMessages = async (query: any, data: HybridInteractionMessage) => {
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
import { Guild, PermissionsBitField } from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import DiscordProvider from '../../providers/Discord';
|
||||
import Prisma from '../../providers/Prisma';
|
||||
import Cache from '../../providers/Cache';
|
||||
|
||||
import { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import {
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
makeSuccessEmbed,
|
||||
sendHybridInteractionMessageResponse
|
||||
} from '../../utils/DiscordMessage';
|
||||
|
||||
import { COMMON_EMBEDS } from '.';
|
||||
import { checkMemberPermissionsInGuild } from '../../utils/DiscordPermission';
|
||||
|
||||
const MAX_GLOBAL_PURGE_LIMIT = 1000;
|
||||
|
||||
const EMBEDS = {
|
||||
PURGE_INFO: (data: HybridInteractionMessage, locale: I18n, currentLimit: string) => {
|
||||
return makeInfoEmbed({
|
||||
title: locale.__('settings_purge_limit.info', { LIMIT: currentLimit }),
|
||||
description: locale.__('settings_purge_limit.info_description'),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
PURGE_TOO_BIG: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeErrorEmbed({
|
||||
title: locale.__('settings_purge_limit.purge_limit_too_big', { LIMIT: MAX_GLOBAL_PURGE_LIMIT.toString() }),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
PURGE_NAN: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeErrorEmbed({
|
||||
title: locale.__('settings_purge_limit.purge_limit_nan'),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
PURGE_ZERO: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeErrorEmbed({
|
||||
title: locale.__('settings_purge_limit.purge_limit_zero'),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
PURGE_UPDATED: (data: HybridInteractionMessage, locale: I18n, newLimit: string) => {
|
||||
return makeSuccessEmbed({
|
||||
title: locale.__('settings_purge_limit.purge_limit_updated', { LIMIT: newLimit }),
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default async (data: HybridInteractionMessage, args: any, guild: Guild, locale: I18n) => {
|
||||
let member = data.getMember();
|
||||
if (!member) return;
|
||||
|
||||
const GuildCache = await Cache.getCachedGuild(guild.id);
|
||||
if (!GuildCache) return;
|
||||
const limit = GuildCache.Purge_Limit;
|
||||
|
||||
if (
|
||||
!(await checkMemberPermissionsInGuild({
|
||||
member,
|
||||
data,
|
||||
locale,
|
||||
permissions: [PermissionsBitField.Flags.ManageGuild]
|
||||
}))
|
||||
)
|
||||
return;
|
||||
|
||||
let newLimit: string | null | undefined;
|
||||
if (data.isMessage()) {
|
||||
let _name: string;
|
||||
if (typeof args[1] === 'undefined')
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.PURGE_INFO(data, locale, limit.toString())]
|
||||
});
|
||||
|
||||
let __name = args;
|
||||
__name.shift();
|
||||
_name = __name.join(' ');
|
||||
newLimit = _name;
|
||||
} else if (data.isApplicationCommand())
|
||||
newLimit = data.getSlashCommand().options.get('limit', true).value?.toString();
|
||||
|
||||
if (typeof newLimit === 'undefined' || newLimit === null)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.PURGE_INFO(data, locale, limit.toString())]
|
||||
});
|
||||
|
||||
let parsedLimit = parseInt(newLimit);
|
||||
if (isNaN(parsedLimit))
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.PURGE_NAN(data, locale)]
|
||||
});
|
||||
|
||||
if (parsedLimit > MAX_GLOBAL_PURGE_LIMIT)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.PURGE_TOO_BIG(data, locale)]
|
||||
});
|
||||
|
||||
if (parsedLimit === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.PURGE_ZERO(data, locale)]
|
||||
});
|
||||
|
||||
let placeholder: HybridInteractionMessage | undefined;
|
||||
|
||||
let _placeholder = await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [COMMON_EMBEDS.PROCESSING(data, locale)]
|
||||
});
|
||||
if (_placeholder) placeholder = new HybridInteractionMessage(_placeholder);
|
||||
|
||||
await Prisma.client.guild.update({
|
||||
where: { id: guild.id },
|
||||
data: { Purge_Limit: parsedLimit }
|
||||
});
|
||||
Cache.updateGuildCache(guild.id);
|
||||
|
||||
if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder.getMessage().edit({ embeds: [EMBEDS.PURGE_UPDATED(data, locale, newLimit)] });
|
||||
else if (data.isApplicationCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.PURGE_UPDATED(data, locale, newLimit)] },
|
||||
true
|
||||
);
|
||||
};
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
import * as PrefixModule from './Prefix';
|
||||
import * as LanguageModule from './Language';
|
||||
import * as ServiceAnnouncementModule from './ServiceAnnouncement';
|
||||
import * as PurgeLimitModule from './PurgeLimit';
|
||||
|
||||
export const COMMON_EMBEDS = {
|
||||
MEMBER_NO_PERMISSION: (data: HybridInteractionMessage, locale: I18n, permissions: PermissionResolvable[]) => {
|
||||
@@ -111,6 +112,8 @@ export default class Settings extends DiscordModule {
|
||||
return await PrefixModule.default(data, args, guild, locale);
|
||||
case 'language':
|
||||
return await LanguageModule.default(data, args, guild, locale);
|
||||
case 'purgelimit':
|
||||
return await PurgeLimitModule.default(data, args, guild, locale);
|
||||
case 'enableserviceannouncement':
|
||||
return await ServiceAnnouncementModule.setEnableServiceAnnouncement(data, args, guild, locale);
|
||||
case 'serviceannouncementchannel':
|
||||
|
||||
@@ -47,7 +47,7 @@ export const GLOBAL_COMMANDS: Object[] = [
|
||||
new SlashCommandBuilder()
|
||||
.setName('purge')
|
||||
.setDescription('Purge messages')
|
||||
.addStringOption((option) => option.setName('message').setDescription('Amount to purge').setRequired(true)),
|
||||
.addStringOption((option) => option.setName('amount').setDescription('Amount to purge').setRequired(true)),
|
||||
|
||||
new SlashCommandBuilder()
|
||||
.setName('osu')
|
||||
|
||||
Reference in New Issue
Block a user