Skip to content

Commit

Permalink
Update dependencies; bump .net to 8.0 (#180)
Browse files Browse the repository at this point in the history
* Update dependencies; bump .net to 8.0
  • Loading branch information
voed authored Feb 9, 2025
1 parent f20f8b9 commit f3c6b9c
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 53 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.x.x
dotnet-version: |
6.x.x
8.x.x
- name: Restore dependencies
run: |
Expand Down
12 changes: 6 additions & 6 deletions TGBotFramework/BotFramework.Tests/BotFramework.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Watson" Version="6.0.2" />
<PackageReference Include="Watson" Version="6.3.5" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions TGBotFramework/BotFramework.Webhook/WebhookUpdateProvider.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Net;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using BotFramework.Abstractions.UpdateProvider;
using BotFramework.Config;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Telegram.Bot;
using Telegram.Bot.Types;
using WatsonWebserver.Core;
Expand Down Expand Up @@ -43,13 +43,13 @@ public async Task StartAsync(CancellationToken token)
var server = new WatsonWebserver.Webserver(GetWebserverSettings(), Route);
_ = server.StartAsync(_canRunTokenSource.Token);

await _client.SetWebhookAsync(_config.Webhook.Url, secretToken: _secretToken, cancellationToken: token);
await _client.SetWebhook(_config.Webhook.Url, secretToken: _secretToken, cancellationToken: token);
}

public async Task StopAsync(CancellationToken token)
{
_canRunTokenSource.Cancel();
await _client.DeleteWebhookAsync(cancellationToken: token);
await _client.DeleteWebhook(cancellationToken: token);
}

private async Task Route(HttpContextBase ctx)
Expand All @@ -65,7 +65,7 @@ private async Task Route(HttpContextBase ctx)

