Skip to content

Commit 623348b

Browse files
authored
v1.6.0 (#26)
2 parents ec4afca + ebbf371 commit 623348b

9 files changed

Lines changed: 165 additions & 160 deletions

File tree

package-lock.json

Lines changed: 110 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "axobot-api",
3-
"version": "1.5.2",
3+
"version": "1.6.0",
44
"description": "A TypeScript API for the Axobot Discord bot",
55
"main": "index.js",
66
"scripts": {
@@ -38,17 +38,17 @@
3838
},
3939
"dependencies": {
4040
"cache-manager": "^5.4.0",
41-
"compression": "^1.7.4",
41+
"compression": "^1.8.1",
4242
"console-stamp": "^3.1.1",
4343
"cors": "^2.8.5",
44-
"discord.js": "^14.18.0",
44+
"discord.js": "^14.21.0",
4545
"dotenv": "^16.3.1",
4646
"express": "^5.0.1",
4747
"express-rate-limit": "^7.4.0",
4848
"json-bigint": "^1.0.0",
4949
"jsonwebtoken": "^9.0.1",
5050
"mariadb": "^3.2.0",
51-
"morgan": "^1.10.0",
51+
"morgan": "^1.10.1",
5252
"rss-parser": "github:ZRunner/rss-parser",
5353
"typescript-eslint": "^7.1.1",
5454
"typia": "^7.0.0"

src/database/guild-config/guild-config-options.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
"default": 10,
4141
"is_listed": false
4242
},
43+
"quickrss_max_number": {
44+
"type": "int",
45+
"min": 0,
46+
"max": null,
47+
"default": 3,
48+
"is_listed": false
49+
},
4350
"streamers_max_number": {
4451
"type": "int",
4552
"min": 0,

src/database/models/rss.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ export interface RssFeedForCreation {
2525
roles: string[];
2626
useEmbed: boolean;
2727
embed: {
28-
authorText?: string;
28+
author_text?: string;
2929
title?: string;
30-
footerText?: string;
30+
footer_text?: string;
3131
color?: number;
32-
showDateInFooter?: boolean;
33-
enableLinkInTitle?: boolean;
34-
imageLocation?: "thumbnail" | "banner" | "none";
32+
show_date_in_footer?: boolean;
33+
enable_link_in_title?: boolean;
34+
image_location?: "thumbnail" | "banner" | "none";
3535
};
3636
silentMention: boolean;
3737
enabled: boolean;
@@ -44,13 +44,13 @@ export interface RssFeedForEdition {
4444
roles: string[];
4545
useEmbed: boolean;
4646
embed: {
47-
authorText?: string;
47+
author_text?: string;
4848
title?: string;
49-
footerText?: string;
49+
footer_text?: string;
5050
color?: number;
51-
showDateInFooter?: boolean;
52-
enableLinkInTitle?: boolean;
53-
imageLocation?: "thumbnail" | "banner" | "none";
51+
show_date_in_footer?: boolean;
52+
enable_link_in_title?: boolean;
53+
image_location?: "thumbnail" | "banner" | "none";
5454
};
5555
silentMention: boolean;
5656
enabled: boolean;
@@ -66,13 +66,13 @@ export interface DBRssFeed {
6666
roles: bigint[];
6767
useEmbed: boolean;
6868
embed: {
69-
authorText?: string;
69+
author_text?: string;
7070
title?: string;
71-
footerText?: string;
71+
footer_text?: string;
7272
color?: number;
73-
showDateInFooter?: boolean;
74-
enableLinkInTitle?: boolean;
75-
imageLocation?: "thumbnail" | "banner" | "none";
73+
show_date_in_footer?: boolean;
74+
enable_link_in_title?: boolean;
75+
image_location?: "thumbnail" | "banner" | "none";
7676
};
7777
silentMention: boolean;
7878
recentErrors: number;

src/modules/discord/controler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ChannelType, GuildBasedChannel } from "discord.js";
22
import { NextFunction, Request, Response } from "express";
33
import { SqlError } from "mariadb";
4-
import { is } from "typia";
4+
import { equals, is } from "typia";
55

66
import DiscordClient from "../../bot/client";
77
import Database from "../../database/db";
@@ -664,7 +664,7 @@ export async function editRssFeed(req: Request, res: Response) {
664664
}
665665
// check data validity
666666
const data = req.body;
667-
if (!is<RssFeedPUTData>(data)) {
667+
if (!is<RssFeedPUTData>(data) || !equals<RssFeedPUTData["embed"]>(data.embed)) {
668668
res._err = "Invalid data";
669669
res.status(400).send(res._err);
670670
return;

src/modules/discord/types/guilds.d.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,21 @@ interface RoleRewardsPUTData {
3838
level: string;
3939
}
4040

41-
interface __RssFeedPUT_Common {
41+
interface RssFeedPUTData {
42+
id: string;
4243
channelId: string;
4344
structure: string;
4445
roles: string[];
4546
useEmbed: boolean;
4647
embed: {
47-
authorText?: string;
48+
author_text?: string;
4849
title?: string;
49-
footerText?: string;
50+
footer_text?: string;
5051
color?: number;
51-
showDateInFooter?: boolean;
52-
enableLinkInTitle?: boolean;
53-
imageLocation?: "thumbnail" | "banner" | "none";
52+
show_date_in_footer?: boolean;
53+
enable_link_in_title?: boolean;
54+
image_location?: "thumbnail" | "banner" | "none";
5455
};
5556
silentMention: boolean;
5657
enabled: boolean;
57-
}
58-
59-
interface RssFeedPUTData extends __RssFeedPUT_Common {
60-
id: string;
6158
}

src/rss/modules/parsed-entry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface ParsedEntry {
66
author: string | null;
77
channel: string | null;
88
image: string | null;
9+
imageAlt: string | null;
910
postText: string | null;
1011
postDescription: string | null;
1112
}

src/rss/modules/web-rss.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ export default class WebRss {
1414
})),
1515
});
1616

17+
private imageUrlRegex = new RegExp(
18+
[
19+
"(http(s?):)",
20+
"([/|.\\w\\s-])*",
21+
"\\.(?:jpe?g|gif|png|webp)",
22+
].join(""),
23+
"i"
24+
);
25+
26+
private imageAltRegex = new RegExp(/<img\b[^>]*?(?:title="([^"]+)"|alt="([^"]+)")[^>]*?>/, "i");
27+
1728
async getLastPost(url: string): Promise<ParsedEntry | undefined> {
1829
const feed = await this.getFeed(url);
1930
if (!feed) {
@@ -63,6 +74,7 @@ export default class WebRss {
6374
author: entry.creator || entry.author || feed.title || null,
6475
channel: feed.title || null,
6576
image: entry.mediaThumbnail?.url || this.extractImageFromEnclosure(entry) || this.extractFirstImageFromContent(entry.content || "") || null,
77+
imageAlt: this.extractFirstImageAltFromContent(entry.content || "") || null,
6678
postText: entry.contentSnippet || null,
6779
postDescription: entry.summary || null,
6880
};
@@ -76,14 +88,11 @@ export default class WebRss {
7688
}
7789

7890
private extractFirstImageFromContent(content: string): string | null {
79-
const exp = new RegExp(
80-
[
81-
"(http(s?):)",
82-
"([/|.\\w\\s-])*",
83-
"\\.(?:jpe?g|gif|png|webp)",
84-
].join(""),
85-
"i"
86-
);
87-
return content.match(exp)?.[0] || null;
91+
return content.match(this.imageUrlRegex)?.[0] || null;
92+
}
93+
94+
private extractFirstImageAltFromContent(content: string): string | null {
95+
const match = content.match(this.imageAltRegex);
96+
return match?.[1] || match?.[2] || null;
8897
}
8998
}

src/rss/modules/youtube-rss.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export default class YouTubeRss {
141141
author: entry.author!,
142142
channel: entry.author!,
143143
image: entry.mediaThumbnail?.url || null,
144+
imageAlt: null,
144145
postText: entry.contentSnippet || null,
145146
postDescription: null,
146147
};

0 commit comments

Comments
 (0)