mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 18:59:19 +00:00
✨ feat: Add early access opt-in feature
This commit is contained in:
@@ -26,6 +26,8 @@ import {
|
||||
checkMemberPermissionsInChannel,
|
||||
checkMemberPermissionsInGuild
|
||||
} from '../utils/DiscordPermission';
|
||||
import Cache from '../providers/Cache';
|
||||
import { COMMON_EMBEDS } from './Settings';
|
||||
|
||||
const EMBEDS = {
|
||||
PURGE_INFO: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -155,8 +157,17 @@ export default class Purge extends DiscordModule {
|
||||
const channel = data.getGuildChannel() as GuildTextBasedChannel;
|
||||
if (!channel) return;
|
||||
|
||||
const cachedGuild = await Cache.getCachedGuild(guild.id);
|
||||
if (!cachedGuild) return;
|
||||
|
||||
const locale = await Locale.getGuildLocale(guild.id);
|
||||
|
||||
// TODO: Remove this feature when ready from early access
|
||||
if (!cachedGuild.EarlyAccess_Enabled)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [COMMON_EMBEDS.EARLY_ACCESS_WARNING(data, locale)]
|
||||
});
|
||||
|
||||
let query;
|
||||
|
||||
if (data.isMessage()) {
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
import { Guild, GuildChannel, ThreadChannel, Message, PermissionsBitField } from 'discord.js';
|
||||
import { I18n } from 'i18n';
|
||||
|
||||
import Prisma from '../../providers/Prisma';
|
||||
import Cache from '../../providers/Cache';
|
||||
|
||||
import { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import {
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
makeSuccessEmbed,
|
||||
sendHybridInteractionMessageResponse,
|
||||
makeWarningEmbed
|
||||
} from '../../utils/DiscordMessage';
|
||||
|
||||
import { COMMON_EMBEDS } from '.';
|
||||
import { checkMemberPermissionsInGuild } from '../../utils/DiscordPermission';
|
||||
|
||||
const EMBEDS = {
|
||||
EARLY_ACCESS_INVALID_STATUS: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Invalid status, Use ``true`` or ``false``',
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
NO_EARLY_ACCESS_STATUS_PROVIDED: async (
|
||||
data: HybridInteractionMessage,
|
||||
locale: I18n,
|
||||
isServiceAnnouncementEnabled: boolean
|
||||
) => {
|
||||
return makeInfoEmbed({
|
||||
title: 'Early Access Opt-in Status',
|
||||
description: `Early Access features are ${
|
||||
isServiceAnnouncementEnabled ? '**enabled**' : '**disabled**'
|
||||
} on this server`,
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
EARLY_ACCESS_STATUS_UPDATED: (data: HybridInteractionMessage, locale: I18n, newStatus: boolean) => {
|
||||
return makeSuccessEmbed({
|
||||
title: `Early Access features are now ${newStatus ? 'enabled' : 'disabled'}`,
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
EARLY_ACCESS_STATUS_ALREADY_SET: (data: HybridInteractionMessage, locale: I18n, status: boolean) => {
|
||||
return makeInfoEmbed({
|
||||
title: `Early Access features are already ${status ? 'enabled' : 'disabled'}`,
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
EARLY_ACCESS_ENABLED_WARNING: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeWarningEmbed({
|
||||
title: locale.__('early_access_warning.title'),
|
||||
description: locale.__('early_access_warning.description'),
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const setEnableEarlyAccess = async (data: HybridInteractionMessage, args: any, guild: Guild, locale: I18n) => {
|
||||
let member = data.getMember();
|
||||
if (!member) return;
|
||||
|
||||
if (
|
||||
!(await checkMemberPermissionsInGuild({
|
||||
member,
|
||||
data,
|
||||
locale,
|
||||
permissions: [PermissionsBitField.Flags.Administrator]
|
||||
}))
|
||||
)
|
||||
return;
|
||||
|
||||
let GuildCache = await Cache.getCachedGuild(guild.id);
|
||||
if (!GuildCache) return;
|
||||
|
||||
let newStatus: string | null | undefined;
|
||||
if (data.isMessage()) {
|
||||
let _name: string;
|
||||
if (typeof args[1] === 'undefined')
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.NO_EARLY_ACCESS_STATUS_PROVIDED(data, locale, GuildCache.EarlyAccess_Enabled)]
|
||||
});
|
||||
|
||||
let __name = args;
|
||||
__name.shift();
|
||||
_name = __name.join(' ');
|
||||
newStatus = _name;
|
||||
} else if (data.isApplicationCommand())
|
||||
newStatus = data.getSlashCommand().options.get('status', true).value?.toString();
|
||||
|
||||
if (!newStatus)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.NO_EARLY_ACCESS_STATUS_PROVIDED(data, locale, GuildCache.EarlyAccess_Enabled)]
|
||||
});
|
||||
|
||||
if (!['true', 'false', 'yes', 'no', 'y', 'n', 'enable', 'disable', 'on', 'off'].includes(newStatus.toLowerCase()))
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.EARLY_ACCESS_INVALID_STATUS(data, locale)]
|
||||
});
|
||||
|
||||
const newStatusBool = ['true', 'yes', 'y', 'enable', 'on'].includes(newStatus.toLowerCase()) ? true : false;
|
||||
|
||||
if (GuildCache?.EarlyAccess_Enabled === newStatusBool)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.EARLY_ACCESS_STATUS_ALREADY_SET(data, locale, newStatusBool)]
|
||||
});
|
||||
|
||||
let placeholder = await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [COMMON_EMBEDS.PROCESSING(data, locale)]
|
||||
});
|
||||
|
||||
await Prisma.client.guild.update({
|
||||
where: { id: guild.id },
|
||||
data: {
|
||||
EarlyAccess_Enabled: newStatusBool
|
||||
}
|
||||
});
|
||||
|
||||
await Cache.updateGuildCache(guild.id);
|
||||
|
||||
let toSend = [EMBEDS.EARLY_ACCESS_STATUS_UPDATED(data, locale, newStatusBool)];
|
||||
|
||||
if (newStatusBool) toSend.push(EMBEDS.EARLY_ACCESS_ENABLED_WARNING(data, locale));
|
||||
|
||||
if (data.isMessage())
|
||||
return await (placeholder as Message).edit({
|
||||
embeds: toSend
|
||||
});
|
||||
else if (data.isApplicationCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{
|
||||
embeds: toSend
|
||||
},
|
||||
true
|
||||
);
|
||||
};
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
import * as PrefixModule from './Prefix';
|
||||
import * as LanguageModule from './Language';
|
||||
import * as ServiceAnnouncementModule from './ServiceAnnouncement';
|
||||
import * as EarlyAccessModule from './EarlyAccess';
|
||||
import * as PurgeLimitModule from './PurgeLimit';
|
||||
|
||||
export const COMMON_EMBEDS = {
|
||||
@@ -49,6 +50,14 @@ export const COMMON_EMBEDS = {
|
||||
description: locale.__('common.processing_description'),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
EARLY_ACCESS_WARNING: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeInfoEmbed({
|
||||
icon: '🧪',
|
||||
title: locale.__('common.early_access_features'),
|
||||
description: locale.__('common.early_access_features_description'),
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -118,6 +127,8 @@ export default class Settings extends DiscordModule {
|
||||
return await ServiceAnnouncementModule.setEnableServiceAnnouncement(data, args, guild, locale);
|
||||
case 'serviceannouncementchannel':
|
||||
return await ServiceAnnouncementModule.setServiceAnnouncementChannel(data, args, guild, locale);
|
||||
case 'earlyaccess':
|
||||
return await EarlyAccessModule.setEnableEarlyAccess(data, args, guild, locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user