mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 10:49:20 +00:00
✨ feat: Purge limit settings command
This commit is contained in:
+9
-1
@@ -154,7 +154,7 @@
|
|||||||
"settings": {
|
"settings": {
|
||||||
"title": "Settings",
|
"title": "Settings",
|
||||||
"description": "Change how {{BOT_NAME}} behave on **{{{GUILD_NAME}}}**",
|
"description": "Change how {{BOT_NAME}} behave on **{{{GUILD_NAME}}}**",
|
||||||
"valid_args": "``Prefix`` ``Language`` ``EnableServiceAnnouncement`` ``ServiceAnnouncementChannel``"
|
"valid_args": "``Prefix`` ``Language`` ``EnableServiceAnnouncement`` ``ServiceAnnouncementChannel`` ``PurgeLimit``"
|
||||||
},
|
},
|
||||||
"settings_prefix": {
|
"settings_prefix": {
|
||||||
"info": "Current prefix is {{{PREFIX}}}",
|
"info": "Current prefix is {{{PREFIX}}}",
|
||||||
@@ -166,6 +166,14 @@
|
|||||||
"prefix_updated": "Prefix updated",
|
"prefix_updated": "Prefix updated",
|
||||||
"prefix_updated_description": "From now onwards, I shall be called by using ``{{{PREFIX}}}``"
|
"prefix_updated_description": "From now onwards, I shall be called by using ``{{{PREFIX}}}``"
|
||||||
},
|
},
|
||||||
|
"settings_purge_limit": {
|
||||||
|
"info": "Current purge limit is {{LIMIT}}",
|
||||||
|
"info_description": "Provide a new purge limit to change",
|
||||||
|
"purge_limit_too_big": "Purge limit too big, maximum is {{LIMIT}}",
|
||||||
|
"purge_limit_zero": "Purge limit can't be zero",
|
||||||
|
"purge_limit_nan": "Purge limit is not a number",
|
||||||
|
"purge_limit_updated": "Purge limit updated to {{LIMIT}}"
|
||||||
|
},
|
||||||
"settings_language": {
|
"settings_language": {
|
||||||
"info": "Current language is {{LANGUAGE}}",
|
"info": "Current language is {{LANGUAGE}}",
|
||||||
"info_description": "Provide a new language to change\n**Available languages**: ``{{LANGUAGES}}``",
|
"info_description": "Provide a new language to change\n**Available languages**: ``{{LANGUAGES}}``",
|
||||||
|
|||||||
+9
-1
@@ -154,7 +154,7 @@
|
|||||||
"settings": {
|
"settings": {
|
||||||
"title": "設定",
|
"title": "設定",
|
||||||
"description": "**{{{GUILD_NAME}}}**サーバでの{{BOT_NAME}}の動作変更",
|
"description": "**{{{GUILD_NAME}}}**サーバでの{{BOT_NAME}}の動作変更",
|
||||||
"valid_args": "``Prefix`` ``Language`` ``EnableServiceAnnouncement`` ``ServiceAnnouncementChannel``"
|
"valid_args": "``Prefix`` ``Language`` ``EnableServiceAnnouncement`` ``ServiceAnnouncementChannel`` ``PurgeLimit``"
|
||||||
},
|
},
|
||||||
"settings_prefix": {
|
"settings_prefix": {
|
||||||
"info": "現在の接頭辞は「{{{PREFIX}}}」です。",
|
"info": "現在の接頭辞は「{{{PREFIX}}}」です。",
|
||||||
@@ -166,6 +166,14 @@
|
|||||||
"prefix_updated": "プレフィックスを更新",
|
"prefix_updated": "プレフィックスを更新",
|
||||||
"prefix_updated_description": "これ以降、私は 「``{{{PREFIX}}}``」 を使って呼び出されることになります。"
|
"prefix_updated_description": "これ以降、私は 「``{{{PREFIX}}}``」 を使って呼び出されることになります。"
|
||||||
},
|
},
|
||||||
|
"settings_purge_limit": {
|
||||||
|
"info": "現在の削除上限は {{LIMIT}} です",
|
||||||
|
"info_description": "変更する新しい削除上限を指定してください",
|
||||||
|
"purge_limit_too_big": "削除上限が大きすぎます。最大は {{LIMIT}} です",
|
||||||
|
"purge_limit_zero": "削除上限はゼロにできません",
|
||||||
|
"purge_limit_nan": "削除上限が数値ではありません",
|
||||||
|
"purge_limit_updated": "削除上限が {{LIMIT}} に更新されました"
|
||||||
|
},
|
||||||
"settings_language": {
|
"settings_language": {
|
||||||
"info": "現在の言語は{{LANGUAGE}}です",
|
"info": "現在の言語は{{LANGUAGE}}です",
|
||||||
"info_description": "変更する新しい言語を提供する\n**利用可能な言語**: ``{{LANGUAGES}}``",
|
"info_description": "変更する新しい言語を提供する\n**利用可能な言語**: ``{{LANGUAGES}}``",
|
||||||
|
|||||||
+9
-1
@@ -154,7 +154,7 @@
|
|||||||
"settings": {
|
"settings": {
|
||||||
"title": "การตั้งค่า",
|
"title": "การตั้งค่า",
|
||||||
"description": "เปลี่ยนพฤติกรรมของ {{BOT_NAME}} บน **{{{GUILD_NAME}}}**",
|
"description": "เปลี่ยนพฤติกรรมของ {{BOT_NAME}} บน **{{{GUILD_NAME}}}**",
|
||||||
"valid_args": "``Prefix`` ``Language`` ``EnableServiceAnnouncement`` ``ServiceAnnouncementChannel``"
|
"valid_args": "``Prefix`` ``Language`` ``EnableServiceAnnouncement`` ``ServiceAnnouncementChannel`` ``PurgeLimit``"
|
||||||
},
|
},
|
||||||
"settings_prefix": {
|
"settings_prefix": {
|
||||||
"info": "คำนำหน้าปัจจุบันคือ {{{PREFIX}}}",
|
"info": "คำนำหน้าปัจจุบันคือ {{{PREFIX}}}",
|
||||||
@@ -166,6 +166,14 @@
|
|||||||
"prefix_updated": "อัปเดตคำนำหน้าแล้ว",
|
"prefix_updated": "อัปเดตคำนำหน้าแล้ว",
|
||||||
"prefix_updated_description": "จากนี้ไป คุณสามารถเรียกฉันโดยใช้ ``{{{PREFIX}}}`` นะ"
|
"prefix_updated_description": "จากนี้ไป คุณสามารถเรียกฉันโดยใช้ ``{{{PREFIX}}}`` นะ"
|
||||||
},
|
},
|
||||||
|
"settings_purge_limit": {
|
||||||
|
"info": "ขณะนี้ขีดจำกัดการล้างคือ {{LIMIT}}",
|
||||||
|
"info_description": "ระบุขีดจำกัดการล้างใหม่เพื่อเปลี่ยนแปลง",
|
||||||
|
"purge_limit_too_big": "ขีดจำกัดการล้างใหญ่เกินไป สูงสุดคือ {{LIMIT}}",
|
||||||
|
"purge_limit_zero": "ไม่สามารถตั้งค่าขีดจำกัดการล้างเป็นศูนย์ได้",
|
||||||
|
"purge_limit_nan": "ขีดจำกัดการล้างไม่ใช่ตัวเลข",
|
||||||
|
"purge_limit_updated": "ปรับปรุงขีดจำกัดการล้างเป็น {{LIMIT}} แล้ว"
|
||||||
|
},
|
||||||
"settings_language": {
|
"settings_language": {
|
||||||
"info": "ภาษาปัจจุบันตอนนี้คือ {{LANGUAGE}}",
|
"info": "ภาษาปัจจุบันตอนนี้คือ {{LANGUAGE}}",
|
||||||
"info_description": "ระบุภาษาใหม่เพื่อเปลี่ยน\n**ภาษาที่ใช้ได้**: ``{{LANGUAGES}}``",
|
"info_description": "ระบุภาษาใหม่เพื่อเปลี่ยน\n**ภาษาที่ใช้ได้**: ``{{LANGUAGES}}``",
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ export default class Purge extends DiscordModule {
|
|||||||
query = args.join(' ');
|
query = args.join(' ');
|
||||||
} else if (data.isApplicationCommand()) {
|
} else if (data.isApplicationCommand()) {
|
||||||
const interaction = data.getSlashCommand();
|
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) => {
|
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 PrefixModule from './Prefix';
|
||||||
import * as LanguageModule from './Language';
|
import * as LanguageModule from './Language';
|
||||||
import * as ServiceAnnouncementModule from './ServiceAnnouncement';
|
import * as ServiceAnnouncementModule from './ServiceAnnouncement';
|
||||||
|
import * as PurgeLimitModule from './PurgeLimit';
|
||||||
|
|
||||||
export const COMMON_EMBEDS = {
|
export const COMMON_EMBEDS = {
|
||||||
MEMBER_NO_PERMISSION: (data: HybridInteractionMessage, locale: I18n, permissions: PermissionResolvable[]) => {
|
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);
|
return await PrefixModule.default(data, args, guild, locale);
|
||||||
case 'language':
|
case 'language':
|
||||||
return await LanguageModule.default(data, args, guild, locale);
|
return await LanguageModule.default(data, args, guild, locale);
|
||||||
|
case 'purgelimit':
|
||||||
|
return await PurgeLimitModule.default(data, args, guild, locale);
|
||||||
case 'enableserviceannouncement':
|
case 'enableserviceannouncement':
|
||||||
return await ServiceAnnouncementModule.setEnableServiceAnnouncement(data, args, guild, locale);
|
return await ServiceAnnouncementModule.setEnableServiceAnnouncement(data, args, guild, locale);
|
||||||
case 'serviceannouncementchannel':
|
case 'serviceannouncementchannel':
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export const GLOBAL_COMMANDS: Object[] = [
|
|||||||
new SlashCommandBuilder()
|
new SlashCommandBuilder()
|
||||||
.setName('purge')
|
.setName('purge')
|
||||||
.setDescription('Purge messages')
|
.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()
|
new SlashCommandBuilder()
|
||||||
.setName('osu')
|
.setName('osu')
|
||||||
|
|||||||
Reference in New Issue
Block a user