From 708836d45fb026a40b7c6fc2b8a49ccb60afbc17 Mon Sep 17 00:00:00 2001 From: Eduardo Aznar Date: Tue, 19 Sep 2023 14:56:18 +0200 Subject: [PATCH 1/3] New translations en_us.json (Turkish) --- src/lang/tr_TR.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lang/tr_TR.json b/src/lang/tr_TR.json index 823c2d3a2..935cc56eb 100644 --- a/src/lang/tr_TR.json +++ b/src/lang/tr_TR.json @@ -397,7 +397,7 @@ "redditMembersOnline": { "name": "redditMembersOnline:subreddit", "description": "Bir subredditin aktif üye sayısını gösterir", - "detailedDescription": "Bir subredditin üye sayısını sayar, `subreddit` bölümünü istediğiniz subreddit ile değiştirin", + "detailedDescription": "Bir subredditin üye sayısını gösterir, `subreddit` bölümünü istediğiniz subreddit ile değiştirin", "usage": [ "{redditMembersOnline:subreddit}" ], From ac6a4d5f5aaf1632dd6bd31c06a4e1102871b7e5 Mon Sep 17 00:00:00 2001 From: livingflore Date: Wed, 20 Dec 2023 22:09:08 +0500 Subject: [PATCH 2/3] youtube counter adjusted for handle nickname --- src/counters/YouTube.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/counters/YouTube.ts b/src/counters/YouTube.ts index c3945fffa..2d7ad2015 100644 --- a/src/counters/YouTube.ts +++ b/src/counters/YouTube.ts @@ -4,8 +4,8 @@ const { YOUTUBE_API_KEY } = getEnv(); import Counter from "../typings/Counter"; -const anyChannelMatch = /^((http|https):\/\/|)(www\.|m\.)?youtube\.com\/(channel|user|c)\//; -const usernameChannelMatch = /^((http|https):\/\/|)(www\.|m\.)?youtube\.com\/(user|c)\//; +const legacyUsernameChannelMatch = /^((http|https):\/\/|)(www\.|m\.)?youtube\.com\/(user|c)\//; +const handleUsernameChannelMatch = /^((http|https):\/\/|)(www\.|m\.)?youtube\.com\/\@/; const idChannelMatch = /^((http|https):\/\/|)(www\.|m\.)?youtube\.com\/channel\//; const YouTubeCounter: Counter = { @@ -20,13 +20,20 @@ const YouTubeCounter: Counter = { lifetime: 60 * 60 * 1000, execute: async ({ unparsedArgs: channelUrl }) => { if (!YOUTUBE_API_KEY) throw new Error("YOUTUBE_API_KEY not provided"); - let channel = channelUrl.replace(anyChannelMatch, ""); - let searchChannelBy = ""; - if (usernameChannelMatch.test(channelUrl)) { + let channel = ""; + let searchChannelBy = "id"; + + if (legacyUsernameChannelMatch.test(channelUrl)) { searchChannelBy = "forUsername"; - } else if (idChannelMatch.test(channelUrl)) { - searchChannelBy = "id"; + channel = channelUrl.replace(legacyUsernameChannelMatch, ""); + } if (handleUsernameChannelMatch.test(channelUrl)) { + const getId = await fetch( + `https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&q=${channelUrl.replace(handleUsernameChannelMatch, "")}&type=channel&key=${YOUTUBE_API_KEY}` + ).then((response) => response.json()); + channel = getId.items?.[0]?.id.channelId; + } if (idChannelMatch.test(channelUrl)) { + channel = channelUrl.replace(idChannelMatch, "") } else { throw new Error(`Invalid youtube channel url: ${channelUrl}`); } From 039343d87fa271d8cc2e5f350806352f9cfdcbc3 Mon Sep 17 00:00:00 2001 From: Eduardo Aznar Date: Wed, 20 Dec 2023 20:33:06 +0100 Subject: [PATCH 3/3] Bug fix --- src/counters/YouTube.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/counters/YouTube.ts b/src/counters/YouTube.ts index 2d7ad2015..5ac17bdda 100644 --- a/src/counters/YouTube.ts +++ b/src/counters/YouTube.ts @@ -27,12 +27,12 @@ const YouTubeCounter: Counter = { if (legacyUsernameChannelMatch.test(channelUrl)) { searchChannelBy = "forUsername"; channel = channelUrl.replace(legacyUsernameChannelMatch, ""); - } if (handleUsernameChannelMatch.test(channelUrl)) { + } else if (handleUsernameChannelMatch.test(channelUrl)) { const getId = await fetch( `https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&q=${channelUrl.replace(handleUsernameChannelMatch, "")}&type=channel&key=${YOUTUBE_API_KEY}` ).then((response) => response.json()); channel = getId.items?.[0]?.id.channelId; - } if (idChannelMatch.test(channelUrl)) { + } else if (idChannelMatch.test(channelUrl)) { channel = channelUrl.replace(idChannelMatch, "") } else { throw new Error(`Invalid youtube channel url: ${channelUrl}`);