Compare commits
No commits in common. "master" and "v6.5.1" have entirely different histories.
@ -1,48 +0,0 @@
|
|||||||
name: build nuget workflow for TelegramBotBase project
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
Build-TelegramBotBase:
|
|
||||||
env:
|
|
||||||
APP_PROJECT_NAME: TelegramBotBase
|
|
||||||
PACKAGE_VERSION: "123.1.6"
|
|
||||||
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 /p:Version=$PACKAGE_VERSION
|
|
||||||
|
|
||||||
- name: Build app
|
|
||||||
run: dotnet build -c Release --version-suffix $PACKAGE_VERSION --no-restore $APP_PROJECT_NAME /p:Version=$PACKAGE_VERSION
|
|
||||||
|
|
||||||
- name: Pack app
|
|
||||||
run: dotnet pack --no-build $APP_PROJECT_NAME /p:Version=$PACKAGE_VERSION
|
|
||||||
|
|
||||||
- name: disconnect old source
|
|
||||||
run: dotnet nuget remove source gitea
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Connect source
|
|
||||||
run: dotnet nuget add source --name gitea https://git.kosyakmakc.ru/api/packages/kosyakmakc/nuget/index.json
|
|
||||||
|
|
||||||
- name: Upload nuget package
|
|
||||||
run: dotnet nuget push --source gitea --api-key ${{ secrets.kosyakmakc_nuget_publish }} ${{ gitea.workspace }}/${{ env.APP_PROJECT_NAME }}/bin/Release/$APP_PROJECT_NAME.$PACKAGE_VERSION.nupkg
|
|
||||||
@ -55,7 +55,7 @@ public class DataResult : ResultBase
|
|||||||
{
|
{
|
||||||
var encryptedContent = new MemoryStream();
|
var encryptedContent = new MemoryStream();
|
||||||
encryptedContent.SetLength(Document.FileSize.Value);
|
encryptedContent.SetLength(Document.FileSize.Value);
|
||||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFile(Document.FileId,
|
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId,
|
||||||
encryptedContent);
|
encryptedContent);
|
||||||
|
|
||||||
return InputFile.FromStream(encryptedContent, Document.FileName);
|
return InputFile.FromStream(encryptedContent, Document.FileName);
|
||||||
@ -69,9 +69,9 @@ public class DataResult : ResultBase
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task DownloadDocument(string path)
|
public async Task DownloadDocument(string path)
|
||||||
{
|
{
|
||||||
var file = await Device.Client.TelegramClient.GetFile(Document.FileId);
|
var file = await Device.Client.TelegramClient.GetFileAsync(Document.FileId);
|
||||||
var fs = new FileStream(path, FileMode.Create);
|
var fs = new FileStream(path, FileMode.Create);
|
||||||
await Device.Client.TelegramClient.DownloadFile(file.FilePath, fs);
|
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ public class DataResult : ResultBase
|
|||||||
public async Task<byte[]> DownloadRawDocument()
|
public async Task<byte[]> DownloadRawDocument()
|
||||||
{
|
{
|
||||||
var ms = new MemoryStream();
|
var ms = new MemoryStream();
|
||||||
await Device.Client.TelegramClient.GetInfoAndDownloadFile(Document.FileId, ms);
|
await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId, ms);
|
||||||
return ms.ToArray();
|
return ms.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ public class DataResult : ResultBase
|
|||||||
public async Task<string> DownloadRawTextDocument(Encoding encoding)
|
public async Task<string> DownloadRawTextDocument(Encoding encoding)
|
||||||
{
|
{
|
||||||
var ms = new MemoryStream();
|
var ms = new MemoryStream();
|
||||||
await Device.Client.TelegramClient.GetInfoAndDownloadFile(Document.FileId, ms);
|
await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId, ms);
|
||||||
|
|
||||||
ms.Position = 0;
|
ms.Position = 0;
|
||||||
|
|
||||||
@ -116,16 +116,16 @@ public class DataResult : ResultBase
|
|||||||
{
|
{
|
||||||
var encryptedContent = new MemoryStream();
|
var encryptedContent = new MemoryStream();
|
||||||
encryptedContent.SetLength(Video.FileSize.Value);
|
encryptedContent.SetLength(Video.FileSize.Value);
|
||||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFile(Video.FileId, encryptedContent);
|
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Video.FileId, encryptedContent);
|
||||||
|
|
||||||
return InputFile.FromStream(encryptedContent, "");
|
return InputFile.FromStream(encryptedContent, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DownloadVideo(string path)
|
public async Task DownloadVideo(string path)
|
||||||
{
|
{
|
||||||
var file = await Device.Client.TelegramClient.GetFile(Video.FileId);
|
var file = await Device.Client.TelegramClient.GetFileAsync(Video.FileId);
|
||||||
var fs = new FileStream(path, FileMode.Create);
|
var fs = new FileStream(path, FileMode.Create);
|
||||||
await Device.Client.TelegramClient.DownloadFile(file.FilePath, fs);
|
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
}
|
}
|
||||||
@ -134,16 +134,16 @@ public class DataResult : ResultBase
|
|||||||
{
|
{
|
||||||
var encryptedContent = new MemoryStream();
|
var encryptedContent = new MemoryStream();
|
||||||
encryptedContent.SetLength(Audio.FileSize.Value);
|
encryptedContent.SetLength(Audio.FileSize.Value);
|
||||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFile(Audio.FileId, encryptedContent);
|
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Audio.FileId, encryptedContent);
|
||||||
|
|
||||||
return InputFile.FromStream(encryptedContent, "");
|
return InputFile.FromStream(encryptedContent, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DownloadAudio(string path)
|
public async Task DownloadAudio(string path)
|
||||||
{
|
{
|
||||||
var file = await Device.Client.TelegramClient.GetFile(Audio.FileId);
|
var file = await Device.Client.TelegramClient.GetFileAsync(Audio.FileId);
|
||||||
var fs = new FileStream(path, FileMode.Create);
|
var fs = new FileStream(path, FileMode.Create);
|
||||||
await Device.Client.TelegramClient.DownloadFile(file.FilePath, fs);
|
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
}
|
}
|
||||||
@ -153,7 +153,7 @@ public class DataResult : ResultBase
|
|||||||
var photo = Photos[index];
|
var photo = Photos[index];
|
||||||
var encryptedContent = new MemoryStream();
|
var encryptedContent = new MemoryStream();
|
||||||
encryptedContent.SetLength(photo.FileSize.Value);
|
encryptedContent.SetLength(photo.FileSize.Value);
|
||||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFile(photo.FileId, encryptedContent);
|
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(photo.FileId, encryptedContent);
|
||||||
|
|
||||||
return InputFile.FromStream(encryptedContent, "");
|
return InputFile.FromStream(encryptedContent, "");
|
||||||
}
|
}
|
||||||
@ -161,9 +161,9 @@ public class DataResult : ResultBase
|
|||||||
public async Task DownloadPhoto(int index, string path)
|
public async Task DownloadPhoto(int index, string path)
|
||||||
{
|
{
|
||||||
var photo = Photos[index];
|
var photo = Photos[index];
|
||||||
var file = await Device.Client.TelegramClient.GetFile(photo.FileId);
|
var file = await Device.Client.TelegramClient.GetFileAsync(photo.FileId);
|
||||||
var fs = new FileStream(path, FileMode.Create);
|
var fs = new FileStream(path, FileMode.Create);
|
||||||
await Device.Client.TelegramClient.DownloadFile(file.FilePath, fs);
|
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -446,8 +446,8 @@ public class FormBase : IDisposable
|
|||||||
{
|
{
|
||||||
c.Cleanup().Wait();
|
c.Cleanup().Wait();
|
||||||
|
|
||||||
|
Controls.Remove(c);
|
||||||
}
|
}
|
||||||
Controls.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -103,7 +103,7 @@ public class MessageClient
|
|||||||
|
|
||||||
var receiverOptions = new ReceiverOptions();
|
var receiverOptions = new ReceiverOptions();
|
||||||
|
|
||||||
receiverOptions.DropPendingUpdates = ThrowPendingUpdates;
|
receiverOptions.ThrowPendingUpdates = ThrowPendingUpdates;
|
||||||
|
|
||||||
TelegramClient.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions, _cancellationTokenSource.Token);
|
TelegramClient.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions, _cancellationTokenSource.Token);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Text.Json;
|
using Newtonsoft.Json;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ public class MessageResult : ResultBase
|
|||||||
T cd = null;
|
T cd = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cd = JsonSerializer.Deserialize<T>(RawData);
|
cd = JsonConvert.DeserializeObject<T>(RawData);
|
||||||
|
|
||||||
return cd;
|
return cd;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,7 +72,7 @@ public class ThreadPoolMessageClient : MessageClient
|
|||||||
|
|
||||||
var receiverOptions = new ReceiverOptions();
|
var receiverOptions = new ReceiverOptions();
|
||||||
|
|
||||||
receiverOptions.DropPendingUpdates = ThrowPendingUpdates;
|
receiverOptions.ThrowPendingUpdates = ThrowPendingUpdates;
|
||||||
|
|
||||||
ThreadPool.SetMaxThreads(ThreadPool_WorkerThreads, ThreadPool_IOThreads);
|
ThreadPool.SetMaxThreads(ThreadPool_WorkerThreads, ThreadPool_IOThreads);
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@ namespace TelegramBotBase.Controls.Inline;
|
|||||||
[DebuggerDisplay("{Text}")]
|
[DebuggerDisplay("{Text}")]
|
||||||
public class Label : ControlBase
|
public class Label : ControlBase
|
||||||
{
|
{
|
||||||
protected bool _renderNecessary = true;
|
private bool _renderNecessary = true;
|
||||||
|
|
||||||
private string _text = Default.Language["Label_Text"];
|
private string _text = Default.Language["Label_Text"];
|
||||||
|
|
||||||
|
|||||||
@ -23,15 +23,13 @@ public class ServiceProviderStartFormFactory : IStartFormFactory
|
|||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FormBase CreateForm() => CreateForm(null);
|
public FormBase CreateForm()
|
||||||
|
|
||||||
public FormBase CreateForm(Type? specifiedStartFrom = null)
|
|
||||||
{
|
{
|
||||||
FormBase fb = null;
|
FormBase fb = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
fb = (FormBase)ActivatorUtilities.CreateInstance(_serviceProvider, specifiedStartFrom ?? _startFormClass);
|
fb = (FormBase)ActivatorUtilities.CreateInstance(_serviceProvider, _startFormClass);
|
||||||
}
|
}
|
||||||
catch(InvalidOperationException ex)
|
catch(InvalidOperationException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -24,7 +24,7 @@ public class AutoCleanForm : FormBase
|
|||||||
DeleteMode = EDeleteMode.OnEveryCall;
|
DeleteMode = EDeleteMode.OnEveryCall;
|
||||||
DeleteSide = EDeleteSide.BotOnly;
|
DeleteSide = EDeleteSide.BotOnly;
|
||||||
|
|
||||||
Opened += AutoCleanForm_Init;
|
Init += AutoCleanForm_Init;
|
||||||
|
|
||||||
Closed += AutoCleanForm_Closed;
|
Closed += AutoCleanForm_Closed;
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ public class AutoCleanForm : FormBase
|
|||||||
|
|
||||||
[SaveState] public EDeleteSide DeleteSide { get; set; }
|
[SaveState] public EDeleteSide DeleteSide { get; set; }
|
||||||
|
|
||||||
private Task AutoCleanForm_Init(object sender, EventArgs e)
|
private Task AutoCleanForm_Init(object sender, InitEventArgs e)
|
||||||
{
|
{
|
||||||
if (Device == null)
|
if (Device == null)
|
||||||
{
|
{
|
||||||
@ -70,8 +70,7 @@ public class AutoCleanForm : FormBase
|
|||||||
|
|
||||||
private Task Device_MessageSent(object sender, MessageSentEventArgs e)
|
private Task Device_MessageSent(object sender, MessageSentEventArgs e)
|
||||||
{
|
{
|
||||||
if (DeleteSide == EDeleteSide.UserOnly
|
if (DeleteSide == EDeleteSide.UserOnly)
|
||||||
|| Device.ActiveForm != this)
|
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
@ -138,12 +137,6 @@ public class AutoCleanForm : FormBase
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
Device.MessageSent -= Device_MessageSent;
|
|
||||||
|
|
||||||
Device.MessageReceived -= Device_MessageReceived;
|
|
||||||
|
|
||||||
Device.MessageDeleted -= Device_MessageDeleted;
|
|
||||||
|
|
||||||
MessageCleanup().Wait();
|
MessageCleanup().Wait();
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using System.Text;
|
using Newtonsoft.Json;
|
||||||
using System.Text.Json;
|
using System.Text;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
using TelegramBotBase.Exceptions;
|
using TelegramBotBase.Exceptions;
|
||||||
|
|
||||||
namespace TelegramBotBase.Form;
|
namespace TelegramBotBase.Form;
|
||||||
@ -20,9 +19,9 @@ public class CallbackData
|
|||||||
Value = value;
|
Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonPropertyName("m")] public string Method { get; set; }
|
[JsonProperty("m")] public string Method { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("v")] public string Value { get; set; }
|
[JsonProperty("v")] public string Value { get; set; }
|
||||||
|
|
||||||
public static string Create(string method, string value)
|
public static string Create(string method, string value)
|
||||||
{
|
{
|
||||||
@ -37,7 +36,7 @@ public class CallbackData
|
|||||||
{
|
{
|
||||||
var s = string.Empty;
|
var s = string.Empty;
|
||||||
|
|
||||||
s = JsonSerializer.Serialize(this);
|
s = JsonConvert.SerializeObject(this);
|
||||||
|
|
||||||
//Is data over 64 bytes ?
|
//Is data over 64 bytes ?
|
||||||
int byte_count = Encoding.UTF8.GetByteCount(s);
|
int byte_count = Encoding.UTF8.GetByteCount(s);
|
||||||
@ -56,7 +55,7 @@ public class CallbackData
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static CallbackData Deserialize(string data)
|
public static CallbackData Deserialize(string data)
|
||||||
{
|
{
|
||||||
return JsonSerializer.Deserialize<CallbackData>(data);
|
return JsonConvert.DeserializeObject<CallbackData>(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static implicit operator string(CallbackData callbackData) => callbackData.Serialize(true);
|
public static implicit operator string(CallbackData callbackData) => callbackData.Serialize(true);
|
||||||
|
|||||||
@ -11,28 +11,28 @@ public class GroupForm : FormBase
|
|||||||
{
|
{
|
||||||
switch (message.MessageType)
|
switch (message.MessageType)
|
||||||
{
|
{
|
||||||
case MessageType.NewChatMembers:
|
case MessageType.ChatMembersAdded:
|
||||||
|
|
||||||
await OnMemberChanges(new MemberChangeEventArgs(MessageType.NewChatMembers, message,
|
await OnMemberChanges(new MemberChangeEventArgs(MessageType.ChatMembersAdded, message,
|
||||||
message.Message.NewChatMembers));
|
message.Message.NewChatMembers));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case MessageType.LeftChatMember:
|
case MessageType.ChatMemberLeft:
|
||||||
|
|
||||||
await OnMemberChanges(new MemberChangeEventArgs(MessageType.LeftChatMember, message,
|
await OnMemberChanges(new MemberChangeEventArgs(MessageType.ChatMemberLeft, message,
|
||||||
message.Message.LeftChatMember));
|
message.Message.LeftChatMember));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MessageType.NewChatPhoto:
|
case MessageType.ChatPhotoChanged:
|
||||||
case MessageType.DeleteChatPhoto:
|
case MessageType.ChatPhotoDeleted:
|
||||||
case MessageType.NewChatTitle:
|
case MessageType.ChatTitleChanged:
|
||||||
case MessageType.MigrateFromChatId:
|
case MessageType.MigratedFromGroup:
|
||||||
case MessageType.MigrateToChatId:
|
case MessageType.MigratedToSupergroup:
|
||||||
case MessageType.PinnedMessage:
|
case MessageType.MessagePinned:
|
||||||
case MessageType.GroupChatCreated:
|
case MessageType.GroupCreated:
|
||||||
case MessageType.SupergroupChatCreated:
|
case MessageType.SupergroupCreated:
|
||||||
case MessageType.ChannelChatCreated:
|
case MessageType.ChannelCreated:
|
||||||
|
|
||||||
await OnGroupChanged(new GroupChangedEventArgs(message.MessageType, message));
|
await OnGroupChanged(new GroupChangedEventArgs(message.MessageType, message));
|
||||||
|
|
||||||
|
|||||||
@ -82,7 +82,7 @@ public class PromptDialog : ModalDialog
|
|||||||
{
|
{
|
||||||
var bf = new ButtonForm();
|
var bf = new ButtonForm();
|
||||||
bf.AddButtonRow(new ButtonBase(BackLabel, "back"));
|
bf.AddButtonRow(new ButtonBase(BackLabel, "back"));
|
||||||
await Device.Send(Message, (IReplyMarkup)bf);
|
await Device.Send(Message, (ReplyMarkupBase)bf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,8 +46,6 @@ public class FormBaseMessageLoop : IMessageLoopFactory
|
|||||||
mr.Device = session;
|
mr.Device = session;
|
||||||
ur.Device = session;
|
ur.Device = session;
|
||||||
|
|
||||||
session.OnMessageReceived(new(mr.Message));
|
|
||||||
|
|
||||||
var activeForm = session.ActiveForm;
|
var activeForm = session.ActiveForm;
|
||||||
|
|
||||||
//Pre Loading Event
|
//Pre Loading Event
|
||||||
|
|||||||
@ -6,7 +6,6 @@ using System.Threading.Tasks;
|
|||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Attributes;
|
using TelegramBotBase.Attributes;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Factories;
|
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
using TelegramBotBase.Interfaces;
|
using TelegramBotBase.Interfaces;
|
||||||
using TelegramBotBase.Sessions;
|
using TelegramBotBase.Sessions;
|
||||||
@ -146,17 +145,9 @@ public class SessionManager
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
FormBase form;
|
|
||||||
if (BotBase.StartFormFactory is ServiceProviderStartFormFactory diFactory)
|
|
||||||
{
|
|
||||||
form = diFactory.CreateForm(t);
|
|
||||||
}
|
|
||||||
//No default constructor, fallback
|
//No default constructor, fallback
|
||||||
else if (t.GetConstructor(new Type[] { })?.Invoke(new object[] { }) is FormBase f)
|
if (!(t.GetConstructor(new Type[] { })?.Invoke(new object[] { }) is FormBase form))
|
||||||
{
|
|
||||||
form = f;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (!statemachine.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
if (!statemachine.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||||
{
|
{
|
||||||
@ -302,19 +293,17 @@ public class SessionManager
|
|||||||
|
|
||||||
se.Values = ssea.Values;
|
se.Values = ssea.Values;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
//Search for public properties with SaveState attribute
|
||||||
|
var fields = form.GetType()
|
||||||
|
.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
|
||||||
|
.Where(a => a.GetCustomAttributes(typeof(SaveState), true).Length != 0).ToList();
|
||||||
|
|
||||||
|
foreach (var f in fields)
|
||||||
{
|
{
|
||||||
//Search for public properties with SaveState attribute
|
var val = f.GetValue(form);
|
||||||
var fields = form.GetType()
|
|
||||||
.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
|
|
||||||
.Where(a => a.GetCustomAttributes(typeof(SaveState), true).Length != 0).ToList();
|
|
||||||
|
|
||||||
foreach (var f in fields)
|
se.Values.Add("$" + f.Name, val);
|
||||||
{
|
|
||||||
var val = f.GetValue(form);
|
|
||||||
|
|
||||||
se.Values.Add("$" + f.Name, val);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
states.Add(se);
|
states.Add(se);
|
||||||
|
|||||||
@ -239,7 +239,8 @@ public class DeviceSession : IDeviceSession
|
|||||||
text = text.MarkdownV2Escape();
|
text = text.MarkdownV2Escape();
|
||||||
}
|
}
|
||||||
|
|
||||||
var t = Api(a => a.SendMessage(deviceId, text, messageThreadId: null, parseMode: parseMode, replyParameters: replyTo,
|
|
||||||
|
var t = Api(a => a.SendTextMessageAsync(deviceId, text, null, parseMode, replyToMessageId: replyTo,
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
@ -293,7 +294,7 @@ public class DeviceSession : IDeviceSession
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var t = Api(a => a.SendMessage(DeviceId, text, messageThreadId: null, parseMode: parseMode, replyParameters: replyTo,
|
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
@ -311,7 +312,7 @@ public class DeviceSession : IDeviceSession
|
|||||||
/// <param name="replyTo"></param>
|
/// <param name="replyTo"></param>
|
||||||
/// <param name="disableNotification"></param>
|
/// <param name="disableNotification"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<Message> Send(string text, IReplyMarkup markup, int replyTo = 0,
|
public async Task<Message> Send(string text, ReplyMarkupBase markup, int replyTo = 0,
|
||||||
bool disableNotification = false, ParseMode parseMode = ParseMode.Markdown,
|
bool disableNotification = false, ParseMode parseMode = ParseMode.Markdown,
|
||||||
bool markdownV2AutoEscape = true)
|
bool markdownV2AutoEscape = true)
|
||||||
{
|
{
|
||||||
@ -331,7 +332,7 @@ public class DeviceSession : IDeviceSession
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var t = Api(a => a.SendMessage(DeviceId, text, messageThreadId: null, parseMode: parseMode, replyParameters: replyTo,
|
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
@ -361,7 +362,7 @@ public class DeviceSession : IDeviceSession
|
|||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
|
|
||||||
var t = Api(a => a.SendPhoto(DeviceId, file, messageThreadId: null, caption: caption, parseMode: parseMode, replyParameters: replyTo,
|
var t = Api(a => a.SendPhotoAsync(DeviceId, file, null, caption, parseMode, replyToMessageId: replyTo,
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
@ -391,8 +392,8 @@ public class DeviceSession : IDeviceSession
|
|||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
|
|
||||||
var t = Api(a => a.SendVideo(DeviceId, file, caption: caption, parseMode: parseMode,
|
var t = Api(a => a.SendVideoAsync(DeviceId, file, caption: caption, parseMode: parseMode,
|
||||||
replyParameters: replyTo, replyMarkup: markup,
|
replyToMessageId: replyTo, replyMarkup: markup,
|
||||||
disableNotification: disableNotification));
|
disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
@ -421,8 +422,8 @@ public class DeviceSession : IDeviceSession
|
|||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
|
|
||||||
var t = Api(a => a.SendVideo(DeviceId, InputFile.FromUri(url), parseMode: parseMode,
|
var t = Api(a => a.SendVideoAsync(DeviceId, InputFile.FromUri(url), parseMode: parseMode,
|
||||||
replyParameters: replyTo, replyMarkup: markup,
|
replyToMessageId: replyTo, replyMarkup: markup,
|
||||||
disableNotification: disableNotification));
|
disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
@ -456,7 +457,7 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
var fts = InputFile.FromStream(ms, filename);
|
var fts = InputFile.FromStream(ms, filename);
|
||||||
|
|
||||||
var t = Api(a => a.SendVideo(DeviceId, fts, parseMode: parseMode, replyParameters: replyTo,
|
var t = Api(a => a.SendVideoAsync(DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo,
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
@ -493,7 +494,7 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
var fts = InputFile.FromStream(fs, filename);
|
var fts = InputFile.FromStream(fs, filename);
|
||||||
|
|
||||||
var t = Api(a => a.SendVideo(DeviceId, fts, parseMode: parseMode, replyParameters: replyTo,
|
var t = Api(a => a.SendVideoAsync(DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo,
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
@ -572,8 +573,8 @@ public class DeviceSession : IDeviceSession
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var t = Api(a => a.SendDocument(DeviceId, document, messageThreadId: null, thumbnail: null, caption: caption, replyMarkup: markup,
|
var t = Api(a => a.SendDocumentAsync(DeviceId, document, null, null, caption, replyMarkup: markup,
|
||||||
disableNotification: disableNotification, replyParameters: replyTo));
|
disableNotification: disableNotification, replyToMessageId: replyTo));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
@ -771,11 +772,11 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
#region "Users"
|
#region "Users"
|
||||||
|
|
||||||
public virtual async Task RestrictUser(long userId, ChatPermissions permissions, bool useIndependentGroupPermission = false, DateTime until = default)
|
public virtual async Task RestrictUser(long userId, ChatPermissions permissions, bool? useIndependentGroupPermission = null, DateTime until = default)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Api(a => a.RestrictChatMember(DeviceId, userId, permissions, useIndependentChatPermissions: useIndependentGroupPermission, untilDate: until));
|
await Api(a => a.RestrictChatMemberAsync(DeviceId, userId, permissions, useIndependentGroupPermission, until));
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text.Json;
|
using Newtonsoft.Json;
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
@ -48,7 +48,11 @@ public class JsonStateMachine : IStateMachine
|
|||||||
{
|
{
|
||||||
var content = File.ReadAllText(FilePath);
|
var content = File.ReadAllText(FilePath);
|
||||||
|
|
||||||
var sc = JsonSerializer.Deserialize<StateContainer>(content);
|
var sc = JsonConvert.DeserializeObject<StateContainer>(content, new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
TypeNameHandling = TypeNameHandling.All,
|
||||||
|
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
|
||||||
|
});
|
||||||
|
|
||||||
return sc;
|
return sc;
|
||||||
}
|
}
|
||||||
@ -73,9 +77,10 @@ public class JsonStateMachine : IStateMachine
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var content = JsonSerializer.Serialize(e.States, new JsonSerializerOptions
|
var content = JsonConvert.SerializeObject(e.States, Formatting.Indented, new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
WriteIndented = true,
|
TypeNameHandling = TypeNameHandling.All,
|
||||||
|
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
|
||||||
});
|
});
|
||||||
|
|
||||||
File.WriteAllText(FilePath, content);
|
File.WriteAllText(FilePath, content);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text.Json;
|
using Newtonsoft.Json;
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
@ -49,7 +49,7 @@ public class SimpleJsonStateMachine : IStateMachine
|
|||||||
{
|
{
|
||||||
var content = File.ReadAllText(FilePath);
|
var content = File.ReadAllText(FilePath);
|
||||||
|
|
||||||
var sc = JsonSerializer.Deserialize<StateContainer>(content);
|
var sc = JsonConvert.DeserializeObject<StateContainer>(content);
|
||||||
|
|
||||||
return sc;
|
return sc;
|
||||||
}
|
}
|
||||||
@ -74,9 +74,7 @@ public class SimpleJsonStateMachine : IStateMachine
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var content = JsonSerializer.Serialize(e.States, new JsonSerializerOptions() {
|
var content = JsonConvert.SerializeObject(e.States, Formatting.Indented);
|
||||||
WriteIndented = true
|
|
||||||
});
|
|
||||||
|
|
||||||
File.WriteAllText(FilePath, content);
|
File.WriteAllText(FilePath, content);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
@ -57,7 +57,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Telegram.Bot" Version="22.2.0" />
|
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -14,12 +14,12 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<group targetFramework=".NETFramework4.6.1">
|
<group targetFramework=".NETFramework4.6.1">
|
||||||
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
|
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
|
||||||
<dependency id="Telegram.Bot" version="22.2.0" exclude="Build,Analyzers" />
|
<dependency id="Telegram.Bot" version="19.0.0" exclude="Build,Analyzers" />
|
||||||
</group>
|
</group>
|
||||||
<group targetFramework=".NETStandard2.0">
|
<group targetFramework=".NETStandard2.0">
|
||||||
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
|
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
|
||||||
<dependency id="Telegram.Bot" version="22.2.0" exclude="Build,Analyzers" />
|
<dependency id="Telegram.Bot" version="19.0.0" exclude="Build,Analyzers" />
|
||||||
</group>
|
</group>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</metadata>
|
</metadata>
|
||||||
</package>
|
</package>
|
||||||
|
|||||||
@ -38,11 +38,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TelegramBotBase.Extensions.
|
|||||||
EndProject
|
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}"
|
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
|
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
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user