mirror of
https://github.com/spacebarchat/server.git
synced 2026-10-23 00:03:05 +00:00
fix: forbid poll editing/creating in non-text channels
This commit is contained in:
1 parent
eae999789c
commit
25aa725ba1
3 files changed
+11
No files matched your search
@@ -32,6 +32,7 @@ import {
|
||||
getRights,
|
||||
uploadFile,
|
||||
NewUrlUserSignatureData,
|
||||
DiscordApiErrors,
|
||||
} from "@spacebar/util";
|
||||
import { MessageCreateAttachment, MessageCreateCloudAttachment, MessageCreateSchema, MessageEditSchema, ChannelType } from "@spacebar/schemas";
|
||||
|
||||
@@ -85,6 +86,10 @@ router.patch(
|
||||
}
|
||||
} else rights.hasThrow("SELF_EDIT_MESSAGES");
|
||||
|
||||
if (message.poll) {
|
||||
throw DiscordApiErrors.POLL_CANNOT_EDIT_MESSAGE;
|
||||
}
|
||||
|
||||
// no longer necessary, somehow resolved by updating the type of `attachments`...?
|
||||
// //@ts-expect-error Something is wrong with message_reference here, TS complains since "channel_id" is optional in MessageCreateSchema
|
||||
const new_message = await handleMessage({
|
||||
|
||||
@@ -355,6 +355,10 @@ router.post(
|
||||
throw new HTTPError(`Cannot send messages to channel of type ${channel.type}`, 400);
|
||||
}
|
||||
|
||||
if (body.poll && !isTextChannel(channel.type)) {
|
||||
throw DiscordApiErrors.POLL_INVALID_CHANNEL_TYPE;
|
||||
}
|
||||
|
||||
// handle blocked users in dms
|
||||
if (channel.recipients?.length == 2) {
|
||||
const otherUser = channel.recipients.find((r) => r.user_id != req.user_id)?.user;
|
||||
|
||||
@@ -661,6 +661,8 @@ export const DiscordApiErrors = {
|
||||
BULK_BAN_FAILED: new ApiError("Failed to ban users", 500000),
|
||||
POLL_VOTING_BLOCKED: new ApiError("Poll voting blocked", 520000),
|
||||
POLL_EXPIRED: new ApiError("Poll expired", 520001),
|
||||
POLL_INVALID_CHANNEL_TYPE: new ApiError("Invalid channel type for poll creation", 520002),
|
||||
POLL_CANNOT_EDIT_MESSAGE: new ApiError("Cannot edit a poll message", 520003),
|
||||
|
||||
//Other errors
|
||||
UNKNOWN_VOICE_STATE: new ApiError("Unknown Voice State", 10065, 404),
|
||||
|
||||
Reference in new issue
Block a user