Skip to content

Commit 98ee753

Browse files
committed
better url regex
1 parent 6dde0ea commit 98ee753

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ bot.telegram.getMe().then((botInfo) => {
5858
});
5959

6060
bot.hears(
61-
/^http(s)?:\/\/\w+\.\w+.*(\w|\/)/gm,
61+
/(((https?:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w\-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\\w]*))?)/gm,
6262
sendError,
6363
async (ctx, next) => {
6464
ctx.state.chat = await ctx.getChat();

middlewares/sub-multi-url.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ const RSS = require('../proxies/rssFeed');
44
const i18n = require('../i18n');
55

66
module.exports = async (ctx, next) => {
7-
const urls = ctx.message.text.match(/^http(s)?:\/\/\w+\.\w+.*(\w|\/)/gm);
7+
const urls = ctx.message.text.match(
8+
/(((https?:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w\-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\\w]*))?)/gm
9+
);
810
const feedsReady = await Promise.all(
911
urls.map(async (url) => {
1012
url = decodeURI(url);

0 commit comments

Comments
 (0)