Skip to content

Commit

Permalink
chore: small things (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldietzler authored Sep 14, 2024
1 parent 13d703a commit ae8d747
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
26 changes: 12 additions & 14 deletions src/services/discord.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,10 @@ export class DiscordService {
);
}

return links.map(({ name, link }) => {
const formattedName = `${name}${link}`;
return {
name: formattedName.length < 100 ? formattedName : `${formattedName.slice(0, 97)}...`,
value: name,
};
});
return links.map(({ name, link }) => ({
name: this.shortenName(`${name}${link}`),
value: name,
}));
}

async addLink({ name, link, author }: { name: string; link: string; author: string }) {
Expand Down Expand Up @@ -193,13 +190,10 @@ export class DiscordService {
order: 'desc',
});

return result.items.map((item) => {
const name = `${item.pull_request ? '[PR]' : '[Issue]'} (${item.number}) ${item.title}`;
return {
name: name.length > 100 ? name.substring(0, 97) + '...' : name,
value: String(item.number),
};
});
return result.items.map((item) => ({
name: this.shortenName(`${item.pull_request ? '[PR]' : '[Issue]'} (${item.number}) ${item.title}`),
value: String(item.number),
}));
} catch (error) {
this.logger.log('Could not fetch search results from GitHub');
return [];
Expand Down Expand Up @@ -284,4 +278,8 @@ export class DiscordService {
getPrOrIssue(id: number) {
return this.github.getIssueOrPr(GithubOrg.ImmichApp, GithubRepo.Immich, id);
}

private shortenName(name: string, maxLength: number = 100) {
return name.length > maxLength ? `${name.substring(0, maxLength - 3)}...` : name;
}
}
3 changes: 2 additions & 1 deletion src/services/webhook.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Inject, Injectable, Logger, UnauthorizedException } from '@nestjs/common';
import { Colors, EmbedBuilder } from 'discord.js';
import { Colors, EmbedBuilder, MessageFlags } from 'discord.js';
import { getConfig } from 'src/config';
import { GithubStatusComponent, GithubStatusIncident, PaymentIntent, StripeBase } from 'src/dtos/webhook.dto';
import { IDatabaseRepository } from 'src/interfaces/database.interface';
Expand Down Expand Up @@ -116,6 +116,7 @@ export class WebhookService {
.setColor(livemode ? Colors.Green : Colors.Yellow)
.setFields(makeLicenseFields({ server, client })),
],
flags: [MessageFlags.SuppressNotifications],
});
}
}

0 comments on commit ae8d747

Please sign in to comment.