Compare commits
No commits in common. "master" and "v6.4.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
|
|
||||||
@ -8,7 +8,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="TelegramBotBase" Version="6.4.1" />
|
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="TelegramBotBase" Version="6.4.1" />
|
<PackageReference Include="TelegramBotBase" Version="5.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -16,7 +16,6 @@ namespace BotAndWebApplication.BotStuff.Tasks
|
|||||||
.DefaultCommands()
|
.DefaultCommands()
|
||||||
.NoSerialization()
|
.NoSerialization()
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
.UseThreadPool()
|
|
||||||
.Build();
|
.Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,12 +8,12 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.11" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.9"/>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.11" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.9"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj" />
|
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="TelegramBotBase" Version="6.4.1" />
|
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="TelegramBotBase" Version="6.4.1" />
|
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
56
README.md
56
README.md
@ -14,10 +14,6 @@
|
|||||||
|
|
||||||
**Releases: [GitHub](https://github.com/MajMcCloud/TelegramBotFramework/releases)**
|
**Releases: [GitHub](https://github.com/MajMcCloud/TelegramBotFramework/releases)**
|
||||||
|
|
||||||
**Need your own bot? Get in touch https://t.me/botbasebuilder**
|
|
||||||
|
|
||||||
**on X: @florian_zevedei**
|
|
||||||
|
|
||||||
## Donate
|
## Donate
|
||||||
|
|
||||||
Paypal: [https://paypal.me/majmccloud](https://paypal.me/majmccloud)
|
Paypal: [https://paypal.me/majmccloud](https://paypal.me/majmccloud)
|
||||||
@ -106,7 +102,6 @@ var bot = BotBaseBuilder
|
|||||||
})
|
})
|
||||||
.NoSerialization()
|
.NoSerialization()
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
.UseSingleThread()
|
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
// Upload bot commands to BotFather
|
// Upload bot commands to BotFather
|
||||||
@ -127,32 +122,8 @@ like ChatId and other stuff your carrying.
|
|||||||
From there you build up your bots:
|
From there you build up your bots:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
public class Start : FormBase
|
public class StartForm : FormBase
|
||||||
{
|
{
|
||||||
|
|
||||||
public Start()
|
|
||||||
{
|
|
||||||
//Additional event handlers
|
|
||||||
Init += Start_Init;
|
|
||||||
Opened += Start_Opened;
|
|
||||||
Closed += Start_Closed;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets invoked on initialization, before navigation
|
|
||||||
private async Task Start_Init(object sender, Args.InitEventArgs e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets invoked after opened
|
|
||||||
private async Task Start_Opened(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets invoked after form has been closed
|
|
||||||
private async Task Start_Closed(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets invoked during Navigation to this form
|
// Gets invoked during Navigation to this form
|
||||||
public override async Task PreLoad(MessageResult message)
|
public override async Task PreLoad(MessageResult message)
|
||||||
{
|
{
|
||||||
@ -249,7 +220,6 @@ var bot = BotBaseBuilder
|
|||||||
})
|
})
|
||||||
.NoSerialization()
|
.NoSerialization()
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
.UseSingleThread()
|
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
bot.BotCommand += async (s, en) =>
|
bot.BotCommand += async (s, en) =>
|
||||||
@ -290,15 +260,15 @@ public class SimpleForm : AutoCleanForm
|
|||||||
{
|
{
|
||||||
public SimpleForm()
|
public SimpleForm()
|
||||||
{
|
{
|
||||||
DeleteSide = EDeleteSide.Both;
|
this.DeleteSide = TelegramBotBase.Enums.eDeleteSide.Both;
|
||||||
DeleteMode = EDeleteMode.OnLeavingForm;
|
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
||||||
|
|
||||||
Opened += SimpleForm_Opened;
|
this.Opened += SimpleForm_Opened;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SimpleForm_Opened(object sender, EventArgs e)
|
private async Task SimpleForm_Opened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await Device.Send("Hello world! (send 'back' to get back to Start)\r\nOr\r\nhi, hello, maybe, bye and ciao");
|
await this.Device.Send("Hello world! (send 'back' to get back to Start)\r\nOr\r\nhi, hello, maybe, bye and ciao");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Load(MessageResult message)
|
public override async Task Load(MessageResult message)
|
||||||
@ -336,13 +306,7 @@ public class SimpleForm : AutoCleanForm
|
|||||||
```csharp
|
```csharp
|
||||||
public class ButtonTestForm : AutoCleanForm
|
public class ButtonTestForm : AutoCleanForm
|
||||||
{
|
{
|
||||||
public ButtonTestForm()
|
public override async Task Opened()
|
||||||
{
|
|
||||||
this.DeleteMode = eDeleteMode.OnLeavingForm;
|
|
||||||
Opened += ButtonTestForm_Opened;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task ButtonTestForm_Opened(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
await this.Device.Send("Hello world! (Click 'back' to get back to Start)");
|
await this.Device.Send("Hello world! (Click 'back' to get back to Start)");
|
||||||
}
|
}
|
||||||
@ -412,10 +376,9 @@ public class ProgressTest : AutoCleanForm
|
|||||||
public ProgressTest()
|
public ProgressTest()
|
||||||
{
|
{
|
||||||
this.DeleteMode = eDeleteMode.OnLeavingForm;
|
this.DeleteMode = eDeleteMode.OnLeavingForm;
|
||||||
Opened += ProgressTest_Opened;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ProgressTest_Opened(object sender, EventArgs e)
|
public override async Task Opened()
|
||||||
{
|
{
|
||||||
await this.Device.Send("Welcome to ProgressTest");
|
await this.Device.Send("Welcome to ProgressTest");
|
||||||
}
|
}
|
||||||
@ -895,7 +858,6 @@ var bot = BotBaseBuilder
|
|||||||
})
|
})
|
||||||
.UseSimpleJSON(AppContext.BaseDirectory + "config\\states.json")
|
.UseSimpleJSON(AppContext.BaseDirectory + "config\\states.json")
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
.UseSingleThread()
|
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
await bot.Start();
|
await bot.Start();
|
||||||
@ -919,7 +881,6 @@ var bot = BotBaseBuilder
|
|||||||
})
|
})
|
||||||
.UseJSON(AppContext.BaseDirectory + "config\\states.json")
|
.UseJSON(AppContext.BaseDirectory + "config\\states.json")
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
.UseSingleThread()
|
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
await bot.Start();
|
await bot.Start();
|
||||||
@ -942,7 +903,6 @@ var bot = BotBaseBuilder
|
|||||||
})
|
})
|
||||||
.UseXML(AppContext.BaseDirectory + "config\\states.xml")
|
.UseXML(AppContext.BaseDirectory + "config\\states.xml")
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
.UseSingleThread()
|
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
await bot.Start();
|
await bot.Start();
|
||||||
@ -956,7 +916,7 @@ datatype and one for implementing into a form which should be invoked with event
|
|||||||
#### IStateMachine
|
#### IStateMachine
|
||||||
|
|
||||||
Is the basic StateMachine interface, it has two methods `SaveFormStates(SaveStatesEventArgs e)`
|
Is the basic StateMachine interface, it has two methods `SaveFormStates(SaveStatesEventArgs e)`
|
||||||
and `LoadFormStates()`, nothing fancy, just simple calls. Implement both methods with your own
|
and `StateContainerLoadFormStates()`, nothing fancy, just simple calls. Implement both methods with your own
|
||||||
serialization process.
|
serialization process.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="IronSoftware.System.Drawing" Version="2024.5.1" />
|
<PackageReference Include="IronSoftware.System.Drawing" Version="2024.1.1" />
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" />
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.3" />
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="TelegramBotBase" Version="6.0.0" />
|
<PackageReference Include="TelegramBotBase" Version="6.0.0" />
|
||||||
<PackageReference Include="Npgsql" Version="8.0.3" />
|
<PackageReference Include="Npgsql" Version="8.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
using System;
|
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;
|
||||||
|
|
||||||
@ -10,36 +9,16 @@ namespace TelegramBotBase.Base;
|
|||||||
|
|
||||||
public class MessageResult : ResultBase
|
public class MessageResult : ResultBase
|
||||||
{
|
{
|
||||||
|
internal MessageResult()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public MessageResult(Update update)
|
public MessageResult(Update update)
|
||||||
{
|
{
|
||||||
UpdateData = update;
|
UpdateData = update;
|
||||||
|
|
||||||
init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init()
|
public Update UpdateData { get; set; }
|
||||||
{
|
|
||||||
IsAction = UpdateData.CallbackQuery != null;
|
|
||||||
|
|
||||||
if (Message == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
IsBotCommand = Message.Entities?.Any(a => a.Type == MessageEntityType.BotCommand) ?? false;
|
|
||||||
|
|
||||||
if (!IsBotCommand)
|
|
||||||
return;
|
|
||||||
|
|
||||||
BotCommand = MessageText.Split(' ')[0];
|
|
||||||
|
|
||||||
IsBotGroupCommand = BotCommand.Contains("@");
|
|
||||||
|
|
||||||
if (IsBotGroupCommand)
|
|
||||||
{
|
|
||||||
BotCommand = BotCommand.Substring(0, BotCommand.LastIndexOf('@'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Update UpdateData { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the Device/ChatId
|
/// Returns the Device/ChatId
|
||||||
@ -76,17 +55,12 @@ public class MessageResult : ResultBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is this an action ? (i.e. button click)
|
/// Is this an action ? (i.e. button click)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsAction { get; private set; }
|
public bool IsAction => UpdateData.CallbackQuery != null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is this a command ? Starts with a slash '/' and a command
|
/// Is this a command ? Starts with a slash '/' and a command
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsBotCommand { get; private set; }
|
public bool IsBotCommand => MessageText.StartsWith("/");
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Is this a bot command sent from a group via @BotId ?
|
|
||||||
/// </summary>
|
|
||||||
public bool IsBotGroupCommand { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a List of all parameters which has been sent with the command itself (i.e. /start 123 456 789 =>
|
/// Returns a List of all parameters which has been sent with the command itself (i.e. /start 123 456 789 =>
|
||||||
@ -109,7 +83,18 @@ public class MessageResult : ResultBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns just the command (i.e. /start 1 2 3 => /start)
|
/// Returns just the command (i.e. /start 1 2 3 => /start)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BotCommand { get; private set; }
|
public string BotCommand
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!IsBotCommand)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MessageText.Split(' ')[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns if this message will be used on the first form or not.
|
/// Returns if this message will be used on the first form or not.
|
||||||
@ -126,7 +111,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);
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@ using Telegram.Bot.Types;
|
|||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Enums;
|
using TelegramBotBase.Enums;
|
||||||
using TelegramBotBase.Exceptions;
|
|
||||||
using TelegramBotBase.Interfaces;
|
using TelegramBotBase.Interfaces;
|
||||||
using TelegramBotBase.Sessions;
|
using TelegramBotBase.Sessions;
|
||||||
using Console = TelegramBotBase.Tools.Console;
|
using Console = TelegramBotBase.Tools.Console;
|
||||||
@ -116,7 +115,7 @@ public sealed class BotBase
|
|||||||
if (ds == null)
|
if (ds == null)
|
||||||
{
|
{
|
||||||
ds = await Sessions.StartSession(e.DeviceId);
|
ds = await Sessions.StartSession(e.DeviceId);
|
||||||
ds.LastMessage = e.Message;
|
ds.LastMessage = e.RawData.Message;
|
||||||
|
|
||||||
OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds));
|
OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds));
|
||||||
}
|
}
|
||||||
@ -140,13 +139,6 @@ public sealed class BotBase
|
|||||||
mr.IsFirstHandler = false;
|
mr.IsFirstHandler = false;
|
||||||
} while (ds.FormSwitched && i < GetSetting(ESettings.NavigationMaximum, 10));
|
} while (ds.FormSwitched && i < GetSetting(ESettings.NavigationMaximum, 10));
|
||||||
}
|
}
|
||||||
catch (InvalidServiceProviderConfiguration ex)
|
|
||||||
{
|
|
||||||
var ds = Sessions.GetSession(e.DeviceId);
|
|
||||||
OnException(new SystemExceptionEventArgs(e.Message.Text, e.DeviceId, ds, ex));
|
|
||||||
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var ds = Sessions.GetSession(e.DeviceId);
|
var ds = Sessions.GetSession(e.DeviceId);
|
||||||
@ -197,10 +189,13 @@ public sealed class BotBase
|
|||||||
/// <param name="deviceId">Contains the device/chat id of the device to update.</param>
|
/// <param name="deviceId">Contains the device/chat id of the device to update.</param>
|
||||||
public async Task InvokeMessageLoop(long deviceId)
|
public async Task InvokeMessageLoop(long deviceId)
|
||||||
{
|
{
|
||||||
var mr = new MessageResult(new Update
|
var mr = new MessageResult
|
||||||
{
|
{
|
||||||
Message = new Message()
|
UpdateData = new Update
|
||||||
});
|
{
|
||||||
|
Message = new Message()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
await InvokeMessageLoop(deviceId, mr);
|
await InvokeMessageLoop(deviceId, mr);
|
||||||
}
|
}
|
||||||
@ -265,7 +260,7 @@ public sealed class BotBase
|
|||||||
{
|
{
|
||||||
foreach (var scope in BotCommandScopes)
|
foreach (var scope in BotCommandScopes)
|
||||||
{
|
{
|
||||||
if (scope.Value.Any(a => Constants.Telegram.BotCommandIndicator + a.Command == command))
|
if (scope.Value.Any(a => "/" + a.Command == command))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,14 +73,14 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IBuildingStage QuickStart(string apiKey, Type startForm, bool throwPendingUpdates = false)
|
public IBuildingStage QuickStart(string apiKey, Type startForm)
|
||||||
{
|
{
|
||||||
_apiKey = apiKey;
|
_apiKey = apiKey;
|
||||||
_factory = new DefaultStartFormFactory(startForm);
|
_factory = new DefaultStartFormFactory(startForm);
|
||||||
|
|
||||||
DefaultMessageLoop();
|
DefaultMessageLoop();
|
||||||
|
|
||||||
NoProxy(throwPendingUpdates);
|
NoProxy();
|
||||||
|
|
||||||
OnlyStart();
|
OnlyStart();
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IBuildingStage QuickStart<T>(string apiKey, bool throwPendingUpdates = false)
|
public IBuildingStage QuickStart<T>(string apiKey)
|
||||||
where T : FormBase
|
where T : FormBase
|
||||||
{
|
{
|
||||||
_apiKey = apiKey;
|
_apiKey = apiKey;
|
||||||
@ -102,7 +102,7 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
|
|
||||||
DefaultMessageLoop();
|
DefaultMessageLoop();
|
||||||
|
|
||||||
NoProxy(throwPendingUpdates);
|
NoProxy();
|
||||||
|
|
||||||
OnlyStart();
|
OnlyStart();
|
||||||
|
|
||||||
@ -115,14 +115,14 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBuildingStage QuickStart(string apiKey, IStartFormFactory startFormFactory, bool throwPendingUpdates = false)
|
public IBuildingStage QuickStart(string apiKey, IStartFormFactory startFormFactory)
|
||||||
{
|
{
|
||||||
_apiKey = apiKey;
|
_apiKey = apiKey;
|
||||||
_factory = startFormFactory;
|
_factory = startFormFactory;
|
||||||
|
|
||||||
DefaultMessageLoop();
|
DefaultMessageLoop();
|
||||||
|
|
||||||
NoProxy(throwPendingUpdates);
|
NoProxy();
|
||||||
|
|
||||||
OnlyStart();
|
OnlyStart();
|
||||||
|
|
||||||
|
|||||||
@ -20,18 +20,16 @@ public interface IAPIKeySelectionStage
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="apiKey"></param>
|
/// <param name="apiKey"></param>
|
||||||
/// <param name="StartForm"></param>
|
/// <param name="StartForm"></param>
|
||||||
/// <param name="throwPendingUpdates">Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling.</param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IBuildingStage QuickStart(string apiKey, Type StartForm, bool throwPendingUpdates = false);
|
IBuildingStage QuickStart(string apiKey, Type StartForm);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Quick and easy way to create a BotBase instance.
|
/// Quick and easy way to create a BotBase instance.
|
||||||
/// Uses: DefaultMessageLoop, NoProxy, OnlyStart, NoSerialization, DefaultLanguage
|
/// Uses: DefaultMessageLoop, NoProxy, OnlyStart, NoSerialization, DefaultLanguage
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="apiKey"></param>
|
/// <param name="apiKey"></param>
|
||||||
/// <param name="throwPendingUpdates">Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling.</param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IBuildingStage QuickStart<T>(string apiKey , bool throwPendingUpdates = false) where T : FormBase;
|
IBuildingStage QuickStart<T>(string apiKey) where T : FormBase;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Quick and easy way to create a BotBase instance.
|
/// Quick and easy way to create a BotBase instance.
|
||||||
@ -39,7 +37,6 @@ public interface IAPIKeySelectionStage
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="apiKey"></param>
|
/// <param name="apiKey"></param>
|
||||||
/// <param name="StartFormFactory"></param>
|
/// <param name="StartFormFactory"></param>
|
||||||
/// <param name="throwPendingUpdates">Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling.</param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IBuildingStage QuickStart(string apiKey, IStartFormFactory StartFormFactory, bool throwPendingUpdates = false);
|
IBuildingStage QuickStart(string apiKey, IStartFormFactory StartFormFactory);
|
||||||
}
|
}
|
||||||
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
@ -21,16 +20,6 @@ public static class Extensions
|
|||||||
scope = BotCommandScope.Default();
|
scope = BotCommandScope.Default();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(command))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(command), $"{nameof(command)} parameter can not be null or empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(command.StartsWith(Constants.Telegram.BotCommandIndicator))
|
|
||||||
{
|
|
||||||
throw new ArgumentException($"{nameof(command)} parameter does not have to start with a slash, please remove.", $"{nameof(command)}");
|
|
||||||
}
|
|
||||||
|
|
||||||
var item = cmds.FirstOrDefault(a => a.Key.Type == scope.Type);
|
var item = cmds.FirstOrDefault(a => a.Key.Type == scope.Type);
|
||||||
|
|
||||||
if (item.Value != null)
|
if (item.Value != null)
|
||||||
|
|||||||
@ -16,15 +16,4 @@ public static class Telegram
|
|||||||
public const int MaxReplyKeyboardCols = 12;
|
public const int MaxReplyKeyboardCols = 12;
|
||||||
|
|
||||||
public const int MessageDeletionsPerSecond = 30;
|
public const int MessageDeletionsPerSecond = 30;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The maximum length of callback data. Will raise an exception of it exceeds it.
|
|
||||||
/// </summary>
|
|
||||||
public const int MaxCallBackDataBytes = 64;
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The slash constant which indicates a bot command.
|
|
||||||
/// </summary>
|
|
||||||
public const string BotCommandIndicator = "/";
|
|
||||||
}
|
}
|
||||||
@ -51,24 +51,7 @@ public class ButtonGrid : ControlBase
|
|||||||
DataSource = new ButtonFormDataSource(form);
|
DataSource = new ButtonFormDataSource(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
string m_Title = Default.Language["ButtonGrid_Title"];
|
public string Title { get; set; } = Default.Language["ButtonGrid_Title"];
|
||||||
|
|
||||||
public string Title
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return m_Title;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} property must have been a value unequal to null/empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
m_Title = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string ConfirmationText { get; set; } = "";
|
public string ConfirmationText { get; set; } = "";
|
||||||
|
|
||||||
@ -357,14 +340,14 @@ public class ButtonGrid : ControlBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//var button = HeadLayoutButtonRow?. .FirstOrDefault(a => a.Text.Trim() == result.MessageText)
|
//var button = HeadLayoutButtonRow?. .FirstOrDefault(a => a.Text.Trim() == result.MessageText)
|
||||||
// ?? SubHeadLayoutButtonRow?.FirstOrDefault(a => a.Text.Trim() == result.MessageText);
|
// ?? SubHeadLayoutButtonRow?.FirstOrDefault(a => a.Text.Trim() == result.MessageText);
|
||||||
|
|
||||||
// bf.ToList().FirstOrDefault(a => a.Text.Trim() == result.MessageText)
|
// bf.ToList().FirstOrDefault(a => a.Text.Trim() == result.MessageText)
|
||||||
|
|
||||||
//var index = bf.FindRowByButton(button);
|
//var index = bf.FindRowByButton(button);
|
||||||
|
|
||||||
check:
|
check:
|
||||||
|
|
||||||
//Remove button click message
|
//Remove button click message
|
||||||
if (DeleteReplyMessage)
|
if (DeleteReplyMessage)
|
||||||
@ -466,15 +449,15 @@ public class ButtonGrid : ControlBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//var bf = DataSource.ButtonForm;
|
//var bf = DataSource.ButtonForm;
|
||||||
|
|
||||||
//var button = HeadLayoutButtonRow?.FirstOrDefault(a => a.Value == result.RawData)
|
//var button = HeadLayoutButtonRow?.FirstOrDefault(a => a.Value == result.RawData)
|
||||||
// ?? SubHeadLayoutButtonRow?.FirstOrDefault(a => a.Value == result.RawData)
|
// ?? SubHeadLayoutButtonRow?.FirstOrDefault(a => a.Value == result.RawData)
|
||||||
// ?? bf.ToList().FirstOrDefault(a => a.Value == result.RawData);
|
// ?? bf.ToList().FirstOrDefault(a => a.Value == result.RawData);
|
||||||
|
|
||||||
//var index = bf.FindRowByButton(button);
|
//var index = bf.FindRowByButton(button);
|
||||||
|
|
||||||
check:
|
check:
|
||||||
if (match != null)
|
if (match != null)
|
||||||
{
|
{
|
||||||
await result.ConfirmAction(ConfirmationText ?? "");
|
await result.ConfirmAction(ConfirmationText ?? "");
|
||||||
@ -523,13 +506,13 @@ public class ButtonGrid : ControlBase
|
|||||||
if (DataSource.RowCount > Constants.Telegram.MaxInlineKeyBoardRows && !EnablePaging)
|
if (DataSource.RowCount > Constants.Telegram.MaxInlineKeyBoardRows && !EnablePaging)
|
||||||
{
|
{
|
||||||
throw new MaximumRowsReachedException
|
throw new MaximumRowsReachedException
|
||||||
{ Value = DataSource.RowCount, Maximum = Constants.Telegram.MaxInlineKeyBoardRows };
|
{ Value = DataSource.RowCount, Maximum = Constants.Telegram.MaxInlineKeyBoardRows };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DataSource.ColumnCount > Constants.Telegram.MaxInlineKeyBoardCols)
|
if (DataSource.ColumnCount > Constants.Telegram.MaxInlineKeyBoardCols)
|
||||||
{
|
{
|
||||||
throw new MaximumColsException
|
throw new MaximumColsException
|
||||||
{ Value = DataSource.ColumnCount, Maximum = Constants.Telegram.MaxInlineKeyBoardCols };
|
{ Value = DataSource.ColumnCount, Maximum = Constants.Telegram.MaxInlineKeyBoardCols };
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -539,13 +522,13 @@ public class ButtonGrid : ControlBase
|
|||||||
if (DataSource.RowCount > Constants.Telegram.MaxReplyKeyboardRows && !EnablePaging)
|
if (DataSource.RowCount > Constants.Telegram.MaxReplyKeyboardRows && !EnablePaging)
|
||||||
{
|
{
|
||||||
throw new MaximumRowsReachedException
|
throw new MaximumRowsReachedException
|
||||||
{ Value = DataSource.RowCount, Maximum = Constants.Telegram.MaxReplyKeyboardRows };
|
{ Value = DataSource.RowCount, Maximum = Constants.Telegram.MaxReplyKeyboardRows };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DataSource.ColumnCount > Constants.Telegram.MaxReplyKeyboardCols)
|
if (DataSource.ColumnCount > Constants.Telegram.MaxReplyKeyboardCols)
|
||||||
{
|
{
|
||||||
throw new MaximumColsException
|
throw new MaximumColsException
|
||||||
{ Value = DataSource.ColumnCount, Maximum = Constants.Telegram.MaxReplyKeyboardCols };
|
{ Value = DataSource.ColumnCount, Maximum = Constants.Telegram.MaxReplyKeyboardCols };
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -710,7 +693,7 @@ public class ButtonGrid : ControlBase
|
|||||||
Updated();
|
Updated();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
//Remove event handler
|
//Remove event handler
|
||||||
{
|
{
|
||||||
Device.MessageDeleted -= Device_MessageDeleted;
|
Device.MessageDeleted -= Device_MessageDeleted;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,6 @@ using TelegramBotBase.Enums;
|
|||||||
using TelegramBotBase.Exceptions;
|
using TelegramBotBase.Exceptions;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
using TelegramBotBase.Localizations;
|
using TelegramBotBase.Localizations;
|
||||||
using static System.Net.Mime.MediaTypeNames;
|
|
||||||
using static TelegramBotBase.Base.Async;
|
using static TelegramBotBase.Base.Async;
|
||||||
|
|
||||||
namespace TelegramBotBase.Controls.Hybrid;
|
namespace TelegramBotBase.Controls.Hybrid;
|
||||||
@ -52,24 +51,7 @@ public class CheckedButtonList : ControlBase
|
|||||||
DataSource = new ButtonFormDataSource(form);
|
DataSource = new ButtonFormDataSource(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
string m_Title = Default.Language["ButtonGrid_Title"];
|
public string Title { get; set; } = Default.Language["ButtonGrid_Title"];
|
||||||
|
|
||||||
public string Title
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return m_Title;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} property must have been a value unequal to null/empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
m_Title = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string ConfirmationText { get; set; } = "";
|
public string ConfirmationText { get; set; } = "";
|
||||||
|
|
||||||
|
|||||||
@ -67,24 +67,7 @@ public class TaggedButtonGrid : MultiView
|
|||||||
DataSource = new ButtonFormDataSource(form);
|
DataSource = new ButtonFormDataSource(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
string m_Title = Default.Language["ButtonGrid_Title"];
|
public string Title { get; set; } = Default.Language["ButtonGrid_Title"];
|
||||||
|
|
||||||
public string Title
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return m_Title;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} property must have been a value unequal to null/empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
m_Title = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string ConfirmationText { get; set; }
|
public string ConfirmationText { get; set; }
|
||||||
|
|
||||||
|
|||||||
@ -14,9 +14,9 @@ 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 = string.Empty;
|
||||||
|
|
||||||
public String Text
|
public String Text
|
||||||
{
|
{
|
||||||
@ -29,10 +29,6 @@ public class Label : ControlBase
|
|||||||
if (_text == value)
|
if (_text == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException($"{nameof(Text)}", $"{nameof(Text)} property must have been a value unequal to null/empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
_text = value;
|
_text = value;
|
||||||
_renderNecessary = true;
|
_renderNecessary = true;
|
||||||
@ -40,8 +36,6 @@ public class Label : ControlBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private ParseMode _parseMode = ParseMode.Markdown;
|
private ParseMode _parseMode = ParseMode.Markdown;
|
||||||
|
|
||||||
public ParseMode ParseMode
|
public ParseMode ParseMode
|
||||||
|
|||||||
@ -32,32 +32,10 @@ public class MultiToggleButton : ControlBase
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string ChangedString { get; set; } = Default.Language["MultiToggleButton_Changed"];
|
public string ChangedString { get; set; } = Default.Language["MultiToggleButton_Changed"];
|
||||||
|
|
||||||
private string _title = Default.Language["MultiToggleButton_Title"];
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This holds the title of the control.
|
/// This holds the title of the control.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public String Title
|
public string Title { get; set; } = Default.Language["MultiToggleButton_Title"];
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _title;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_title == value)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} must have been a value unequal to null/empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
_title = value;
|
|
||||||
_renderNecessary = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int? MessageId { get; set; }
|
public int? MessageId { get; set; }
|
||||||
|
|
||||||
|
|||||||
@ -36,31 +36,7 @@ public class ToggleButton : ControlBase
|
|||||||
|
|
||||||
public string ChangedString { get; set; } = Default.Language["ToggleButton_Changed"];
|
public string ChangedString { get; set; } = Default.Language["ToggleButton_Changed"];
|
||||||
|
|
||||||
private string _title = Default.Language["ToggleButton_Title"];
|
public string Title { get; set; } = Default.Language["ToggleButton_Title"];
|
||||||
|
|
||||||
public String Title
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _title;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_title == value)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} property must have been a value unequal to null/empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
_title = value;
|
|
||||||
_renderNecessary = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public int? MessageId { get; set; }
|
public int? MessageId { get; set; }
|
||||||
|
|
||||||
|
|||||||
@ -1,35 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Telegram.Bot.Exceptions;
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Exceptions;
|
|
||||||
|
|
||||||
public sealed class CallbackDataTooLongException : Exception
|
|
||||||
{
|
|
||||||
static ApiRequestException _innerException = new Telegram.Bot.Exceptions.ApiRequestException("Bad Request: BUTTON_DATA_INVALID", 400);
|
|
||||||
|
|
||||||
static String _message = $"You have exceeded the maximum {Constants.Telegram.MaxCallBackDataBytes} bytes of callback data.\r\nThis is a pre-sending message from the TelegramBotBase framework.\r\nread more: https://core.telegram.org/bots/api#inlinekeyboardbutton";
|
|
||||||
|
|
||||||
static String _message_with_bytes = $"You have exceeded the maximum {Constants.Telegram.MaxCallBackDataBytes} bytes of callback data with @current_callback_bytes@ bytes.\r\nThis is a pre-sending message from the TelegramBotBase framework.\r\nread more: https://core.telegram.org/bots/api#inlinekeyboardbutton";
|
|
||||||
|
|
||||||
public CallbackDataTooLongException() : base(_message, _innerException)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="current_callback_bytes">The amount of callback bytes generated.</param>
|
|
||||||
public CallbackDataTooLongException(int current_callback_bytes) : base(getMessage(current_callback_bytes), _innerException)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static String getMessage(int current_callback_bytes = -1)
|
|
||||||
{
|
|
||||||
if (current_callback_bytes == -1)
|
|
||||||
return _message;
|
|
||||||
|
|
||||||
return _message_with_bytes.Replace("@current_callback_bytes@", current_callback_bytes.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Exceptions
|
|
||||||
{
|
|
||||||
public sealed class InvalidServiceProviderConfiguration : Exception
|
|
||||||
{
|
|
||||||
public InvalidServiceProviderConfiguration(string message, Exception innerException) : base(message, innerException) { }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using TelegramBotBase.DependencyInjection;
|
using TelegramBotBase.DependencyInjection;
|
||||||
using TelegramBotBase.Exceptions;
|
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
using TelegramBotBase.Interfaces;
|
using TelegramBotBase.Interfaces;
|
||||||
|
|
||||||
@ -23,20 +22,9 @@ 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;
|
var fb = (FormBase)ActivatorUtilities.CreateInstance(_serviceProvider, _startFormClass);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
fb = (FormBase)ActivatorUtilities.CreateInstance(_serviceProvider, specifiedStartFrom ?? _startFormClass);
|
|
||||||
}
|
|
||||||
catch(InvalidOperationException ex)
|
|
||||||
{
|
|
||||||
throw new InvalidServiceProviderConfiguration(ex.Message, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Sets an internal field for future ServiceProvider navigation
|
//Sets an internal field for future ServiceProvider navigation
|
||||||
fb.SetServiceProvider(_serviceProvider);
|
fb.SetServiceProvider(_serviceProvider);
|
||||||
|
|||||||
@ -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,7 +1,4 @@
|
|||||||
using System.Text;
|
using Newtonsoft.Json;
|
||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
using TelegramBotBase.Exceptions;
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Form;
|
namespace TelegramBotBase.Form;
|
||||||
|
|
||||||
@ -20,30 +17,28 @@ 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)
|
||||||
{
|
{
|
||||||
return new CallbackData(method, value).Serialize(true);
|
return new CallbackData(method, value).Serialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes data to json string
|
/// Serializes data to json string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string Serialize(bool throwExceptionOnOverflow = false)
|
public string Serialize()
|
||||||
{
|
{
|
||||||
var s = string.Empty;
|
var s = "";
|
||||||
|
try
|
||||||
s = JsonSerializer.Serialize(this);
|
{
|
||||||
|
s = JsonConvert.SerializeObject(this);
|
||||||
//Is data over 64 bytes ?
|
}
|
||||||
int byte_count = Encoding.UTF8.GetByteCount(s);
|
catch
|
||||||
if (throwExceptionOnOverflow && byte_count > Constants.Telegram.MaxCallBackDataBytes)
|
|
||||||
{
|
{
|
||||||
throw new CallbackDataTooLongException(byte_count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
@ -56,8 +51,19 @@ public class CallbackData
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static CallbackData Deserialize(string data)
|
public static CallbackData Deserialize(string data)
|
||||||
{
|
{
|
||||||
return JsonSerializer.Deserialize<CallbackData>(data);
|
CallbackData cd = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
cd = JsonConvert.DeserializeObject<CallbackData>(data);
|
||||||
|
|
||||||
|
return cd;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static implicit operator string(CallbackData callbackData) => callbackData.Serialize(true);
|
public static implicit operator string(CallbackData callbackData) => callbackData.Serialize();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,6 +34,5 @@ public sealed class English : Localization
|
|||||||
Values["ToggleButton_Changed"] = "Setting changed";
|
Values["ToggleButton_Changed"] = "Setting changed";
|
||||||
Values["ButtonGrid_SearchIcon"] = "🔍";
|
Values["ButtonGrid_SearchIcon"] = "🔍";
|
||||||
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
||||||
Values["Label_Text"] = "Default label text";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,6 +34,5 @@ public sealed class German : Localization
|
|||||||
Values["ToggleButton_Changed"] = "Einstellung geändert";
|
Values["ToggleButton_Changed"] = "Einstellung geändert";
|
||||||
Values["ButtonGrid_SearchIcon"] = "🔍";
|
Values["ButtonGrid_SearchIcon"] = "🔍";
|
||||||
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
||||||
Values["Label_Text"] = "Standard Label Text";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -34,7 +34,6 @@ public sealed class Persian : Localization
|
|||||||
Values["ToggleButton_Changed"] = "تنظیمات تغییر کرد";
|
Values["ToggleButton_Changed"] = "تنظیمات تغییر کرد";
|
||||||
Values["ButtonGrid_SearchIcon"] = "🔍";
|
Values["ButtonGrid_SearchIcon"] = "🔍";
|
||||||
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
||||||
Values["Label_Text"] = "متن برچسب پیشفرض";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,6 +34,5 @@ public sealed class Russian : Localization
|
|||||||
Values["ToggleButton_Changed"] = "Настройки изменены";
|
Values["ToggleButton_Changed"] = "Настройки изменены";
|
||||||
Values["ButtonGrid_SearchIcon"] = "🔍";
|
Values["ButtonGrid_SearchIcon"] = "🔍";
|
||||||
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
||||||
Values["Label_Text"] = "Текст метки по умолчанию";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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
|
||||||
@ -81,16 +79,13 @@ public class FormBaseMessageLoop : IMessageLoopFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Action Event
|
//Action Event
|
||||||
if (!session.FormSwitched && mr.IsAction && !mr.Handled)
|
if (!session.FormSwitched && mr.IsAction)
|
||||||
{
|
{
|
||||||
//Send Action event to controls
|
//Send Action event to controls
|
||||||
await activeForm.ActionControls(mr);
|
await activeForm.ActionControls(mr);
|
||||||
|
|
||||||
if (!mr.Handled)
|
//Send Action event to form itself
|
||||||
{
|
await activeForm.Action(mr);
|
||||||
//Send Action event to form itself, if not already handled by a control
|
|
||||||
await activeForm.Action(mr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mr.Handled)
|
if (!mr.Handled)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -72,16 +72,13 @@ public class FullMessageLoop : IMessageLoopFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Action Event
|
//Action Event
|
||||||
if (!session.FormSwitched && mr.IsAction && !mr.Handled)
|
if (!session.FormSwitched && mr.IsAction)
|
||||||
{
|
{
|
||||||
//Send Action event to controls
|
//Send Action event to controls
|
||||||
await activeForm.ActionControls(mr);
|
await activeForm.ActionControls(mr);
|
||||||
|
|
||||||
if (!mr.Handled)
|
//Send Action event to form itself
|
||||||
{
|
await activeForm.Action(mr);
|
||||||
//Send Action event to form itself, if not already handled by a control
|
|
||||||
await activeForm.Action(mr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mr.Handled)
|
if (!mr.Handled)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -131,9 +131,13 @@ public class DeviceSession : IDeviceSession
|
|||||||
public async Task ConfirmAction(string callbackQueryId, string message = "", bool showAlert = false,
|
public async Task ConfirmAction(string callbackQueryId, string message = "", bool showAlert = false,
|
||||||
string urlToOpen = null)
|
string urlToOpen = null)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
await Client.TelegramClient.AnswerCallbackQueryAsync(callbackQueryId, message, showAlert, urlToOpen);
|
{
|
||||||
|
await Client.TelegramClient.AnswerCallbackQueryAsync(callbackQueryId, message, showAlert, urlToOpen);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -153,8 +157,17 @@ public class DeviceSession : IDeviceSession
|
|||||||
throw new MessageTooLongException(text.Length);
|
throw new MessageTooLongException(text.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await Api(a =>
|
||||||
|
a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
return await Api(a => a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -172,9 +185,17 @@ public class DeviceSession : IDeviceSession
|
|||||||
throw new MessageTooLongException(text.Length);
|
throw new MessageTooLongException(text.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await Api(a =>
|
||||||
|
a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
return await Api(a => a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
|
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -194,8 +215,18 @@ public class DeviceSession : IDeviceSession
|
|||||||
throw new MessageTooLongException(message.Text.Length);
|
throw new MessageTooLongException(message.Text.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await Api(a => a.EditMessageTextAsync(DeviceId, message.MessageId, message.Text, parseMode,
|
try
|
||||||
replyMarkup: markup));
|
{
|
||||||
|
return await Api(a =>
|
||||||
|
a.EditMessageTextAsync(DeviceId, message.MessageId, message.Text, parseMode,
|
||||||
|
replyMarkup: markup));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -206,8 +237,15 @@ public class DeviceSession : IDeviceSession
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<Message> EditReplyMarkup(int messageId, ButtonForm bf)
|
public async Task<Message> EditReplyMarkup(int messageId, ButtonForm bf)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await Api(a => a.EditMessageReplyMarkupAsync(DeviceId, messageId, bf));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
return await Api(a => a.EditMessageReplyMarkupAsync(DeviceId, messageId, bf));
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -239,15 +277,21 @@ public class DeviceSession : IDeviceSession
|
|||||||
text = text.MarkdownV2Escape();
|
text = text.MarkdownV2Escape();
|
||||||
}
|
}
|
||||||
|
|
||||||
var t = Api(a => a.SendMessage(deviceId, text, messageThreadId: null, parseMode: parseMode, replyParameters: replyTo,
|
try
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
{
|
||||||
|
var t = Api(a => a.SendTextMessageAsync(deviceId, text, null, parseMode, replyToMessageId: replyTo,
|
||||||
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
|
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
return await t;
|
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -292,15 +336,20 @@ public class DeviceSession : IDeviceSession
|
|||||||
text = text.MarkdownV2Escape();
|
text = text.MarkdownV2Escape();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
|
||||||
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var t = Api(a => a.SendMessage(DeviceId, text, messageThreadId: null, parseMode: parseMode, replyParameters: replyTo,
|
var o = GetOrigin(new StackTrace());
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
|
||||||
|
|
||||||
return await t;
|
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -311,7 +360,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)
|
||||||
{
|
{
|
||||||
@ -330,15 +379,20 @@ public class DeviceSession : IDeviceSession
|
|||||||
text = text.MarkdownV2Escape();
|
text = text.MarkdownV2Escape();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
|
||||||
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var t = Api(a => a.SendMessage(DeviceId, text, messageThreadId: null, parseMode: parseMode, replyParameters: replyTo,
|
var o = GetOrigin(new StackTrace());
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
|
||||||
|
|
||||||
return await t;
|
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -360,15 +414,20 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var t = Api(a => a.SendPhotoAsync(DeviceId, file, null, caption, parseMode, replyToMessageId: replyTo,
|
||||||
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var t = Api(a => a.SendPhoto(DeviceId, file, messageThreadId: null, caption: caption, parseMode: parseMode, replyParameters: replyTo,
|
var o = GetOrigin(new StackTrace());
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
|
||||||
|
|
||||||
return await t;
|
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -390,16 +449,21 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var t = Api(a => a.SendVideoAsync(DeviceId, file, caption: caption, parseMode: parseMode,
|
||||||
|
replyToMessageId: replyTo, replyMarkup: markup,
|
||||||
|
disableNotification: disableNotification));
|
||||||
|
|
||||||
var t = Api(a => a.SendVideo(DeviceId, file, caption: caption, parseMode: parseMode,
|
var o = GetOrigin(new StackTrace());
|
||||||
replyParameters: replyTo, replyMarkup: markup,
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
disableNotification: disableNotification));
|
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
|
||||||
|
|
||||||
return await t;
|
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -420,16 +484,21 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var t = Api(a => a.SendVideoAsync(DeviceId, InputFile.FromUri(url), parseMode: parseMode,
|
||||||
|
replyToMessageId: replyTo, replyMarkup: markup,
|
||||||
|
disableNotification: disableNotification));
|
||||||
|
|
||||||
var t = Api(a => a.SendVideo(DeviceId, InputFile.FromUri(url), parseMode: parseMode,
|
var o = GetOrigin(new StackTrace());
|
||||||
replyParameters: replyTo, replyMarkup: markup,
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
disableNotification: disableNotification));
|
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
|
||||||
|
|
||||||
return await t;
|
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -451,19 +520,24 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var ms = new MemoryStream(video);
|
||||||
|
|
||||||
var ms = new MemoryStream(video);
|
var fts = InputFile.FromStream(ms, filename);
|
||||||
|
|
||||||
var fts = InputFile.FromStream(ms, filename);
|
var t = Api(a => a.SendVideoAsync(DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo,
|
||||||
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var t = Api(a => a.SendVideo(DeviceId, fts, parseMode: parseMode, replyParameters: replyTo,
|
var o = GetOrigin(new StackTrace());
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
|
||||||
|
|
||||||
return await t;
|
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -486,21 +560,26 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var fs = new FileStream(filepath, FileMode.Open);
|
||||||
|
|
||||||
var fs = new FileStream(filepath, FileMode.Open);
|
var filename = Path.GetFileName(filepath);
|
||||||
|
|
||||||
var filename = Path.GetFileName(filepath);
|
var fts = InputFile.FromStream(fs, filename);
|
||||||
|
|
||||||
var fts = InputFile.FromStream(fs, filename);
|
var t = Api(a => a.SendVideoAsync(DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo,
|
||||||
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var t = Api(a => a.SendVideo(DeviceId, fts, parseMode: parseMode, replyParameters: replyTo,
|
var o = GetOrigin(new StackTrace());
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
|
||||||
|
|
||||||
return await t;
|
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -571,15 +650,20 @@ public class DeviceSession : IDeviceSession
|
|||||||
markup = buttons;
|
markup = buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
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,
|
var o = GetOrigin(new StackTrace());
|
||||||
disableNotification: disableNotification, replyParameters: replyTo));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
|
||||||
|
|
||||||
return await t;
|
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -630,16 +714,22 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
public async Task<Message> HideReplyKeyboard(string closedMsg = "Closed", bool autoDeleteResponse = true)
|
public async Task<Message> HideReplyKeyboard(string closedMsg = "Closed", bool autoDeleteResponse = true)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
var m = await Send(closedMsg, new ReplyKeyboardRemove());
|
{
|
||||||
|
var m = await Send(closedMsg, new ReplyKeyboardRemove());
|
||||||
if (autoDeleteResponse && m != null)
|
|
||||||
|
if (autoDeleteResponse && m != null)
|
||||||
|
{
|
||||||
|
await DeleteMessage(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
catch
|
||||||
{
|
{
|
||||||
await DeleteMessage(m);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -669,9 +759,13 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
public virtual async Task ChangeChatPermissions(ChatPermissions permissions)
|
public virtual async Task ChangeChatPermissions(ChatPermissions permissions)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
await Api(a => a.SetChatPermissionsAsync(DeviceId, permissions));
|
{
|
||||||
|
await Api(a => a.SetChatPermissionsAsync(DeviceId, permissions));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type GetOrigin(StackTrace stackTrace)
|
private Type GetOrigin(StackTrace stackTrace)
|
||||||
@ -771,11 +865,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
|
||||||
{
|
{
|
||||||
@ -784,31 +878,49 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
public virtual async Task<ChatMember> GetChatUser(long userId)
|
public virtual async Task<ChatMember> GetChatUser(long userId)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await Api(a => a.GetChatMemberAsync(DeviceId, userId));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
return await Api(a => a.GetChatMemberAsync(DeviceId, userId));
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("User BanUser instead.")]
|
[Obsolete("User BanUser instead.")]
|
||||||
public virtual async Task KickUser(long userId, DateTime until = default)
|
public virtual async Task KickUser(long userId, DateTime until = default)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
await Api(a => a.BanChatMemberAsync(DeviceId, userId, until));
|
{
|
||||||
|
await Api(a => a.BanChatMemberAsync(DeviceId, userId, until));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task BanUser(long userId, DateTime until = default)
|
public virtual async Task BanUser(long userId, DateTime until = default)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
await Api(a => a.BanChatMemberAsync(DeviceId, userId, until));
|
{
|
||||||
|
await Api(a => a.BanChatMemberAsync(DeviceId, userId, until));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task UnbanUser(long userId)
|
public virtual async Task UnbanUser(long userId)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
await Api(a => a.UnbanChatMemberAsync(DeviceId, userId));
|
{
|
||||||
|
await Api(a => a.UnbanChatMemberAsync(DeviceId, userId));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -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,11 +14,11 @@
|
|||||||
<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>
|
||||||
|
|||||||
@ -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