try
{
var obj = JsonConvert.DeserializeObject<Update>(request.DataAsString);
var obj = JsonSerializer.Deserialize<Update>(request.DataAsString);
if (obj != null)
{
_updateTarget.Push(obj);
Expand Down
2 changes: 1 addition & 1 deletion TGBotFramework/BotFramework/Attributes/MessageAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private bool CanHandleMessage(Message message)
MessageFlag.HasVideoChatStarted => message.VideoChatStarted != null,
MessageFlag.HasVideoChatEnded => message.VideoChatEnded != null,
MessageFlag.HasVideoChatParticipantsInvited => message.VideoChatParticipantsInvited != null,
MessageFlag.HasMediaSpoiler => message.HasMediaSpoiler ?? false,
MessageFlag.HasMediaSpoiler => message.HasMediaSpoiler,
MessageFlag.HasInvoice => message.Invoice != null,
MessageFlag.HasPassportData => message.PassportData != null,
MessageFlag.HasSuccessfulPayment => message.SuccessfulPayment != null,
Expand Down
2 changes: 1 addition & 1 deletion TGBotFramework/BotFramework/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private async Task<User> GetMeSafeAsync(CancellationToken cancellationToken)
{
try
{
return await BotClient.GetMeAsync(cancellationToken);
return await BotClient.GetMe(cancellationToken);
} catch (Exception e)
{
Console.WriteLine(e);
Expand Down
12 changes: 6 additions & 6 deletions TGBotFramework/BotFramework/BotFramework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@

<ItemGroup>
<PackageReference Include="HttpToSocks5Proxy" Version="1.4.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.2" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.5.119">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.1" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.7.115">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Telegram.Bot" Version="19.0.0-preview.2" />
<PackageReference Include="Telegram.Bot" Version="22.3.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion TGBotFramework/BotFramework/ServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void AddTelegramBot(this IServiceCollection collection)
public static void AddTelegramBot<T>(this IServiceCollection collection) where T: BotStartup, new()
{
var startup = new T();

foreach (var ware in startup.__SetupInternal())
{
collection.AddScoped(typeof(IMiddleware),ware);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public PollingUpdateProvider(ITelegramBotClient client, IUpdateTarget updateTarg

public async Task StartAsync(CancellationToken token)
{
await _client.DeleteWebhookAsync(cancellationToken: token);
await _client.DeleteWebhook(cancellationToken: token);
token.ThrowIfCancellationRequested();
_client.StartReceiving(
HandleUpdateAsync,
HandleErrorAsync,
new ReceiverOptions { ThrowPendingUpdates = false },
new ReceiverOptions { DropPendingUpdates = false },
_canRunTokenSource.Token
);
}
Expand Down
6 changes: 3 additions & 3 deletions TGBotFramework/BotFramework/Utils/BotExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public static Task<Message> SendHtmlStringAsync(this ITelegramBotClient bot, Cha
{
if(replyTo == null)
{
return bot.SendTextMessageAsync(chat, message.ToString(), parseMode: ParseMode.Html);
return bot.SendMessage(chat, message.ToString(), parseMode: ParseMode.Html);
}

return bot.SendTextMessageAsync(chat, message.ToString(), parseMode: ParseMode.Html, replyToMessageId: replyTo.Value);
var replyParams = new ReplyParameters() { ChatId = chat.Id, MessageId = replyTo.Value };
return bot.SendMessage(chat, message.ToString(), parseMode: ParseMode.Html, replyParams);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
26 changes: 13 additions & 13 deletions TGBotFramework/Examples/BotAsWorkerService/EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ public class EventHandler:BotEventHandler
[Command("start", CommandParseMode.Both), Priority(10)]
public async Task<bool> Start()
{
await Bot.SendTextMessageAsync(Chat, "Hello! U started me =)");
await Bot.SendMessage(Chat, "Hello! U started me =)");
return false;
}

//Answer on message with "ban" text
[TextMessage("ban", textContent: TextContent.Caption)]
public async Task Ban() => await Bot.SendTextMessageAsync(Chat, "I will ban you right now! Just kidding");
public async Task Ban() => await Bot.SendMessage(Chat, "I will ban you right now! Just kidding");

//Answer on message that satisfy provided regex expression
[RegexTextMessage("^.*?(?i)python$")]
public async Task Task() => await Bot.SendTextMessageAsync(Chat, "I hate snakes");
public async Task Task() => await Bot.SendMessage(Chat, "I hate snakes");

//Answer on any update
[Update(UpdateFlag.All)]
public async Task Update() => await Bot.SendTextMessageAsync(Chat, "Hello");
public async Task Update() => await Bot.SendMessage(Chat, "Hello");

[Update(UpdateFlag.CallbackQuery)]
public async Task CBQuery()
{
await Bot.SendTextMessageAsync(Chat, "callback");
await Bot.SendMessage(Chat, "callback");
}

[Command("query", CommandParseMode.Both)]
Expand All @@ -54,12 +54,12 @@ public async Task HandleQuery()
}
};

await Bot.SendTextMessageAsync(Chat.Id, "123", replyMarkup: new InlineKeyboardMarkup(buttons));
await Bot.SendMessage(Chat.Id, "123", replyMarkup: new InlineKeyboardMarkup(buttons));
}

//Answer on message that contains photo or video
[Message(MessageFlag.HasPhoto | MessageFlag.HasVideo)]
public async Task PhotoVideo() => await Bot.SendTextMessageAsync(Chat, "Send me more!");
public async Task PhotoVideo() => await Bot.SendMessage(Chat, "Send me more!");

//Answer on command with parameters: "/me hello"
[ParametrizedCommand("me", CommandParseMode.Both)]
Expand All @@ -70,27 +70,27 @@ public async Task Me(MeParam me)
{
user += $" {From.LastName}";
}
await Bot.SendTextMessageAsync(Chat, $"<code>{user} says: {me.Text}</code>", parseMode: ParseMode.Html);
await Bot.SendMessage(Chat, $"<code>{user} says: {me.Text}</code>", parseMode: ParseMode.Html);
}

//Parametrized command with int parameter: "/status 2"
[ParametrizedCommand("status", CommandParseMode.Both)]
public async Task Status(int status)
{
await Bot.SendTextMessageAsync(Chat, "status " + status);
await Bot.SendMessage(Chat, "status " + status);
}

[Command("command1", CommandParseMode.WithUsername)]
public async Task Command1()
{
await Bot.SendTextMessageAsync(Chat, "Command1");
await Bot.SendMessage(Chat, "Command1");
}

[Message(MessageFlag.IsReply)]
[Command("command2")]
public async Task Command2()
{
await Bot.SendTextMessageAsync(Chat, "Command2");
await Bot.SendMessage(Chat, "Command2");
}

[HandleCondition(ConditionType.Any)]
Expand All @@ -100,7 +100,7 @@ public async Task Command2()
[Message(MessageFlag.HasText)]
public async Task<bool> MultiAttr()
{
await Bot.SendTextMessageAsync(Chat.Id, "multi attributes");
await Bot.SendMessage(Chat.Id, "multi attributes");
return true;
}

Expand All @@ -109,7 +109,7 @@ public async Task<bool> MultiAttr()
[Message(MessageFlag.HasCaption)]
public async Task<bool> MultiAttr2()
{
await Bot.SendTextMessageAsync(Chat.Id, "Message with photo AND caption");
await Bot.SendMessage(Chat.Id, "Message with photo AND caption");
return true;
}

Expand Down
8 changes: 4 additions & 4 deletions TGBotFramework/Examples/MsgDumpBot/EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task MsgDump()
if(msg.ReplyToMessage != null)
{
string jmsg = JsonConvert.SerializeObject(msg, Formatting.Indented);
await Bot.SendTextMessageAsync(Chat.Id, $"<code>{jmsg}</code>", parseMode: ParseMode.Html);
await Bot.SendMessage(Chat.Id, $"<code>{jmsg}</code>", parseMode: ParseMode.Html);
}
}

Expand Down Expand Up @@ -54,7 +54,7 @@ public async Task StoreSession(string arg)

Context.SessionProvider.SaveSession(session);

await Context.Instance.BotClient.SendTextMessageAsync(Chat, "Stored!");
await Context.Instance.BotClient.SendMessage(Chat, "Stored!");
}

[ParametrizedCommand("get", CommandParseMode.Both)]
Expand All @@ -64,11 +64,11 @@ public async Task Get(string arg)

if(session.SessionData.ContainsKey(arg))
{
await Bot.SendTextMessageAsync(Chat, $"Data is: {(session.SessionData[arg] as SessionData).Data.Data}");
await Bot.SendMessage(Chat, $"Data is: {(session.SessionData[arg] as SessionData).Data.Data}");
}
else
{
await Bot.SendTextMessageAsync(Chat, "No data!");
await Bot.SendMessage(Chat, "No data!");
}

}
Expand Down
6 changes: 3 additions & 3 deletions TGBotFramework/Examples/MsgDumpBot/MsgDumpBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 5 additions & 3 deletions TGBotFramework/Examples/Webhooks/EventHandler.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using BotFramework;
using System.Text.Json;
using BotFramework;
using BotFramework.Attributes;
using BotFramework.Utils;
using Newtonsoft.Json;

namespace Webhooks;

public class EventHandler : BotEventHandler
{
private static readonly JsonSerializerOptions DumpOptions = new() { WriteIndented = true };

[Command("dump")]
public async Task HandleDump()
{
var message = RawUpdate.Message!.ReplyToMessage ?? RawUpdate.Message;
var text = HtmlString.Empty
.CodeWithStyle("language-json", JsonConvert.SerializeObject(message, Formatting.Indented));
.CodeWithStyle("language-json", JsonSerializer.Serialize(message, DumpOptions));

await Bot.SendHtmlStringAsync(Chat, text, replyTo: message.MessageId);
}
Expand Down
4 changes: 2 additions & 2 deletions TGBotFramework/Examples/Webhooks/Webhooks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit f3c6b9c

Please sign in to comment.