Skip to content

Commit dd89e60

Browse files
committed
feat: add verbose mode to bot sync
1 parent a37807f commit dd89e60

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

libs/api/bot/data-access/src/lib/api-bot-manager.service.ts

+21-5
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export class ApiBotManagerService implements OnModuleInit {
189189
throw new Error(`Server ${serverId} not found for bot ${botId}`)
190190
}
191191

192-
const { dryRun, commandChannel, mentionRoles, mentionUsers } = botServer
192+
const { dryRun, commandChannel, mentionRoles, mentionUsers, verbose } = botServer
193193

194194
async function sendCommandChannel(message: string) {
195195
if (!commandChannel) {
@@ -204,7 +204,13 @@ export class ApiBotManagerService implements OnModuleInit {
204204
const roles = await this.getBotRoles(botId, serverId).then((roles) =>
205205
roles.filter((role) => communityRoleIds.includes(role.id)),
206206
)
207-
207+
if (!roles.length) {
208+
this.logger.warn(`No roles found for bot ${botId} in server ${serverId}`)
209+
return false
210+
}
211+
if (verbose) {
212+
await sendCommandChannel(`Syncing ${roles.length} roles for ${communityMembers.length} members`)
213+
}
208214
const roleMap: Record<string, string> = roles
209215
.map((role) => ({ [role.id]: role.name }))
210216
.reduce((acc, role) => ({ ...acc, ...role }), {})
@@ -270,12 +276,15 @@ export class ApiBotManagerService implements OnModuleInit {
270276
this.logger.warn(`Accounts not in Discord server: ${notFound.length}`)
271277
}
272278

273-
this.logger.verbose(`Synced ${communityMembers.length} members in ${serverId} for bot ${botId}`)
279+
if (verbose) {
280+
await sendCommandChannel(`Synced ${roles.length} roles ${communityMembers.length} members`)
281+
this.logger.verbose(`Synced ${communityMembers.length} members in ${serverId} for bot ${botId}`)
282+
}
274283

275284
return true
276285
}
277286

278-
async testBotServerConfig(botId: string, serverId: string) {
287+
async testBotServerConfig(userId: string, botId: string, serverId: string) {
279288
const bot = await this.core.data.bot.findUnique({ where: { id: botId }, include: { community: true } })
280289
if (!bot) {
281290
throw new Error(`Bot ${botId} not found`)
@@ -298,14 +307,21 @@ export class ApiBotManagerService implements OnModuleInit {
298307
if (!botServer.commandChannel) {
299308
throw new Error(`This bot does not have a command channel set`)
300309
}
301-
310+
const identity = await this.core.data.identity.findFirst({
311+
where: { ownerId: userId, provider: IdentityProvider.Discord },
312+
})
313+
if (!identity) {
314+
throw new Error(`Discord Identity for user ${userId} not found`)
315+
}
302316
const summary = await this.getCommunityRoleSummary(bot.communityId)
303317

304318
await discordBot.sendChannel(botServer.commandChannel, {
305319
embeds: [
306320
{
307321
title: `Configuration for ${discordBot.client?.user?.username} in ${bot.community.name} (${bot.community.cluster})`,
308322
fields: [
323+
{ name: 'Requester', value: `<@${identity.providerId}>` },
324+
{ name: `Bot`, value: `<@${discordBot.client?.user?.id}>` },
309325
{ name: `Admin Role`, value: botServer.adminRole ? `<@&${botServer.adminRole}>` : 'Not set' },
310326
{ name: `Command Channel`, value: `<#${botServer.commandChannel}>` },
311327
{ name: `Dry Run`, value: botServer.dryRun ? 'Enabled' : 'Disabled' },

libs/api/bot/data-access/src/lib/api-user-bot.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class ApiUserBotService {
123123
async userTestBotServerConfig(userId: string, botId: string, serverId: string) {
124124
await this.ensureBotAdmin({ botId, userId })
125125

126-
return this.manager.testBotServerConfig(botId, serverId)
126+
return this.manager.testBotServerConfig(userId, botId, serverId)
127127
}
128128

129129
private async ensureBotAdmin({ botId, userId }: { botId: string; userId: string }) {

0 commit comments

Comments
 (0)