Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
ca825ca7cb
44
Commands.cs
44
Commands.cs
@ -1,8 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using CodeHollow.FeedReader;
|
using CodeHollow.FeedReader;
|
||||||
using NLog;
|
using NLog;
|
||||||
@ -244,18 +247,9 @@ namespace RSSBot {
|
|||||||
|
|
||||||
// Send
|
// Send
|
||||||
foreach (long chatId in feed.Subs.ToList())
|
foreach (long chatId in feed.Subs.ToList())
|
||||||
try {
|
{
|
||||||
await Bot.BotClient.SendTextMessageAsync(chatId, text, ParseMode.Html, true, true);
|
await SendFinishedMessage(chatId, text, feed);
|
||||||
} 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}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,6 +260,32 @@ namespace RSSBot {
|
|||||||
Bot.JobQueue.Change(TimeSpan.FromMinutes(1), TimeSpan.FromMilliseconds(-1));
|
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) {
|
public static async void ShowAvailableFeeds(Message message, GroupCollection args) {
|
||||||
string url = args[1].Value;
|
string url = args[1].Value;
|
||||||
IEnumerable<HtmlFeedLink> feeds;
|
IEnumerable<HtmlFeedLink> feeds;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64;linux-arm</RuntimeIdentifiers>
|
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64;linux-arm</RuntimeIdentifiers>
|
||||||
<Version>1.0.1</Version>
|
<Version>1.1.0</Version>
|
||||||
<!-- <PublishReadyToRun>true</PublishReadyToRun>-->
|
<!-- <PublishReadyToRun>true</PublishReadyToRun>-->
|
||||||
<!-- <PublishSingleFile>true</PublishSingleFile>-->
|
<!-- <PublishSingleFile>true</PublishSingleFile>-->
|
||||||
<SelfContained>false</SelfContained>
|
<SelfContained>false</SelfContained>
|
||||||
@ -17,9 +17,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CodeHollow.FeedReader" Version="1.2.1" />
|
<PackageReference Include="CodeHollow.FeedReader" Version="1.2.1" />
|
||||||
<PackageReference Include="ini-parser" Version="2.5.2" />
|
<PackageReference Include="ini-parser" Version="2.5.2" />
|
||||||
<PackageReference Include="NLog" Version="4.6.8" />
|
<PackageReference Include="NLog" Version="4.7.5" />
|
||||||
<PackageReference Include="StackExchange.Redis" Version="2.0.601" />
|
<PackageReference Include="StackExchange.Redis" Version="2.1.58" />
|
||||||
<PackageReference Include="Telegram.Bot" Version="15.2.0" />
|
<PackageReference Include="Telegram.Bot" Version="15.7.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
Reference in New Issue
Block a user