- Added OWNER_USER_IDS to .env.example for specifying global bot owners. - Introduced new models in the Prisma schema: CommandOverride, OwnerTeamMember, GlobalUserBlacklist, GuildBlacklist, FeatureFlag, BotPresenceConfig, ChangelogEntry, and OwnerAuditLog to support advanced bot management features. - Updated env.ts to preprocess OWNER_USER_IDS for better handling of global bot owner IDs. - Modified ModulePlaceholderPage to ensure proper routing for remaining dashboard modules.
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import type { LogEventTypeDashboard, LoggingConfigDashboard, LoggingConfigDashboardPatch } from '@nexumi/shared';
|
|
import { prisma } from '../prisma';
|
|
|
|
async function ensureLoggingConfig(guildId: string) {
|
|
await prisma.guild.upsert({ where: { id: guildId }, update: {}, create: { id: guildId } });
|
|
return prisma.loggingConfig.upsert({
|
|
where: { guildId },
|
|
update: {},
|
|
create: { guildId }
|
|
});
|
|
}
|
|
|
|
export async function getLoggingDashboard(guildId: string): Promise<LoggingConfigDashboard> {
|
|
const [config, channels] = await Promise.all([
|
|
ensureLoggingConfig(guildId),
|
|
prisma.logChannel.findMany({ where: { guildId }, orderBy: { eventType: 'asc' } })
|
|
]);
|
|
|
|
return {
|
|
enabled: config.enabled,
|
|
ignoreBots: config.ignoreBots,
|
|
ignoredChannelIds: config.ignoredChannelIds,
|
|
ignoredRoleIds: config.ignoredRoleIds,
|
|
logChannels: channels.map((channel) => ({
|
|
eventType: channel.eventType as LogEventTypeDashboard,
|
|
channelId: channel.channelId
|
|
}))
|
|
};
|
|
}
|
|
|
|
export async function updateLoggingDashboard(
|
|
guildId: string,
|
|
patch: LoggingConfigDashboardPatch
|
|
): Promise<LoggingConfigDashboard> {
|
|
await ensureLoggingConfig(guildId);
|
|
|
|
const { logChannels, ...configPatch } = patch;
|
|
|
|
if (Object.keys(configPatch).length > 0) {
|
|
await prisma.loggingConfig.update({ where: { guildId }, data: configPatch });
|
|
}
|
|
|
|
if (logChannels !== undefined) {
|
|
await prisma.$transaction([
|
|
prisma.logChannel.deleteMany({ where: { guildId } }),
|
|
...logChannels.map((mapping) =>
|
|
prisma.logChannel.create({
|
|
data: { guildId, eventType: mapping.eventType, channelId: mapping.channelId }
|
|
})
|
|
)
|
|
]);
|
|
}
|
|
|
|
return getLoggingDashboard(guildId);
|
|
}
|