Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Akamaru 2020-11-05 19:34:46 +01:00
commit ca825ca7cb
2 changed files with 36 additions and 16 deletions

View File

@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using CodeHollow.FeedReader;
using NLog;
@ -244,18 +247,9 @@ namespace RSSBot {
// Send
foreach (long chatId in feed.Subs.ToList())
try {
await Bot.BotClient.SendTextMessageAsync(chatId, text, ParseMode.Html, true, true);
} catch (ApiRequestException e) {
if (e.ErrorCode.Equals(403)) {
Logger.Warn(e.Message);
feed.Cleanup(chatId);
if (feed.Subs.Count == 0) // was last subscriber
Bot.RssBotFeeds.Remove(feed);
} else {
Logger.Error($"{e.ErrorCode}: {e.Message}");
}
}
{
await SendFinishedMessage(chatId, text, feed);
}
}
}
@ -266,6 +260,32 @@ namespace RSSBot {
Bot.JobQueue.Change(TimeSpan.FromMinutes(1), TimeSpan.FromMilliseconds(-1));
}
private static async Task SendFinishedMessage(long chatId, string text, RssBotFeed feed, int waitTime = 10)
{
try
{
await Bot.BotClient.SendTextMessageAsync(chatId, text, ParseMode.Html, true, true);
Thread.Sleep(1000);
} catch (ApiRequestException e)
{
if (e.ErrorCode.Equals(403))
{
Logger.Warn(e.Message);
feed.Cleanup(chatId);
if (feed.Subs.Count == 0) // was last subscriber
Bot.RssBotFeeds.Remove(feed);
} else
{
Logger.Error($"{e.ErrorCode}: {e.Message}");
}
} catch (HttpRequestException e) // likely 429
{
Logger.Warn($"Got rate limited, waiting {waitTime} seconds...");
Thread.Sleep(waitTime * 1000);
await SendFinishedMessage(chatId, text, feed, (waitTime * 2));
}
}
public static async void ShowAvailableFeeds(Message message, GroupCollection args) {
string url = args[1].Value;
IEnumerable<HtmlFeedLink> feeds;

View File

@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64;linux-arm</RuntimeIdentifiers>
<Version>1.0.1</Version>
<Version>1.1.0</Version>
<!-- <PublishReadyToRun>true</PublishReadyToRun>-->
<!-- <PublishSingleFile>true</PublishSingleFile>-->
<SelfContained>false</SelfContained>
@ -17,9 +17,9 @@
<ItemGroup>
<PackageReference Include="CodeHollow.FeedReader" Version="1.2.1" />
<PackageReference Include="ini-parser" Version="2.5.2" />
<PackageReference Include="NLog" Version="4.6.8" />
<PackageReference Include="StackExchange.Redis" Version="2.0.601" />
<PackageReference Include="Telegram.Bot" Version="15.2.0" />
<PackageReference Include="NLog" Version="4.7.5" />
<PackageReference Include="StackExchange.Redis" Version="2.1.58" />
<PackageReference Include="Telegram.Bot" Version="15.7.1" />
</ItemGroup>
</Project>