Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 110 additions & 120 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "axobot-api",
"version": "1.5.2",
"version": "1.6.0",
"description": "A TypeScript API for the Axobot Discord bot",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -38,17 +38,17 @@
},
"dependencies": {
"cache-manager": "^5.4.0",
"compression": "^1.7.4",
"compression": "^1.8.1",
"console-stamp": "^3.1.1",
"cors": "^2.8.5",
"discord.js": "^14.18.0",
"discord.js": "^14.21.0",
"dotenv": "^16.3.1",
"express": "^5.0.1",
"express-rate-limit": "^7.4.0",
"json-bigint": "^1.0.0",
"jsonwebtoken": "^9.0.1",
"mariadb": "^3.2.0",
"morgan": "^1.10.0",
"morgan": "^1.10.1",
"rss-parser": "github:ZRunner/rss-parser",
"typescript-eslint": "^7.1.1",
"typia": "^7.0.0"
Expand Down
7 changes: 7 additions & 0 deletions src/database/guild-config/guild-config-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
"default": 10,
"is_listed": false
},
"quickrss_max_number": {
"type": "int",
"min": 0,
"max": null,
"default": 3,
"is_listed": false
},
"streamers_max_number": {
"type": "int",
"min": 0,
Expand Down
30 changes: 15 additions & 15 deletions src/database/models/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export interface RssFeedForCreation {
roles: string[];
useEmbed: boolean;
embed: {
authorText?: string;
author_text?: string;
title?: string;
footerText?: string;
footer_text?: string;
color?: number;
showDateInFooter?: boolean;
enableLinkInTitle?: boolean;
imageLocation?: "thumbnail" | "banner" | "none";
show_date_in_footer?: boolean;
enable_link_in_title?: boolean;
image_location?: "thumbnail" | "banner" | "none";
};
silentMention: boolean;
enabled: boolean;
Expand All @@ -44,13 +44,13 @@ export interface RssFeedForEdition {
roles: string[];
useEmbed: boolean;
embed: {
authorText?: string;
author_text?: string;
title?: string;
footerText?: string;
footer_text?: string;
color?: number;
showDateInFooter?: boolean;
enableLinkInTitle?: boolean;
imageLocation?: "thumbnail" | "banner" | "none";
show_date_in_footer?: boolean;
enable_link_in_title?: boolean;
image_location?: "thumbnail" | "banner" | "none";
};
silentMention: boolean;
enabled: boolean;
Expand All @@ -66,13 +66,13 @@ export interface DBRssFeed {
roles: bigint[];
useEmbed: boolean;
embed: {
authorText?: string;
author_text?: string;
title?: string;
footerText?: string;
footer_text?: string;
color?: number;
showDateInFooter?: boolean;
enableLinkInTitle?: boolean;
imageLocation?: "thumbnail" | "banner" | "none";
show_date_in_footer?: boolean;
enable_link_in_title?: boolean;
image_location?: "thumbnail" | "banner" | "none";
};
silentMention: boolean;
recentErrors: number;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/discord/controler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChannelType, GuildBasedChannel } from "discord.js";
import { NextFunction, Request, Response } from "express";
import { SqlError } from "mariadb";
import { is } from "typia";
import { equals, is } from "typia";

import DiscordClient from "../../bot/client";
import Database from "../../database/db";
Expand Down Expand Up @@ -664,7 +664,7 @@ export async function editRssFeed(req: Request, res: Response) {
}
// check data validity
const data = req.body;
if (!is<RssFeedPUTData>(data)) {
if (!is<RssFeedPUTData>(data) || !equals<RssFeedPUTData["embed"]>(data.embed)) {
res._err = "Invalid data";
res.status(400).send(res._err);
return;
Expand Down
17 changes: 7 additions & 10 deletions src/modules/discord/types/guilds.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,21 @@ interface RoleRewardsPUTData {
level: string;
}

interface __RssFeedPUT_Common {
interface RssFeedPUTData {
id: string;
channelId: string;
structure: string;
roles: string[];
useEmbed: boolean;
embed: {
authorText?: string;
author_text?: string;
title?: string;
footerText?: string;
footer_text?: string;
color?: number;
showDateInFooter?: boolean;
enableLinkInTitle?: boolean;
imageLocation?: "thumbnail" | "banner" | "none";
show_date_in_footer?: boolean;
enable_link_in_title?: boolean;
image_location?: "thumbnail" | "banner" | "none";
};
silentMention: boolean;
enabled: boolean;
}

interface RssFeedPUTData extends __RssFeedPUT_Common {
id: string;
}
1 change: 1 addition & 0 deletions src/rss/modules/parsed-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface ParsedEntry {
author: string | null;
channel: string | null;
image: string | null;
imageAlt: string | null;
postText: string | null;
postDescription: string | null;
}
27 changes: 18 additions & 9 deletions src/rss/modules/web-rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ export default class WebRss {
})),
});

private imageUrlRegex = new RegExp(
[
"(http(s?):)",
"([/|.\\w\\s-])*",
"\\.(?:jpe?g|gif|png|webp)",
].join(""),
"i"
);

private imageAltRegex = new RegExp(/<img\b[^>]*?(?:title="([^"]+)"|alt="([^"]+)")[^>]*?>/, "i");

async getLastPost(url: string): Promise<ParsedEntry | undefined> {
const feed = await this.getFeed(url);
if (!feed) {
Expand Down Expand Up @@ -63,6 +74,7 @@ export default class WebRss {
author: entry.creator || entry.author || feed.title || null,
channel: feed.title || null,
image: entry.mediaThumbnail?.url || this.extractImageFromEnclosure(entry) || this.extractFirstImageFromContent(entry.content || "") || null,
imageAlt: this.extractFirstImageAltFromContent(entry.content || "") || null,
postText: entry.contentSnippet || null,
postDescription: entry.summary || null,
};
Expand All @@ -76,14 +88,11 @@ export default class WebRss {
}

private extractFirstImageFromContent(content: string): string | null {
const exp = new RegExp(
[
"(http(s?):)",
"([/|.\\w\\s-])*",
"\\.(?:jpe?g|gif|png|webp)",
].join(""),
"i"
);
return content.match(exp)?.[0] || null;
return content.match(this.imageUrlRegex)?.[0] || null;
}

private extractFirstImageAltFromContent(content: string): string | null {
const match = content.match(this.imageAltRegex);
return match?.[1] || match?.[2] || null;
}
}
1 change: 1 addition & 0 deletions src/rss/modules/youtube-rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export default class YouTubeRss {
author: entry.author!,
channel: entry.author!,
image: entry.mediaThumbnail?.url || null,
imageAlt: null,
postText: entry.contentSnippet || null,
postDescription: null,
};
Expand Down