summary refs log tree commit diff
path: root/api/src/util
diff options
context:
space:
mode:
authoruurgothat <cckhmck@gmail.com>2021-10-17 21:49:46 +0300
committeruurgothat <cckhmck@gmail.com>2021-10-17 21:49:46 +0300
commitdb3d6e116a3b49669103abdf5f2d156b2c78c3c4 (patch)
tree1a1a5f4d03ca5d0b94ca5f47456e7cd536ba21e7 /api/src/util
parentMerge branch 'master' of https://github.com/fosscord/fosscord-server (diff)
parentUpdate README.md (diff)
downloadserver-db3d6e116a3b49669103abdf5f2d156b2c78c3c4.tar.xz
Merge branch 'master' of https://github.com/fosscord/fosscord-server
Diffstat (limited to 'api/src/util')
-rw-r--r--api/src/util/Instance.ts15
-rw-r--r--api/src/util/Message.ts6
2 files changed, 13 insertions, 8 deletions
diff --git a/api/src/util/Instance.ts b/api/src/util/Instance.ts

index a7b3205a..6bddfa98 100644 --- a/api/src/util/Instance.ts +++ b/api/src/util/Instance.ts
@@ -1,4 +1,4 @@ -import { Config, Guild } from "@fosscord/util"; +import { Config, Guild, Session } from "@fosscord/util"; export async function initInstance() { // TODO: clean up database and delete tombstone data @@ -8,11 +8,14 @@ export async function initInstance() { // TODO: check if any current user is not part of autoJoinGuilds const { autoJoin } = Config.get().guild; - if (autoJoin.enabled && autoJoin.guilds?.length) { + if (autoJoin.enabled && !autoJoin.guilds?.length) { let guild = await Guild.findOne({}); - if (!guild) guild = await Guild.createGuild({}); - - // @ts-ignore - await Config.set({ guild: { autoJoin: { guilds: [guild.id] } } }); + if (guild) { + // @ts-ignore + await Config.set({ guild: { autoJoin: { guilds: [guild.id] } } }); + } } + + // TODO: do no clear sessions for instance cluster + await Session.delete({}); } diff --git a/api/src/util/Message.ts b/api/src/util/Message.ts
index f8230124..d14d3aa2 100644 --- a/api/src/util/Message.ts +++ b/api/src/util/Message.ts
@@ -24,7 +24,8 @@ import fetch from "node-fetch"; import cheerio from "cheerio"; import { MessageCreateSchema } from "../routes/channels/#channel_id/messages"; -// TODO: check webhook, application, system author +// TODO: check webhook, application, system author, stickers +// TODO: embed gifs/videos/images const LINK_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g; @@ -45,6 +46,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { const message = new Message({ ...opts, + sticker_items: opts.sticker_ids?.map((x) => ({ id: x })), guild_id: channel.guild_id, channel_id: opts.channel_id, attachments: opts.attachments || [], @@ -81,7 +83,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { } // TODO: stickers/activity - if (!opts.content && !opts.embeds?.length && !opts.attachments?.length) { + if (!opts.content && !opts.embeds?.length && !opts.attachments?.length && !opts.sticker_ids?.length) { throw new HTTPError("Empty messages are not allowed", 50006); }