Skip to content

Commit

Permalink
fix custom bot token issue
Browse files Browse the repository at this point in the history
  • Loading branch information
csuvajit committed May 12, 2024
1 parent b82170f commit d21b435
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
10 changes: 7 additions & 3 deletions apps/service-auth/src/guilds/guilds.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JwtAuthGuard, Role, Roles, RolesGuard } from '@app/auth';
import { Body, Controller, Get, Param, Put, Query, UseGuards } from '@nestjs/common';
import { Body, Controller, Get, Param, ParseBoolPipe, Put, Query, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { GuildOutput, GuildRostersOutput, ReorderClanCategoriesInput } from './dto';
import { GuildsService } from './guilds.service';
Expand Down Expand Up @@ -33,8 +33,12 @@ export class GuildsController {

@Get('/:guildId/members')
@ApiOperation({ summary: '(Internal)' })
getGuildMembers(@Param('guildId') guildId: string, @Query('q') q: string) {
return this.guildsService.getMembers(guildId, q);
getGuildMembers(
@Param('guildId') guildId: string,
@Query('q') queryString: string,
@Query('isPublicBot', ParseBoolPipe) isPublicBot: boolean,
) {
return this.guildsService.getMembers(guildId, queryString, !isPublicBot);
}

@Put('/:guildId/clans/reorder')
Expand Down
10 changes: 4 additions & 6 deletions apps/service-auth/src/guilds/guilds.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ export class GuildsService {
private rosterCategoriesCollection: Collection<RosterCategoriesEntity>,
) {}

async getMembers(guildId: string, query: string) {
const [bot, settings] = await Promise.all([
this.customBotsCollection.findOne({ guildIds: guildId }),
this.settingsCollection.findOne({ guildId }),
]);
async getMembers(guildId: string, query: string, isCustomBot: boolean) {
const bot = isCustomBot ? await this.customBotsCollection.findOne({ guildIds: guildId }) : null;

return this.discordClientService.listMembers({
query,
guildId,
token: settings?.hasCustomBot ? bot?.token ?? null : null,
token: bot?.token ?? null,
});
}

Expand Down
5 changes: 2 additions & 3 deletions libs/discord-client/src/discord-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ const rest = new REST({ version: '10' });

@Injectable()
export class DiscordClientService {
constructor(private configService: ConfigService) {
rest.setToken(configService.getOrThrow('DISCORD_TOKEN'));
}
constructor(private configService: ConfigService) {}

async getUser(userId: string): Promise<APIUser> {
const payload = await rest.get(Routes.user(userId));
Expand All @@ -28,6 +26,7 @@ export class DiscordClientService {
token: string | null;
}): Promise<APIGuildMember[]> {
token ??= this.configService.getOrThrow('DISCORD_TOKEN');
if (token) rest.setToken(token);

const payload = await rest.get(Routes.guildMembersSearch(guildId), {
query: new URLSearchParams({ query, limit: '50' }),
Expand Down

0 comments on commit d21b435

Please sign in to comment.