mirror of
https://github.com/immich-app/discord-bot.git
synced 2026-09-30 13:32:52 +08:00
feat: suppress mattermost embeds (#619)
This commit is contained in:
@@ -42,7 +42,7 @@ export interface IMattermostInterface {
|
||||
registerEventListener: <T extends MattermostEvents>(event: T, listener: MattermostEventListener<T>) => void;
|
||||
send: (post: { channelId: string; message: string; props?: Record<string, unknown> }) => Promise<void>;
|
||||
reply: (reply: { channelId: string; rootId: string; message: string }) => Promise<void>;
|
||||
updatePost: (post: { postId: string; message: string }) => Promise<void>;
|
||||
updatePost: (post: Partial<Post> & { id: string }) => Promise<void>;
|
||||
createEmote: (name: string, emoteUrl: string) => Promise<void>;
|
||||
streamChannels: (
|
||||
teamId?: string,
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
CommandWebhookRequest,
|
||||
IMattermostInterface,
|
||||
MattermostEvents,
|
||||
Post,
|
||||
UserProfile,
|
||||
type MattermostEventListener,
|
||||
} from 'src/interfaces/mattermost.interface';
|
||||
@@ -182,8 +183,8 @@ export class MattermostRepository implements IMattermostInterface {
|
||||
await this.#client.createPost({ channel_id: channelId, root_id: rootId, message });
|
||||
}
|
||||
|
||||
async updatePost({ postId, message }: { postId: string; message: string }) {
|
||||
await this.#client.patchPost({ id: postId, message, props: { remove_link_preview: 'true' } });
|
||||
async updatePost(post: Partial<Post> & { id: string }) {
|
||||
await this.#client.patchPost(post);
|
||||
}
|
||||
|
||||
async createEmote(name: string, emoteUrl: string) {
|
||||
|
||||
@@ -97,6 +97,7 @@ export class ChatService {
|
||||
|
||||
await this.mattermost.init();
|
||||
this.mattermost.registerEventListener(WebSocketEvents.Posted, (msg) => this.onMattermostPosted(msg));
|
||||
this.mattermost.registerEventListener(WebSocketEvents.PostEdited, (msg) => this.onMattermostEdited(msg));
|
||||
}
|
||||
|
||||
async onMattermostPosted(msg: MattermostEventMessage<WebSocketEvents.Posted>) {
|
||||
@@ -115,9 +116,16 @@ export class ChatService {
|
||||
---
|
||||
|
||||
${messageParts.join('\n')}`,
|
||||
postId: post.id,
|
||||
id: post.id,
|
||||
props: { remove_link_preview: 'true' },
|
||||
});
|
||||
}
|
||||
await this.suppressMattermostEmbeds(post);
|
||||
}
|
||||
|
||||
async onMattermostEdited(msg: MattermostEventMessage<WebSocketEvents.PostEdited>) {
|
||||
const post = JSON.parse(msg.data.post) as Post;
|
||||
await this.suppressMattermostEmbeds(post);
|
||||
}
|
||||
|
||||
@Cron(Constants.Cron.ImmichBirthday)
|
||||
@@ -732,4 +740,14 @@ ${formattedCode}
|
||||
tax: order.currentAmounts.tax.value,
|
||||
});
|
||||
}
|
||||
|
||||
private async suppressMattermostEmbeds(post: Post) {
|
||||
if (post.metadata.embeds.length === 0 || post.props.remove_link_preview === 'true') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.hasBlacklistUrl(post.metadata.embeds.map(({ url }) => url))) {
|
||||
await this.mattermost.updatePost({ id: post.id, props: { remove_link_preview: 'true' } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -558,7 +558,7 @@ export class WebhookService {
|
||||
horizontal_alignment: 'left',
|
||||
max_width: 26,
|
||||
},
|
||||
{ type: 'text', text: `[${user.login}](${user.html_url})`, is_subtle: true, size: 'small' },
|
||||
{ type: 'text', text: `[${user.login}](${user.html_url})`, is_subtle: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -625,7 +625,7 @@ export class WebhookService {
|
||||
horizontal_alignment: 'left',
|
||||
max_width: 26,
|
||||
},
|
||||
{ type: 'text', text: `[${user.login}](${user.html_url})`, is_subtle: true, size: 'small' },
|
||||
{ type: 'text', text: `[${user.login}](${user.html_url})`, is_subtle: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user