UNPKG

rsshub

Version:
68 lines (66 loc) 2.81 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as config } from "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import "./cache-Bo__VnGm.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as config_not_found_default } from "./config-not-found-Dyp3RlZZ.mjs"; import { a as getGuild, i as getChannelMessages, n as baseUrl, r as getChannel } from "./discord-api-D9fu6pLr.mjs"; import path from "node:path"; //#region lib/routes/discord/channel.ts init_esm_shims(); const route = { path: "/channel/:channelId", categories: ["social-media"], example: "/discord/channel/950465850056536084", parameters: { channelId: "Channel ID" }, features: { requireConfig: [{ name: "DISCORD_AUTHORIZATION", description: "Discord authorization header from the browser" }], requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["discord.com/channels/:guildId/:channelId/:messageID", "discord.com/channels/:guildId/:channelId"] }], name: "Channel Messages", maintainers: ["TonyRL"], handler }; async function handler(ctx) { if (!config.discord || !config.discord.authorization) throw new config_not_found_default("Discord RSS is disabled due to the lack of <a href=\"https://docs.rsshub.app/deploy/config#route-specific-configurations\">relevant config</a>"); const { authorization } = config.discord; const channelId = ctx.req.param("channelId"); const channelInfo = await getChannel(channelId, authorization); const messagesRaw = await getChannelMessages(channelId, authorization, ctx.req.query("limit") ?? 100); const { name: channelName, topic: channelTopic, guild_id: guildId } = channelInfo; const guildInfo = await getGuild(guildId, authorization); const { name: guildName, icon: guidIcon } = guildInfo; const messages = messagesRaw.map((message) => ({ title: message.content.split("\n")[0], description: art(path.join(__dirname, "templates/message-311bc85b.art"), { message, guildInfo }), author: `${message.author.global_name ?? message.author.username}(${message.author.username})`, pubDate: parseDate(message.timestamp), updated: message.edited_timestamp ? parseDate(message.edited_timestamp) : void 0, category: `#${channelName}`, link: `${baseUrl}/channels/${guildId}/${channelId}/${message.id}` })); return { title: `#${channelName} - ${guildName} - Discord`, description: channelTopic, link: `${baseUrl}/channels/${guildId}/${channelId}`, image: `https://cdn.discordapp.com/icons/${guildId}/${guidIcon}.webp`, item: messages, allowEmpty: true }; } //#endregion export { route };