fix: add user object on interaction and interaction_metadata for messages

This commit is contained in:
CyberL1 2025-10-17 22:20:51 +02:00 committed by Rory&
parent 4b5db1c2f4
commit a94f84dd72
2 changed files with 18 additions and 8 deletions

View File

@ -229,17 +229,25 @@ router.get(
return x;
});
await ret
.filter((x) => x.interaction_metadata && !x.interaction_metadata.user)
.forEachAsync(async (x) => {
x.interaction_metadata!.user = await User.findOne({ where: { id: x.interaction_metadata!.user_id } });
x.interaction!.user = await User.findOne({ where: { id: x.interaction_metadata!.user_id } });
});
// polyfill message references for old messages
await ret.filter((msg) => msg.message_reference && !msg.referenced_message?.id).forEachAsync(async (msg) => {
const whereOptions: { id: string; guild_id?: string; channel_id?: string } = {
id: msg.message_reference!.message_id,
};
if (msg.message_reference!.guild_id) whereOptions.guild_id = msg.message_reference!.guild_id;
if (msg.message_reference!.channel_id) whereOptions.channel_id = msg.message_reference!.channel_id;
await ret
.filter((msg) => msg.message_reference && !msg.referenced_message?.id)
.forEachAsync(async (msg) => {
const whereOptions: { id: string; guild_id?: string; channel_id?: string } = {
id: msg.message_reference!.message_id,
};
if (msg.message_reference!.guild_id) whereOptions.guild_id = msg.message_reference!.guild_id;
if (msg.message_reference!.channel_id) whereOptions.channel_id = msg.message_reference!.channel_id;
msg.referenced_message = await Message.findOne({ where: whereOptions, relations: ["author", "mentions", "mention_roles", "mention_channels"] });
});
msg.referenced_message = await Message.findOne({ where: whereOptions, relations: ["author", "mentions", "mention_roles", "mention_channels"] });
});
return res.json(ret);
},

View File

@ -174,6 +174,7 @@ export class Message extends BaseClass {
@Column({ type: "simple-json", nullable: true })
interaction?: {
user: User | null;
id: string;
type: InteractionType;
name: string;
@ -181,6 +182,7 @@ export class Message extends BaseClass {
@Column({ type: "simple-json", nullable: true })
interaction_metadata?: {
user: User | null;
id: string;
type: InteractionType;
user_id: string;