Skip to content

Commit

Permalink
Libraries update
Browse files Browse the repository at this point in the history
  • Loading branch information
pietrodicaprio committed Sep 28, 2022
1 parent 6c53781 commit 3d151fc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 26 deletions.
62 changes: 50 additions & 12 deletions Unifiedban.Terminal/Bot/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Extensions.Polling;
using Telegram.Bot.Exceptions;
using Telegram.Bot.Polling;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.ReplyMarkups;

namespace Unifiedban.Terminal.Bot
{
Expand All @@ -37,7 +35,7 @@ public static void Initialize(string apikey)
if (CacheData.FatalError)
return;

if (String.IsNullOrEmpty(apikey))
if (string.IsNullOrEmpty(apikey))
{
Data.Utils.Logging.AddLog(new Models.SystemLog()
{
Expand Down Expand Up @@ -138,8 +136,14 @@ await BotClient.SendTextMessageAsync(
AllowedUpdates = { }, // receive all update types
ThrowPendingUpdates = throwPendingUpdates
};

BotClient.StartReceiving(
updateHandler: UpdateHandler,
pollingErrorHandler: PollingErrorHandler,
receiverOptions: receiverOptions,
cancellationToken: Cts.Token);

_updateReceiver = new QueuedUpdateReceiver(BotClient, receiverOptions);
/*_updateReceiver = new QueuedUpdateReceiver(BotClient, receiverOptions);
try
{
await foreach (Update update in _updateReceiver.WithCancellation(Cts.Token))
Expand Down Expand Up @@ -182,9 +186,43 @@ await BotClient.SendTextMessageAsync(
Message = ex.InnerException?.Message,
UserId = -2
});
}
}*/

Program.DisposeAll();
// Program.DisposeAll();
}

private static Task PollingErrorHandler(ITelegramBotClient botClient, Exception ex, CancellationToken arg3)
{
var errMsg = ex switch
{
ApiRequestException apiRequestException
=> $"Telegram API Error:\n[{apiRequestException.ErrorCode}]\n{apiRequestException.Message}",
_ => ex.ToString()
};

Data.Utils.Logging.AddLog(new Models.SystemLog()
{
LoggerName = CacheData.LoggerName,
Date = DateTime.Now,
Function = "PollingErrorHandler",
Level = Models.SystemLog.Levels.Fatal,
Message = $"Polling ERROR: {errMsg}",
UserId = -2
});
return Task.CompletedTask;
}

private static async Task UpdateHandler(ITelegramBotClient botClient, Update update, CancellationToken arg3)
{
if (update.Message is not null)
{
await HandleUpdateAsync(update.Message);
}

if (update.CallbackQuery is not null)
{
await HandleCallbackQuery(update.CallbackQuery);
}
}

public static void Dispose()
Expand All @@ -209,7 +247,7 @@ public static void Dispose()

private static async Task HandleCallbackQuery(CallbackQuery callbackQuery)
{
if (callbackQuery.Message.Date < DateTime.Now.AddHours(-pastHoursToSkip))
if (callbackQuery.Message!.Date < DateTime.Now.AddHours(-pastHoursToSkip))
{
Data.Utils.Logging.AddLog(new Models.SystemLog()
{
Expand Down Expand Up @@ -238,7 +276,7 @@ private static async Task HandleCallbackQuery(CallbackQuery callbackQuery)
UserId = -1
});

if (!String.IsNullOrEmpty(callbackQuery.Data))
if (!string.IsNullOrEmpty(callbackQuery.Data))
{
if (callbackQuery.Data.StartsWith('/'))
await Task.Run(() => Command.Parser.Parse(callbackQuery));
Expand All @@ -263,7 +301,7 @@ private static async Task HandleUpdateAsync(Message message)
return;
}

await Task.Run(() => CacheData.IncrementHandledMessages());
await Task.Run(CacheData.IncrementHandledMessages);

if(CacheData.Groups.Keys.Contains(message.Chat.Id))
if (CacheData.Groups[message.Chat.Id].State !=
Expand Down Expand Up @@ -377,7 +415,7 @@ await BotClient.SendTextMessageAsync(message.Chat.Id,
Functions.UserLeftAction(message);
}

if (!String.IsNullOrEmpty(message.MediaGroupId) ||
if (!string.IsNullOrEmpty(message.MediaGroupId) ||
message.Photo != null ||
message.Document != null)
{
Expand Down
27 changes: 13 additions & 14 deletions Unifiedban.Terminal/Unifiedban.Terminal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>3.13.3</Version>
<Version>3.13.4</Version>
<Authors>fabricators</Authors>
<Product>Unifiedban Terminal</Product>
<Copyright>Fabricators 2022</Copyright>
<RepositoryUrl>https://github.com/unified-ban/Terminal</RepositoryUrl>
<RepositoryType>GIT</RepositoryType>
<AssemblyVersion>3.13.3</AssemblyVersion>
<FileVersion>3.13.3.1</FileVersion>
<AssemblyVersion>3.13.4</AssemblyVersion>
<FileVersion>3.13.4.1</FileVersion>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -21,19 +21,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HangFire" Version="1.7.17" />
<PackageReference Include="HangFire.SqlServer" Version="1.7.17" />
<PackageReference Include="log4net" Version="2.0.12" />
<PackageReference Include="HangFire" Version="1.7.31" />
<PackageReference Include="HangFire.SqlServer" Version="1.7.31" />
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Quartz" Version="3.3.3" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
<PackageReference Include="Telegram.Bot" Version="17.0.0" />
<PackageReference Include="RabbitMQ.Client" Version="6.2.2" />
<PackageReference Include="Telegram.Bot.Extensions.Polling" Version="1.0.2" />
<PackageReference Include="Quartz" Version="3.5.0" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
<PackageReference Include="Telegram.Bot" Version="18.0.0" />
<PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 3d151fc

Please sign in to comment.