Fix fetching members for roles in POST message

This commit is contained in:
Madeline 2022-09-29 21:27:33 +10:00
parent 357aada969
commit 835a5ab3a3
2 changed files with 21 additions and 16 deletions

View File

@ -255,17 +255,22 @@ router.post(
); );
} }
const member = await Member.findOneOrFail({ if (message.guild_id) {
where: { id: req.user_id }, // handleMessage will fetch the Member, but only if they are not guild owner.
relations: ["roles"], // have to fetch ourselves otherwise.
}); if (!message.member) {
member.roles = member.roles message.member = await Member.findOneOrFail({
.filter((role: Role) => { where: { id: req.user_id, guild_id: message.guild_id },
return role.id !== role.guild_id; relations: ["roles"]
}) });
.map((role: Role) => { }
return role.id;
}) as any; //@ts-ignore
message.member.roles =
message.member.roles.
filter(x => x.id != x.guild_id)
.map(x => x.id);
}
let read_state = await ReadState.findOne({ let read_state = await ReadState.findOne({
where: { user_id: req.user_id, channel_id } where: { user_id: req.user_id, channel_id }

View File

@ -64,7 +64,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
channel_id: opts.channel_id, channel_id: opts.channel_id,
attachments: opts.attachments || [], attachments: opts.attachments || [],
embeds: opts.embeds || [], embeds: opts.embeds || [],
reactions: /*opts.reactions ||*/ [], reactions: /*opts.reactions ||*/[],
type: opts.type ?? 0, type: opts.type ?? 0,
}); });
@ -247,12 +247,12 @@ export async function postHandleMessage(message: Message) {
const width = const width =
parseInt( parseInt(
$('meta[property="og:image:width"]').attr("content") || $('meta[property="og:image:width"]').attr("content") ||
"", "",
) || undefined; ) || undefined;
const height = const height =
parseInt( parseInt(
$('meta[property="og:image:height"]').attr("content") || $('meta[property="og:image:height"]').attr("content") ||
"", "",
) || undefined; ) || undefined;
const url = $('meta[property="og:url"]').attr("content"); const url = $('meta[property="og:url"]').attr("content");
@ -317,7 +317,7 @@ export async function postHandleMessage(message: Message) {
data.embeds.push(embed); data.embeds.push(embed);
} }
} }
} catch (error) {} } catch (error) { }
} }
await Promise.all([ await Promise.all([
@ -345,7 +345,7 @@ export async function sendMessage(opts: MessageOptions) {
} as MessageCreateEvent), } as MessageCreateEvent),
]); ]);
postHandleMessage(message).catch((e) => {}); // no await as it should catch error non-blockingly postHandleMessage(message).catch((e) => { }); // no await as it should catch error non-blockingly
return message; return message;
} }