Skip to content

Commit

Permalink
Prettier & fix merge util/handlers/Message
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVTomatoCake committed Jul 18, 2024
1 parent 128b81b commit 15a2e57
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions src/api/util/handlers/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,12 @@ import {
//CHANNEL_MENTION,
USER_MENTION,
Webhook,
Attachment,
Config,
Sticker,
MessageCreateSchema,
EmbedCache,
handleFile,
Permissions,
} from "@spacebar/util";
import { HTTPError } from "lambert-server";
import { In } from "typeorm";
import { EmbedHandlers } from "@spacebar/api";
import * as Sentry from "@sentry/node";
import fetch from "node-fetch";
const allow_empty = false;
// TODO: check webhook, application, system author, stickers
// TODO: embed gifs/videos/images
Expand Down Expand Up @@ -167,28 +163,36 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
message.member = permission.cache.member;
}

if (opts.tts) permission.hasThrow("SEND_TTS_MESSAGES");
if (opts.message_reference) {
permission.hasThrow("READ_MESSAGE_HISTORY");
// code below has to be redone when we add custom message routing
if (message.guild_id !== null) {
const guild = await Guild.findOneOrFail({
where: { id: channel.guild_id },
});
if (!guild.features.includes("CROSS_CHANNEL_REPLIES")) {
if (opts.message_reference.guild_id !== channel.guild_id)
throw new HTTPError(
"You can only reference messages from this guild",
);
if (opts.message_reference.channel_id !== opts.channel_id)
throw new HTTPError(
"You can only reference messages from this channel",
);
if (opts.tts) permission.hasThrow("SEND_TTS_MESSAGES");
if (opts.message_reference) {
permission.hasThrow("READ_MESSAGE_HISTORY");
// code below has to be redone when we add custom message routing
if (message.guild_id !== null) {
const guild = await Guild.findOneOrFail({
where: { id: channel.guild_id },
});
if (!opts.message_reference.guild_id)
opts.message_reference.guild_id = channel.guild_id;
if (!opts.message_reference.channel_id)
opts.message_reference.channel_id = opts.channel_id;

if (!guild.features.includes("CROSS_CHANNEL_REPLIES")) {
if (opts.message_reference.guild_id !== channel.guild_id)
throw new HTTPError(
"You can only reference messages from this guild",
);
if (opts.message_reference.channel_id !== opts.channel_id)
throw new HTTPError(
"You can only reference messages from this channel",
);
}

message.message_reference = opts.message_reference;
}
/** Q: should be checked if the referenced message exists? ANSWER: NO
otherwise backfilling won't work **/
message.type = MessageType.REPLY;
}
/** Q: should be checked if the referenced message exists? ANSWER: NO
otherwise backfilling won't work **/
message.type = MessageType.REPLY;
}

// TODO: stickers/activity
Expand Down

0 comments on commit 15a2e57

Please sign in to comment.