Enhance environment configuration and expand Prisma schema for bot management
- 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.
This commit is contained in:
55
apps/webui/src/lib/module-configs/logging.ts
Normal file
55
apps/webui/src/lib/module-configs/logging.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user