diff --git a/.gitea/workflows/TelegramBotFramework.nuget.yaml b/.gitea/workflows/TelegramBotFramework.nuget.yaml
new file mode 100644
index 0000000..71a0150
--- /dev/null
+++ b/.gitea/workflows/TelegramBotFramework.nuget.yaml
@@ -0,0 +1,43 @@
+name: build nuget workflow for TelegramBotBase project
+on:
+ push:
+ branches:
+ - master
+
+jobs:
+ Build-TelegramBotBase:
+ env:
+ APP_PROJECT_NAME: TelegramBotBase
+ strategy:
+ matrix:
+ os:
+ - linux
+ # - win
+ arch:
+ - x64
+ #- x32
+ #- arch64
+ runs-on: [ "${{ matrix.os }}" ]
+ steps:
+ - name: Check out repository code
+ uses: actions/checkout@v4
+
+ - name: Setup dotnet
+ uses: actions/setup-dotnet@v3
+ with:
+ dotnet-version: '8.0.x'
+
+ - name: Restore dependencies
+ run: dotnet restore $APP_PROJECT_NAME
+
+ - name: Build app
+ run: dotnet build -c Release --no-restore $APP_PROJECT_NAME
+
+ - name: Pack app
+ run: dotnet pack --no-build $APP_PROJECT_NAME
+
+ - name: asd
+ run: dotnet nuget add source --name gitea --api-key ${{ secrets.kosyakmakc_nuget_publish }} https://git.kosyakmakc.ru/api/packages/kosyakmakc/nuget/index.json
+
+ - name: Upload nuget package
+ run: dotnet nuget push --source {source_name} {package_file}
diff --git a/TelegramBotBase/Base/DataResult.cs b/TelegramBotBase/Base/DataResult.cs
index 56ca7ca..63654bd 100644
--- a/TelegramBotBase/Base/DataResult.cs
+++ b/TelegramBotBase/Base/DataResult.cs
@@ -55,7 +55,7 @@ public class DataResult : ResultBase
{
var encryptedContent = new MemoryStream();
encryptedContent.SetLength(Document.FileSize.Value);
- var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId,
+ var file = await Device.Client.TelegramClient.GetInfoAndDownloadFile(Document.FileId,
encryptedContent);
return InputFile.FromStream(encryptedContent, Document.FileName);
@@ -69,9 +69,9 @@ public class DataResult : ResultBase
///
public async Task DownloadDocument(string path)
{
- var file = await Device.Client.TelegramClient.GetFileAsync(Document.FileId);
+ var file = await Device.Client.TelegramClient.GetFile(Document.FileId);
var fs = new FileStream(path, FileMode.Create);
- await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
+ await Device.Client.TelegramClient.DownloadFile(file.FilePath, fs);
fs.Close();
fs.Dispose();
}
@@ -83,7 +83,7 @@ public class DataResult : ResultBase
public async Task DownloadRawDocument()
{
var ms = new MemoryStream();
- await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId, ms);
+ await Device.Client.TelegramClient.GetInfoAndDownloadFile(Document.FileId, ms);
return ms.ToArray();
}
@@ -103,7 +103,7 @@ public class DataResult : ResultBase
public async Task DownloadRawTextDocument(Encoding encoding)
{
var ms = new MemoryStream();
- await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId, ms);
+ await Device.Client.TelegramClient.GetInfoAndDownloadFile(Document.FileId, ms);
ms.Position = 0;
@@ -116,16 +116,16 @@ public class DataResult : ResultBase
{
var encryptedContent = new MemoryStream();
encryptedContent.SetLength(Video.FileSize.Value);
- var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Video.FileId, encryptedContent);
+ var file = await Device.Client.TelegramClient.GetInfoAndDownloadFile(Video.FileId, encryptedContent);
return InputFile.FromStream(encryptedContent, "");
}
public async Task DownloadVideo(string path)
{
- var file = await Device.Client.TelegramClient.GetFileAsync(Video.FileId);
+ var file = await Device.Client.TelegramClient.GetFile(Video.FileId);
var fs = new FileStream(path, FileMode.Create);
- await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
+ await Device.Client.TelegramClient.DownloadFile(file.FilePath, fs);
fs.Close();
fs.Dispose();
}
@@ -134,16 +134,16 @@ public class DataResult : ResultBase
{
var encryptedContent = new MemoryStream();
encryptedContent.SetLength(Audio.FileSize.Value);
- var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Audio.FileId, encryptedContent);
+ var file = await Device.Client.TelegramClient.GetInfoAndDownloadFile(Audio.FileId, encryptedContent);
return InputFile.FromStream(encryptedContent, "");
}
public async Task DownloadAudio(string path)
{
- var file = await Device.Client.TelegramClient.GetFileAsync(Audio.FileId);
+ var file = await Device.Client.TelegramClient.GetFile(Audio.FileId);
var fs = new FileStream(path, FileMode.Create);
- await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
+ await Device.Client.TelegramClient.DownloadFile(file.FilePath, fs);
fs.Close();
fs.Dispose();
}
@@ -153,7 +153,7 @@ public class DataResult : ResultBase
var photo = Photos[index];
var encryptedContent = new MemoryStream();
encryptedContent.SetLength(photo.FileSize.Value);
- var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(photo.FileId, encryptedContent);
+ var file = await Device.Client.TelegramClient.GetInfoAndDownloadFile(photo.FileId, encryptedContent);
return InputFile.FromStream(encryptedContent, "");
}
@@ -161,9 +161,9 @@ public class DataResult : ResultBase
public async Task DownloadPhoto(int index, string path)
{
var photo = Photos[index];
- var file = await Device.Client.TelegramClient.GetFileAsync(photo.FileId);
+ var file = await Device.Client.TelegramClient.GetFile(photo.FileId);
var fs = new FileStream(path, FileMode.Create);
- await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
+ await Device.Client.TelegramClient.DownloadFile(file.FilePath, fs);
fs.Close();
fs.Dispose();
}
diff --git a/TelegramBotBase/Base/MessageClient.cs b/TelegramBotBase/Base/MessageClient.cs
index 5d82f8d..bbbfd70 100644
--- a/TelegramBotBase/Base/MessageClient.cs
+++ b/TelegramBotBase/Base/MessageClient.cs
@@ -103,7 +103,7 @@ public class MessageClient
var receiverOptions = new ReceiverOptions();
- receiverOptions.ThrowPendingUpdates = ThrowPendingUpdates;
+ receiverOptions.DropPendingUpdates = ThrowPendingUpdates;
TelegramClient.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions, _cancellationTokenSource.Token);
}
diff --git a/TelegramBotBase/Base/MessageResult.cs b/TelegramBotBase/Base/MessageResult.cs
index f1224c3..13be4ce 100644
--- a/TelegramBotBase/Base/MessageResult.cs
+++ b/TelegramBotBase/Base/MessageResult.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
-using Newtonsoft.Json;
+using System.Text.Json;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
@@ -126,7 +126,7 @@ public class MessageResult : ResultBase
T cd = null;
try
{
- cd = JsonConvert.DeserializeObject(RawData);
+ cd = JsonSerializer.Deserialize(RawData);
return cd;
}
diff --git a/TelegramBotBase/Base/ThreadPoolMessageClient.cs b/TelegramBotBase/Base/ThreadPoolMessageClient.cs
index 41fb131..7647786 100644
--- a/TelegramBotBase/Base/ThreadPoolMessageClient.cs
+++ b/TelegramBotBase/Base/ThreadPoolMessageClient.cs
@@ -72,7 +72,7 @@ public class ThreadPoolMessageClient : MessageClient
var receiverOptions = new ReceiverOptions();
- receiverOptions.ThrowPendingUpdates = ThrowPendingUpdates;
+ receiverOptions.DropPendingUpdates = ThrowPendingUpdates;
ThreadPool.SetMaxThreads(ThreadPool_WorkerThreads, ThreadPool_IOThreads);
diff --git a/TelegramBotBase/Form/CallbackData.cs b/TelegramBotBase/Form/CallbackData.cs
index 13b701a..9224465 100644
--- a/TelegramBotBase/Form/CallbackData.cs
+++ b/TelegramBotBase/Form/CallbackData.cs
@@ -1,5 +1,6 @@
-using Newtonsoft.Json;
-using System.Text;
+using System.Text;
+using System.Text.Json;
+using System.Text.Json.Serialization;
using TelegramBotBase.Exceptions;
namespace TelegramBotBase.Form;
@@ -19,9 +20,9 @@ public class CallbackData
Value = value;
}
- [JsonProperty("m")] public string Method { get; set; }
+ [JsonPropertyName("m")] public string Method { get; set; }
- [JsonProperty("v")] public string Value { get; set; }
+ [JsonPropertyName("v")] public string Value { get; set; }
public static string Create(string method, string value)
{
@@ -36,7 +37,7 @@ public class CallbackData
{
var s = string.Empty;
- s = JsonConvert.SerializeObject(this);
+ s = JsonSerializer.Serialize(this);
//Is data over 64 bytes ?
int byte_count = Encoding.UTF8.GetByteCount(s);
@@ -55,7 +56,7 @@ public class CallbackData
///
public static CallbackData Deserialize(string data)
{
- return JsonConvert.DeserializeObject(data);
+ return JsonSerializer.Deserialize(data);
}
public static implicit operator string(CallbackData callbackData) => callbackData.Serialize(true);
diff --git a/TelegramBotBase/Form/GroupForm.cs b/TelegramBotBase/Form/GroupForm.cs
index 14002f9..d1c879c 100644
--- a/TelegramBotBase/Form/GroupForm.cs
+++ b/TelegramBotBase/Form/GroupForm.cs
@@ -11,28 +11,28 @@ public class GroupForm : FormBase
{
switch (message.MessageType)
{
- case MessageType.ChatMembersAdded:
+ case MessageType.NewChatMembers:
- await OnMemberChanges(new MemberChangeEventArgs(MessageType.ChatMembersAdded, message,
+ await OnMemberChanges(new MemberChangeEventArgs(MessageType.NewChatMembers, message,
message.Message.NewChatMembers));
break;
- case MessageType.ChatMemberLeft:
+ case MessageType.LeftChatMember:
- await OnMemberChanges(new MemberChangeEventArgs(MessageType.ChatMemberLeft, message,
+ await OnMemberChanges(new MemberChangeEventArgs(MessageType.LeftChatMember, message,
message.Message.LeftChatMember));
break;
- case MessageType.ChatPhotoChanged:
- case MessageType.ChatPhotoDeleted:
- case MessageType.ChatTitleChanged:
- case MessageType.MigratedFromGroup:
- case MessageType.MigratedToSupergroup:
- case MessageType.MessagePinned:
- case MessageType.GroupCreated:
- case MessageType.SupergroupCreated:
- case MessageType.ChannelCreated:
+ case MessageType.NewChatPhoto:
+ case MessageType.DeleteChatPhoto:
+ case MessageType.NewChatTitle:
+ case MessageType.MigrateFromChatId:
+ case MessageType.MigrateToChatId:
+ case MessageType.PinnedMessage:
+ case MessageType.GroupChatCreated:
+ case MessageType.SupergroupChatCreated:
+ case MessageType.ChannelChatCreated:
await OnGroupChanged(new GroupChangedEventArgs(message.MessageType, message));
diff --git a/TelegramBotBase/Form/PromptDialog.cs b/TelegramBotBase/Form/PromptDialog.cs
index a2d4c56..1d2d5f4 100644
--- a/TelegramBotBase/Form/PromptDialog.cs
+++ b/TelegramBotBase/Form/PromptDialog.cs
@@ -82,7 +82,7 @@ public class PromptDialog : ModalDialog
{
var bf = new ButtonForm();
bf.AddButtonRow(new ButtonBase(BackLabel, "back"));
- await Device.Send(Message, (ReplyMarkupBase)bf);
+ await Device.Send(Message, (IReplyMarkup)bf);
return;
}
diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs
index f2b49d2..423de31 100644
--- a/TelegramBotBase/Sessions/DeviceSession.cs
+++ b/TelegramBotBase/Sessions/DeviceSession.cs
@@ -239,8 +239,7 @@ public class DeviceSession : IDeviceSession
text = text.MarkdownV2Escape();
}
-
- var t = Api(a => a.SendTextMessageAsync(deviceId, text, null, parseMode, replyToMessageId: replyTo,
+ var t = Api(a => a.SendMessage(deviceId, text, messageThreadId: null, parseMode: parseMode, replyParameters: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
var o = GetOrigin(new StackTrace());
@@ -294,7 +293,7 @@ public class DeviceSession : IDeviceSession
}
- var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
+ var t = Api(a => a.SendMessage(DeviceId, text, messageThreadId: null, parseMode: parseMode, replyParameters: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
var o = GetOrigin(new StackTrace());
@@ -312,7 +311,7 @@ public class DeviceSession : IDeviceSession
///
///
///
- public async Task Send(string text, ReplyMarkupBase markup, int replyTo = 0,
+ public async Task Send(string text, IReplyMarkup markup, int replyTo = 0,
bool disableNotification = false, ParseMode parseMode = ParseMode.Markdown,
bool markdownV2AutoEscape = true)
{
@@ -332,7 +331,7 @@ public class DeviceSession : IDeviceSession
}
- var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
+ var t = Api(a => a.SendMessage(DeviceId, text, messageThreadId: null, parseMode: parseMode, replyParameters: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
var o = GetOrigin(new StackTrace());
@@ -362,7 +361,7 @@ public class DeviceSession : IDeviceSession
InlineKeyboardMarkup markup = buttons;
- var t = Api(a => a.SendPhotoAsync(DeviceId, file, null, caption, parseMode, replyToMessageId: replyTo,
+ var t = Api(a => a.SendPhoto(DeviceId, file, messageThreadId: null, caption: caption, parseMode: parseMode, replyParameters: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
var o = GetOrigin(new StackTrace());
@@ -392,8 +391,8 @@ public class DeviceSession : IDeviceSession
InlineKeyboardMarkup markup = buttons;
- var t = Api(a => a.SendVideoAsync(DeviceId, file, caption: caption, parseMode: parseMode,
- replyToMessageId: replyTo, replyMarkup: markup,
+ var t = Api(a => a.SendVideo(DeviceId, file, caption: caption, parseMode: parseMode,
+ replyParameters: replyTo, replyMarkup: markup,
disableNotification: disableNotification));
var o = GetOrigin(new StackTrace());
@@ -422,8 +421,8 @@ public class DeviceSession : IDeviceSession
InlineKeyboardMarkup markup = buttons;
- var t = Api(a => a.SendVideoAsync(DeviceId, InputFile.FromUri(url), parseMode: parseMode,
- replyToMessageId: replyTo, replyMarkup: markup,
+ var t = Api(a => a.SendVideo(DeviceId, InputFile.FromUri(url), parseMode: parseMode,
+ replyParameters: replyTo, replyMarkup: markup,
disableNotification: disableNotification));
var o = GetOrigin(new StackTrace());
@@ -457,7 +456,7 @@ public class DeviceSession : IDeviceSession
var fts = InputFile.FromStream(ms, filename);
- var t = Api(a => a.SendVideoAsync(DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo,
+ var t = Api(a => a.SendVideo(DeviceId, fts, parseMode: parseMode, replyParameters: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
var o = GetOrigin(new StackTrace());
@@ -494,7 +493,7 @@ public class DeviceSession : IDeviceSession
var fts = InputFile.FromStream(fs, filename);
- var t = Api(a => a.SendVideoAsync(DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo,
+ var t = Api(a => a.SendVideo(DeviceId, fts, parseMode: parseMode, replyParameters: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
var o = GetOrigin(new StackTrace());
@@ -573,8 +572,8 @@ public class DeviceSession : IDeviceSession
}
- var t = Api(a => a.SendDocumentAsync(DeviceId, document, null, null, caption, replyMarkup: markup,
- disableNotification: disableNotification, replyToMessageId: replyTo));
+ var t = Api(a => a.SendDocument(DeviceId, document, messageThreadId: null, thumbnail: null, caption: caption, replyMarkup: markup,
+ disableNotification: disableNotification, replyParameters: replyTo));
var o = GetOrigin(new StackTrace());
await OnMessageSent(new MessageSentEventArgs(await t, o));
@@ -772,11 +771,11 @@ public class DeviceSession : IDeviceSession
#region "Users"
- public virtual async Task RestrictUser(long userId, ChatPermissions permissions, bool? useIndependentGroupPermission = null, DateTime until = default)
+ public virtual async Task RestrictUser(long userId, ChatPermissions permissions, bool useIndependentGroupPermission = false, DateTime until = default)
{
try
{
- await Api(a => a.RestrictChatMemberAsync(DeviceId, userId, permissions, useIndependentGroupPermission, until));
+ await Api(a => a.RestrictChatMember(DeviceId, userId, permissions, useIndependentChatPermissions: useIndependentGroupPermission, untilDate: until));
}
catch
{
diff --git a/TelegramBotBase/States/JSONStateMachine.cs b/TelegramBotBase/States/JSONStateMachine.cs
index 5c764a6..781453c 100644
--- a/TelegramBotBase/States/JSONStateMachine.cs
+++ b/TelegramBotBase/States/JSONStateMachine.cs
@@ -1,6 +1,6 @@
using System;
using System.IO;
-using Newtonsoft.Json;
+using System.Text.Json;
using TelegramBotBase.Args;
using TelegramBotBase.Base;
using TelegramBotBase.Form;
@@ -48,11 +48,7 @@ public class JsonStateMachine : IStateMachine
{
var content = File.ReadAllText(FilePath);
- var sc = JsonConvert.DeserializeObject(content, new JsonSerializerSettings
- {
- TypeNameHandling = TypeNameHandling.All,
- TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
- });
+ var sc = JsonSerializer.Deserialize(content);
return sc;
}
@@ -77,10 +73,9 @@ public class JsonStateMachine : IStateMachine
try
{
- var content = JsonConvert.SerializeObject(e.States, Formatting.Indented, new JsonSerializerSettings
+ var content = JsonSerializer.Serialize(e.States, new JsonSerializerOptions
{
- TypeNameHandling = TypeNameHandling.All,
- TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
+ WriteIndented = true,
});
File.WriteAllText(FilePath, content);
diff --git a/TelegramBotBase/States/SimpleJSONStateMachine.cs b/TelegramBotBase/States/SimpleJSONStateMachine.cs
index e722305..243cfc9 100644
--- a/TelegramBotBase/States/SimpleJSONStateMachine.cs
+++ b/TelegramBotBase/States/SimpleJSONStateMachine.cs
@@ -1,6 +1,6 @@
using System;
using System.IO;
-using Newtonsoft.Json;
+using System.Text.Json;
using TelegramBotBase.Args;
using TelegramBotBase.Base;
using TelegramBotBase.Form;
@@ -49,7 +49,7 @@ public class SimpleJsonStateMachine : IStateMachine
{
var content = File.ReadAllText(FilePath);
- var sc = JsonConvert.DeserializeObject(content);
+ var sc = JsonSerializer.Deserialize(content);
return sc;
}
@@ -74,7 +74,9 @@ public class SimpleJsonStateMachine : IStateMachine
try
{
- var content = JsonConvert.SerializeObject(e.States, Formatting.Indented);
+ var content = JsonSerializer.Serialize(e.States, new JsonSerializerOptions() {
+ WriteIndented = true
+ });
File.WriteAllText(FilePath, content);
}
diff --git a/TelegramBotBase/TelegramBotBase.csproj b/TelegramBotBase/TelegramBotBase.csproj
index 0967e33..9f2a71e 100644
--- a/TelegramBotBase/TelegramBotBase.csproj
+++ b/TelegramBotBase/TelegramBotBase.csproj
@@ -22,7 +22,7 @@
-
+
@@ -57,7 +57,7 @@
-
+
diff --git a/TelegramBotBase/TelegramBotBase.nuspec b/TelegramBotBase/TelegramBotBase.nuspec
index ec58bce..dda3bc7 100644
--- a/TelegramBotBase/TelegramBotBase.nuspec
+++ b/TelegramBotBase/TelegramBotBase.nuspec
@@ -14,12 +14,12 @@
-
+
-
+
-
+
\ No newline at end of file
diff --git a/TelegramBotFramework.sln b/TelegramBotFramework.sln
index 409d950..35fc27c 100644
--- a/TelegramBotFramework.sln
+++ b/TelegramBotFramework.sln
@@ -38,6 +38,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TelegramBotBase.Extensions.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TelegramBotBase.Extensions.Images.IronSoftware", "TelegramBotBase.Extensions.Images.IronSoftware\TelegramBotBase.Extensions.Images.IronSoftware.csproj", "{DC521A4C-7446-46F7-845B-AAF10EDCF8C6}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Элементы решения", "Элементы решения", "{040F54FA-B51F-475F-89F8-2DD23CDC2989}"
+ ProjectSection(SolutionItems) = preProject
+ .gitea\workflows\TelegramBotFramework.nuget.yaml = .gitea\workflows\TelegramBotFramework.nuget.yaml
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU