From aaf5df14e1523ef70fcb9aa5ff9fc0b73ff42fee Mon Sep 17 00:00:00 2001 From: Chris Chrome Date: Wed, 5 Jan 2022 05:44:14 -0500 Subject: Add Role Icons (#574) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Role Icons Co-authored-by: Erkin Alp Güney * Cache coherency rules Co-authored-by: MANIKILLER Co-authored-by: ImAaronFR <96433859+ImAaronFR@users.noreply.github.com> --- api/src/routes/guilds/#guild_id/roles.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'api/src') diff --git a/api/src/routes/guilds/#guild_id/roles.ts b/api/src/routes/guilds/#guild_id/roles.ts index b1875598..b6894e3f 100644 --- a/api/src/routes/guilds/#guild_id/roles.ts +++ b/api/src/routes/guilds/#guild_id/roles.ts @@ -8,7 +8,8 @@ import { GuildRoleDeleteEvent, emitEvent, Config, - DiscordApiErrors + DiscordApiErrors, + handleFile } from "@fosscord/util"; import { HTTPError } from "lambert-server"; import { route } from "@fosscord/api"; @@ -22,6 +23,8 @@ export interface RoleModifySchema { hoist?: boolean; // whether the role should be displayed separately in the sidebar mentionable?: boolean; // whether the role should be mentionable position?: number; + icon?: string; + unicode_emoji?: string; } export type RolePositionUpdateSchema = { @@ -58,7 +61,9 @@ router.post("/", route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" }) guild_id: guild_id, managed: false, permissions: String(req.permission!.bitfield & BigInt(body.permissions || "0")), - tags: undefined + tags: undefined, + icon: null, + unicode_emoji: null }); await Promise.all([ @@ -105,6 +110,8 @@ router.patch("/:role_id", route({ body: "RoleModifySchema", permission: "MANAGE_ const { role_id, guild_id } = req.params; const body = req.body as RoleModifySchema; + if (body.icon) body.icon = await handleFile(`/role-icons/${role_id}`, body.icon as string); + const role = new Role({ ...body, id: role_id, -- cgit 1.5.1 From a8bd9cc7954c9411df85277a8ff7ff44d2a041d0 Mon Sep 17 00:00:00 2001 From: Thesourtimes Date: Thu, 6 Jan 2022 22:14:00 +0300 Subject: Correct the invite response --- api/src/routes/invites/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api/src') diff --git a/api/src/routes/invites/index.ts b/api/src/routes/invites/index.ts index a2cf4cb5..ac813126 100644 --- a/api/src/routes/invites/index.ts +++ b/api/src/routes/invites/index.ts @@ -19,7 +19,7 @@ router.post("/:code", route({}), async (req: Request, res: Response) => { const { features } = await Guild.findOneOrFail({ id: guild_id}); const { public_flags } = await User.findOneOrFail({ id: req.user_id }); - if(features.includes("INTERNAL_EMPLOYEE_ONLY") && (public_flags & 1) !== 1) throw new HTTPError("You are not allowed to join this guild.", 401) + if(features.includes("INTERNAL_EMPLOYEE_ONLY") && (public_flags & 1) !== 1) throw new HTTPError("The Maze isn't meant for you.", 401) const invite = await Invite.joinGuild(req.user_id, code); -- cgit 1.5.1 From e275d2c77d7798f3dc3043f2afeaa3f9b07183c0 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Wed, 12 Jan 2022 01:27:55 +1100 Subject: Message fixes | Character limits and embed fixes (#581) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Adds message character limits (#503) * Fixed message `embeds` being ignored for `embed` * Update Message.ts Co-authored-by: Erkin Alp Güney --- .../routes/channels/#channel_id/messages/index.ts | 2 +- api/src/util/handlers/Message.ts | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'api/src') diff --git a/api/src/routes/channels/#channel_id/messages/index.ts b/api/src/routes/channels/#channel_id/messages/index.ts index b2fb615c..c3d3d408 100644 --- a/api/src/routes/channels/#channel_id/messages/index.ts +++ b/api/src/routes/channels/#channel_id/messages/index.ts @@ -172,7 +172,7 @@ router.post( } const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients", "recipients.user"] }); - const embeds = []; + const embeds = body.embeds || []; if (body.embed) embeds.push(body.embed); let message = await handleMessage({ ...body, diff --git a/api/src/util/handlers/Message.ts b/api/src/util/handlers/Message.ts index ba676394..29414177 100644 --- a/api/src/util/handlers/Message.ts +++ b/api/src/util/handlers/Message.ts @@ -17,13 +17,14 @@ import { User, Application, Webhook, - Attachment + Attachment, + Config, } from "@fosscord/util"; import { HTTPError } from "lambert-server"; import fetch from "node-fetch"; import cheerio from "cheerio"; import { MessageCreateSchema } from "../../routes/channels/#channel_id/messages"; - +const allow_empty = false; // TODO: check webhook, application, system author, stickers // TODO: embed gifs/videos/images @@ -55,6 +56,10 @@ export async function handleMessage(opts: MessageOptions): Promise { type: opts.type ?? 0 }); + if (message.content && message.content.length > Config.get().limits.message.maxCharacters) { + throw new HTTPError("Content length over max character limit") + } + // TODO: are tts messages allowed in dm channels? should permission be checked? if (opts.author_id) { message.author = await User.getPublicUser(opts.author_id); @@ -67,7 +72,7 @@ export async function handleMessage(opts: MessageOptions): Promise { } const permission = await getPermission(opts.author_id, channel.guild_id, opts.channel_id); - permission.hasThrow("SEND_MESSAGES"); + permission.hasThrow("SEND_MESSAGES"); // TODO: add the rights check if (permission.cache.member) { message.member = permission.cache.member; } @@ -75,6 +80,7 @@ export async function handleMessage(opts: MessageOptions): Promise { 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 and 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"); // TODO: should be checked if the referenced message exists? @@ -83,7 +89,7 @@ export async function handleMessage(opts: MessageOptions): Promise { } // TODO: stickers/activity - if (!opts.content && !opts.embeds?.length && !opts.attachments?.length && !opts.sticker_ids?.length) { + if (!allow_empty || (!opts.content && !opts.embeds?.length && !opts.attachments?.length && !opts.sticker_ids?.length)) { throw new HTTPError("Empty messages are not allowed", 50006); } @@ -93,7 +99,7 @@ export async function handleMessage(opts: MessageOptions): Promise { var mention_user_ids = [] as string[]; var mention_everyone = false; - if (content) { + if (content) { // TODO: explicit-only mentions message.content = content.trim(); for (const [_, mention] of content.matchAll(CHANNEL_MENTION)) { if (!mention_channel_ids.includes(mention)) mention_channel_ids.push(mention); @@ -135,7 +141,7 @@ export async function postHandleMessage(message: Message) { const data = { ...message }; data.embeds = data.embeds.filter((x) => x.type !== "link"); - links = links.slice(0, 5); // embed max 5 links + links = links.slice(0, 20); // embed max 20 links — TODO: make this configurable with instance policies for (const link of links) { try { @@ -188,7 +194,7 @@ export async function sendMessage(opts: MessageOptions) { emitEvent({ event: "MESSAGE_CREATE", channel_id: opts.channel_id, data: message.toJSON() } as MessageCreateEvent) ]); - postHandleMessage(message).catch((e) => {}); // no await as it shouldnt block the message send function and silently catch error + postHandleMessage(message).catch((e) => {}); // no await as it should catch error non-blockingly return message; } -- cgit 1.5.1 From 1887703c56b56ec7d9f2c66f5b740cb30db08122 Mon Sep 17 00:00:00 2001 From: ced777ric Date: Tue, 11 Jan 2022 18:38:10 +0100 Subject: fix the message endpoint always returning Empty message error (cherry picked from commit 8b8344e860920f3c3b911dfde1a7a078fef43c9b) --- api/src/util/handlers/Message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api/src') diff --git a/api/src/util/handlers/Message.ts b/api/src/util/handlers/Message.ts index 29414177..a3055aed 100644 --- a/api/src/util/handlers/Message.ts +++ b/api/src/util/handlers/Message.ts @@ -89,7 +89,7 @@ export async function handleMessage(opts: MessageOptions): Promise { } // TODO: stickers/activity - if (!allow_empty || (!opts.content && !opts.embeds?.length && !opts.attachments?.length && !opts.sticker_ids?.length)) { + if (!allow_empty && (!opts.content && !opts.embeds?.length && !opts.attachments?.length && !opts.sticker_ids?.length)) { throw new HTTPError("Empty messages are not allowed", 50006); } -- cgit 1.5.1 From 4baa6e0620760b93e68e780b8746cf2a257800df Mon Sep 17 00:00:00 2001 From: Erkin Alp Güney Date: Wed, 12 Jan 2022 09:58:22 +0300 Subject: Add cross channel replies Resolves #533 --- api/src/util/handlers/Message.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'api/src') diff --git a/api/src/util/handlers/Message.ts b/api/src/util/handlers/Message.ts index a3055aed..dae6f7e8 100644 --- a/api/src/util/handlers/Message.ts +++ b/api/src/util/handlers/Message.ts @@ -81,8 +81,10 @@ export async function handleMessage(opts: MessageOptions): Promise { if (opts.message_reference) { permission.hasThrow("READ_MESSAGE_HISTORY"); // code below has to be redone when we add custom message routing and 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 (!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"); + } // TODO: should be checked if the referenced message exists? // @ts-ignore message.type = MessageType.REPLY; -- cgit 1.5.1 From 072a60fb03fbf5f261c0e9888ce49847e1a350d4 Mon Sep 17 00:00:00 2001 From: Erkin Alp Güney Date: Wed, 12 Jan 2022 16:04:34 +0300 Subject: Fix the feature check --- api/src/util/handlers/Message.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'api/src') diff --git a/api/src/util/handlers/Message.ts b/api/src/util/handlers/Message.ts index dae6f7e8..92bb2335 100644 --- a/api/src/util/handlers/Message.ts +++ b/api/src/util/handlers/Message.ts @@ -2,6 +2,7 @@ import { Channel, Embed, emitEvent, + Guild, Message, MessageCreateEvent, MessageUpdateEvent, @@ -81,6 +82,7 @@ export async function handleMessage(opts: MessageOptions): Promise { if (opts.message_reference) { permission.hasThrow("READ_MESSAGE_HISTORY"); // code below has to be redone when we add custom message routing and cross-channel replies + const guild = await Guild.findOneOrFail({ id: 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"); -- cgit 1.5.1 From 41fca13db2e88e4e2c53544658ee99cf1800f664 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Thu, 13 Jan 2022 18:45:23 +1100 Subject: Fix typo in commit 277b28c --- api/src/util/handlers/Message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api/src') diff --git a/api/src/util/handlers/Message.ts b/api/src/util/handlers/Message.ts index 92bb2335..21664368 100644 --- a/api/src/util/handlers/Message.ts +++ b/api/src/util/handlers/Message.ts @@ -82,7 +82,7 @@ export async function handleMessage(opts: MessageOptions): Promise { if (opts.message_reference) { permission.hasThrow("READ_MESSAGE_HISTORY"); // code below has to be redone when we add custom message routing and cross-channel replies - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ 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"); -- cgit 1.5.1 From aa38c188ea9e62c7dc8606938b126283457d9768 Mon Sep 17 00:00:00 2001 From: Erkin Alp Güney Date: Fri, 14 Jan 2022 23:03:57 +0300 Subject: Further debranding of premium tiers --- .../skus/#sku_id/subscription-plans.ts | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'api/src') diff --git a/api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts b/api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts index 723a5160..d0b533d8 100644 --- a/api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts +++ b/api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts @@ -14,7 +14,7 @@ const skus = new Map([ interval_count: 1, tax_inclusive: true, sku_id: "521842865731534868", - currency: "usd", + currency: "eur", price: 0, price_tier: null }, @@ -25,7 +25,7 @@ const skus = new Map([ interval_count: 1, tax_inclusive: true, sku_id: "521842865731534868", - currency: "usd", + currency: "eur", price: 0, price_tier: null } @@ -36,23 +36,23 @@ const skus = new Map([ [ { id: "511651871736201216", - name: "Premium Classic Monthly", + name: "Individual Premium Tier 1 Monthly", interval: 1, interval_count: 1, tax_inclusive: true, sku_id: "521846918637420545", - currency: "usd", + currency: "eur", price: 0, price_tier: null }, { id: "511651876987469824", - name: "Premium Classic Yearly", + name: "Individual Premium Tier 1 Yearly", interval: 2, interval_count: 1, tax_inclusive: true, sku_id: "521846918637420545", - currency: "usd", + currency: "eur", price: 0, price_tier: null } @@ -63,34 +63,34 @@ const skus = new Map([ [ { id: "642251038925127690", - name: "Premium Quarterly", + name: "Individual Premium Tier 2 Quarterly", interval: 1, interval_count: 3, tax_inclusive: true, sku_id: "521847234246082599", - currency: "usd", + currency: "eur", price: 0, price_tier: null }, { id: "511651880837840896", - name: "Premium Monthly", + name: "Individual Premium Tier 2 Monthly", interval: 1, interval_count: 1, tax_inclusive: true, sku_id: "521847234246082599", - currency: "usd", + currency: "eur", price: 0, price_tier: null }, { id: "511651885459963904", - name: "Premium Yearly", + name: "Individual Premium Tier 2 Yearly", interval: 2, interval_count: 1, tax_inclusive: true, sku_id: "521847234246082599", - currency: "usd", + currency: "eur", price: 0, price_tier: null } @@ -101,25 +101,25 @@ const skus = new Map([ [ { id: "590665532894740483", - name: "Server Boost Monthly", + name: "Crowd Premium Monthly", interval: 1, interval_count: 1, tax_inclusive: true, sku_id: "590663762298667008", discount_price: 0, - currency: "usd", + currency: "eur", price: 0, price_tier: null }, { id: "590665538238152709", - name: "Server Boost Yearly", + name: "Crowd Premium Yearly", interval: 2, interval_count: 1, tax_inclusive: true, sku_id: "590663762298667008", discount_price: 0, - currency: "usd", + currency: "eur", price: 0, price_tier: null } -- cgit 1.5.1 From dbe88d5b188fc91c560da3b8a839b743acc543b0 Mon Sep 17 00:00:00 2001 From: Chris Chrome Date: Sun, 16 Jan 2022 23:51:04 -0500 Subject: Revert previous commit --- .../skus/#sku_id/subscription-plans.ts | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'api/src') diff --git a/api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts b/api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts index d0b533d8..723a5160 100644 --- a/api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts +++ b/api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts @@ -14,7 +14,7 @@ const skus = new Map([ interval_count: 1, tax_inclusive: true, sku_id: "521842865731534868", - currency: "eur", + currency: "usd", price: 0, price_tier: null }, @@ -25,7 +25,7 @@ const skus = new Map([ interval_count: 1, tax_inclusive: true, sku_id: "521842865731534868", - currency: "eur", + currency: "usd", price: 0, price_tier: null } @@ -36,23 +36,23 @@ const skus = new Map([ [ { id: "511651871736201216", - name: "Individual Premium Tier 1 Monthly", + name: "Premium Classic Monthly", interval: 1, interval_count: 1, tax_inclusive: true, sku_id: "521846918637420545", - currency: "eur", + currency: "usd", price: 0, price_tier: null }, { id: "511651876987469824", - name: "Individual Premium Tier 1 Yearly", + name: "Premium Classic Yearly", interval: 2, interval_count: 1, tax_inclusive: true, sku_id: "521846918637420545", - currency: "eur", + currency: "usd", price: 0, price_tier: null } @@ -63,34 +63,34 @@ const skus = new Map([ [ { id: "642251038925127690", - name: "Individual Premium Tier 2 Quarterly", + name: "Premium Quarterly", interval: 1, interval_count: 3, tax_inclusive: true, sku_id: "521847234246082599", - currency: "eur", + currency: "usd", price: 0, price_tier: null }, { id: "511651880837840896", - name: "Individual Premium Tier 2 Monthly", + name: "Premium Monthly", interval: 1, interval_count: 1, tax_inclusive: true, sku_id: "521847234246082599", - currency: "eur", + currency: "usd", price: 0, price_tier: null }, { id: "511651885459963904", - name: "Individual Premium Tier 2 Yearly", + name: "Premium Yearly", interval: 2, interval_count: 1, tax_inclusive: true, sku_id: "521847234246082599", - currency: "eur", + currency: "usd", price: 0, price_tier: null } @@ -101,25 +101,25 @@ const skus = new Map([ [ { id: "590665532894740483", - name: "Crowd Premium Monthly", + name: "Server Boost Monthly", interval: 1, interval_count: 1, tax_inclusive: true, sku_id: "590663762298667008", discount_price: 0, - currency: "eur", + currency: "usd", price: 0, price_tier: null }, { id: "590665538238152709", - name: "Crowd Premium Yearly", + name: "Server Boost Yearly", interval: 2, interval_count: 1, tax_inclusive: true, sku_id: "590663762298667008", discount_price: 0, - currency: "eur", + currency: "usd", price: 0, price_tier: null } -- cgit 1.5.1 From f9ff5b35f3b65d72302ff131cdd6375d572c1842 Mon Sep 17 00:00:00 2001 From: Erkin Alp Güney Date: Sun, 23 Jan 2022 17:46:04 +0300 Subject: Closed-join guilds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves #537 Signed-off-by: Erkin Alp Güney --- api/src/routes/invites/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'api/src') diff --git a/api/src/routes/invites/index.ts b/api/src/routes/invites/index.ts index ac813126..37e9e05a 100644 --- a/api/src/routes/invites/index.ts +++ b/api/src/routes/invites/index.ts @@ -19,7 +19,8 @@ router.post("/:code", route({}), async (req: Request, res: Response) => { const { features } = await Guild.findOneOrFail({ id: guild_id}); const { public_flags } = await User.findOneOrFail({ id: req.user_id }); - if(features.includes("INTERNAL_EMPLOYEE_ONLY") && (public_flags & 1) !== 1) throw new HTTPError("The Maze isn't meant for you.", 401) + if(features.includes("INTERNAL_EMPLOYEE_ONLY") && (public_flags & 1) !== 1) throw new HTTPError("Only intended for the staff of this server.", 401); + if(features.includes("INVITES_CLOSED")) throw new HTTPError("Sorry, this guild has joins closed.", 403); const invite = await Invite.joinGuild(req.user_id, code); -- cgit 1.5.1 From d6f5a08cb5bda45131e2195b12307204f6e1eebb Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Sat, 15 Jan 2022 18:42:29 +1100 Subject: Add unhandled channel types to IsTextChannel method --- api/src/routes/channels/#channel_id/messages/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'api/src') diff --git a/api/src/routes/channels/#channel_id/messages/index.ts b/api/src/routes/channels/#channel_id/messages/index.ts index c3d3d408..1ae9d676 100644 --- a/api/src/routes/channels/#channel_id/messages/index.ts +++ b/api/src/routes/channels/#channel_id/messages/index.ts @@ -37,7 +37,11 @@ export function isTextChannel(type: ChannelType): boolean { case ChannelType.GUILD_PUBLIC_THREAD: case ChannelType.GUILD_PRIVATE_THREAD: case ChannelType.GUILD_TEXT: + case ChannelType.ENCRYPTED: + case ChannelType.ENCRYPTED_THREAD: return true; + default: + throw new HTTPError("unimplemented", 400); } } @@ -87,7 +91,7 @@ router.get("/", async (req: Request, res: Response) => { permissions.hasThrow("VIEW_CHANNEL"); if (!permissions.has("READ_MESSAGE_HISTORY")) return res.json([]); - var query: FindManyOptions & { where: { id?: any } } = { + var query: FindManyOptions & { where: { id?: any; }; } = { order: { id: "DESC" }, take: limit, where: { channel_id }, @@ -216,7 +220,7 @@ router.post( channel.save() ]); - postHandleMessage(message).catch((e) => {}); // no await as it shouldnt block the message send function and silently catch error + postHandleMessage(message).catch((e) => { }); // no await as it shouldnt block the message send function and silently catch error return res.json(message); } -- cgit 1.5.1