Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2457773a12 | ||
|
|
46e65faf31 | ||
|
|
193a4811bf | ||
|
|
08a0de8087 | ||
|
|
82469cff70 | ||
|
|
81eafe1219 | ||
|
|
183e89c36f | ||
|
|
ad6cf9539c | ||
|
|
46576eb819 | ||
|
|
cf9e2285f1 | ||
|
|
ecfacdadbb | ||
|
|
c00c2e8d8f | ||
|
|
bfd905d590 | ||
|
|
7b1bf75dde | ||
|
|
7a7a65c3a7 | ||
|
|
8a42a861cf | ||
|
|
47876681e0 | ||
|
|
9314b4c0e5 | ||
|
|
01c19b9900 | ||
|
|
0af587d27f | ||
|
|
97b9176c3a | ||
|
|
dfa479d409 |
@@ -6,7 +6,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="TelegramBotBase" Version="3.0.0" />
|
<PackageReference Include="TelegramBotBase" Version="3.1.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
<PackageReference Include="TelegramBotBase" Version="3.0.0" />
|
<PackageReference Include="TelegramBotBase" Version="3.1.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ Thanks !
|
|||||||
|
|
||||||
* [ButtonGrid](#button-grid)
|
* [ButtonGrid](#button-grid)
|
||||||
|
|
||||||
|
* [Paging and Searching](#paging--searching)
|
||||||
|
|
||||||
- [Groups](#groups)
|
- [Groups](#groups)
|
||||||
* [SplitterForm](#splitter-form)
|
* [SplitterForm](#splitter-form)
|
||||||
|
|
||||||
@@ -118,7 +120,7 @@ It gives you features which will look/feel like WinForms or have a good way to c
|
|||||||
## How to start:
|
## How to start:
|
||||||
|
|
||||||
Within your empty App your need to put some initial lines including your APIKey to get things started.
|
Within your empty App your need to put some initial lines including your APIKey to get things started.
|
||||||
The "BotBase" Class will manage a lot of things for you, like system calls, action events and so on.
|
The "BotBase" Class will manage a lot of things for you, like bot commands, action events and so on.
|
||||||
"StartForm" is your first Formular which every user will get internally redirected to, like a start page, you could redirect from there later in code, so users won't recognize it.
|
"StartForm" is your first Formular which every user will get internally redirected to, like a start page, you could redirect from there later in code, so users won't recognize it.
|
||||||
It needs to be a subclass of "FormBase" you will find in Namespace TelegramBotBase.Base
|
It needs to be a subclass of "FormBase" you will find in Namespace TelegramBotBase.Base
|
||||||
|
|
||||||
@@ -129,7 +131,10 @@ It needs to be a subclass of "FormBase" you will find in Namespace TelegramBotBa
|
|||||||
BotBase<StartForm> bb = new BotBase<StartForm>("{YOUR API KEY}");
|
BotBase<StartForm> bb = new BotBase<StartForm>("{YOUR API KEY}");
|
||||||
|
|
||||||
//Add Systemcommands if you like, you could catch them later
|
//Add Systemcommands if you like, you could catch them later
|
||||||
bb.SystemCalls.Add("/start");
|
bb.BotCommands.Add(new BotCommand() { Command = "start", Description = "Starts the bot" });
|
||||||
|
|
||||||
|
//Update bot commands to botfather
|
||||||
|
bb.UploadBotCommands().Wait();
|
||||||
|
|
||||||
//Start your Bot
|
//Start your Bot
|
||||||
bb.Start();
|
bb.Start();
|
||||||
@@ -221,10 +226,10 @@ await this.NavigateTo(tf);
|
|||||||
|
|
||||||
All examples are within the test project, so just try it out on your own.
|
All examples are within the test project, so just try it out on your own.
|
||||||
|
|
||||||
### Add some system calls (Example #0 - System Calls)
|
### Add some system calls (Example #0 - Bot Commands)
|
||||||
|
|
||||||
Inside of the BotFather you are able to add "Commands" to your TelegramBot. The user will see them, depending on the application as options he could choose.
|
Inside of the BotFather you are able to add "Commands" to your TelegramBot. The user will see them, depending on the application as options he could choose.
|
||||||
I'm calling them Systemcalls. Before start (and later for sure) you could add them to your BotBase. Every time a message comes in they will get checked if they are one of them.
|
Before start (and later for sure) you could add them to your BotBase. Every time a message comes in they will get checked if they are one of them.
|
||||||
If so, a special event Handler will get raised where you are easier able to manage the action behind.
|
If so, a special event Handler will get raised where you are easier able to manage the action behind.
|
||||||
|
|
||||||
Below we have 4 options.
|
Below we have 4 options.
|
||||||
@@ -242,13 +247,12 @@ Below we have 4 options.
|
|||||||
```
|
```
|
||||||
BotBase<Start> bb = new BotBase<Start>("{YOUR API KEY}");
|
BotBase<Start> bb = new BotBase<Start>("{YOUR API KEY}");
|
||||||
|
|
||||||
bb.SystemCalls.Add("/start");
|
bb.BotCommands.Add(new BotCommand() { Command = "start", Description = "Starts the bot" });
|
||||||
bb.SystemCalls.Add("/form1");
|
bb.BotCommands.Add(new BotCommand() { Command = "form1", Description = "Opens test form 1" });
|
||||||
bb.SystemCalls.Add("/form2");
|
bb.BotCommands.Add(new BotCommand() { Command = "form2", Description = "Opens test form 2" });
|
||||||
|
bb.BotCommands.Add(new BotCommand() { Command = "params", Description = "Returns all send parameters as a message." });
|
||||||
|
|
||||||
bb.SystemCalls.Add("/params");
|
bb.BotCommand += async (s, en) =>
|
||||||
|
|
||||||
bb.SystemCall += async (s, en) =>
|
|
||||||
{
|
{
|
||||||
switch (en.Command)
|
switch (en.Command)
|
||||||
{
|
{
|
||||||
@@ -279,6 +283,9 @@ bb.SystemCall += async (s, en) =>
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Update Bot commands to botfather
|
||||||
|
bb.UploadBotCommands().Wait();
|
||||||
|
|
||||||
bb.Start();
|
bb.Start();
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -799,6 +806,8 @@ await this.NavigateTo(cd);
|
|||||||
### Button Grid
|
### Button Grid
|
||||||
<img src="images/buttongrid.gif?raw=true" />
|
<img src="images/buttongrid.gif?raw=true" />
|
||||||
|
|
||||||
|
#### Paging & Searching
|
||||||
|
<img src="images/buttongrid_pagingfilter.gif?raw=true" />
|
||||||
|
|
||||||
## Groups
|
## Groups
|
||||||
|
|
||||||
|
|||||||
@@ -410,6 +410,19 @@ namespace TelegramBotBase.Form
|
|||||||
this.Controls.Remove(control);
|
this.Controls.Remove(control);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes all controls.
|
||||||
|
/// </summary>
|
||||||
|
public void RemoveAllControls()
|
||||||
|
{
|
||||||
|
foreach(var c in this.Controls)
|
||||||
|
{
|
||||||
|
c.Cleanup().Wait();
|
||||||
|
|
||||||
|
this.Controls.Remove(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Cleanup
|
/// Cleanup
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics.SymbolStore;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -12,6 +13,7 @@ using TelegramBotBase.Base;
|
|||||||
using TelegramBotBase.Enums;
|
using TelegramBotBase.Enums;
|
||||||
using TelegramBotBase.Exceptions;
|
using TelegramBotBase.Exceptions;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
using static TelegramBotBase.Base.Async;
|
||||||
|
|
||||||
namespace TelegramBotBase.Controls
|
namespace TelegramBotBase.Controls
|
||||||
{
|
{
|
||||||
@@ -55,6 +57,14 @@ namespace TelegramBotBase.Controls
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool EnablePaging { get; set; } = false;
|
public bool EnablePaging { get; set; } = false;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enabled a search function.
|
||||||
|
/// </summary>
|
||||||
|
public bool EnableSearch { get; set; } = false;
|
||||||
|
|
||||||
|
public String SearchQuery { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Index of the current page
|
/// Index of the current page
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -66,6 +76,8 @@ namespace TelegramBotBase.Controls
|
|||||||
|
|
||||||
public String NoItemsLabel = Localizations.Default.Language["ButtonGrid_NoItems"];
|
public String NoItemsLabel = Localizations.Default.Language["ButtonGrid_NoItems"];
|
||||||
|
|
||||||
|
public String SearchLabel = Localizations.Default.Language["ButtonGrid_SearchFeature"];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Layout of the buttons which should be displayed always on top.
|
/// Layout of the buttons which should be displayed always on top.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -115,7 +127,7 @@ namespace TelegramBotBase.Controls
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public event EventHandler<ButtonClickedEventArgs> ButtonClicked
|
public event AsyncEventHandler<ButtonClickedEventArgs> ButtonClicked
|
||||||
{
|
{
|
||||||
add
|
add
|
||||||
{
|
{
|
||||||
@@ -127,9 +139,13 @@ namespace TelegramBotBase.Controls
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnButtonClicked(ButtonClickedEventArgs e)
|
public async Task OnButtonClicked(ButtonClickedEventArgs e)
|
||||||
{
|
{
|
||||||
(this.Events[__evButtonClicked] as EventHandler<ButtonClickedEventArgs>)?.Invoke(this, e);
|
var handler = this.Events[__evButtonClicked].GetInvocationList().Cast<AsyncEventHandler<ButtonClickedEventArgs>>();
|
||||||
|
foreach (var h in handler)
|
||||||
|
{
|
||||||
|
await Async.InvokeAllAsync<ButtonClickedEventArgs>(h, this, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async override Task Load(MessageResult result)
|
public async override Task Load(MessageResult result)
|
||||||
@@ -144,8 +160,9 @@ namespace TelegramBotBase.Controls
|
|||||||
|
|
||||||
if (button == null)
|
if (button == null)
|
||||||
{
|
{
|
||||||
if (result.MessageText != null)
|
if (result.MessageText == null)
|
||||||
{
|
return;
|
||||||
|
|
||||||
if (result.MessageText == PreviousPageLabel)
|
if (result.MessageText == PreviousPageLabel)
|
||||||
{
|
{
|
||||||
if (this.CurrentPageIndex > 0)
|
if (this.CurrentPageIndex > 0)
|
||||||
@@ -160,13 +177,38 @@ namespace TelegramBotBase.Controls
|
|||||||
|
|
||||||
this.Updated();
|
this.Updated();
|
||||||
}
|
}
|
||||||
|
else if (this.EnableSearch)
|
||||||
|
{
|
||||||
|
if (result.MessageText.StartsWith("🔍"))
|
||||||
|
{
|
||||||
|
//Sent note about searching
|
||||||
|
if (this.SearchQuery == null)
|
||||||
|
{
|
||||||
|
await this.Device.Send(this.SearchLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.SearchQuery = null;
|
||||||
|
this.Updated();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.SearchQuery = result.MessageText;
|
||||||
|
|
||||||
|
if (this.SearchQuery != null && this.SearchQuery != "")
|
||||||
|
{
|
||||||
|
this.CurrentPageIndex = 0;
|
||||||
|
this.Updated();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
OnButtonClicked(new ButtonClickedEventArgs(button));
|
await OnButtonClicked(new ButtonClickedEventArgs(button));
|
||||||
|
|
||||||
//Remove button click message
|
//Remove button click message
|
||||||
if (this.DeletePreviousMessage)
|
if (this.DeletePreviousMessage)
|
||||||
@@ -219,7 +261,7 @@ namespace TelegramBotBase.Controls
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
OnButtonClicked(new ButtonClickedEventArgs(button));
|
await OnButtonClicked(new ButtonClickedEventArgs(button));
|
||||||
|
|
||||||
result.Handled = true;
|
result.Handled = true;
|
||||||
|
|
||||||
@@ -277,8 +319,16 @@ namespace TelegramBotBase.Controls
|
|||||||
|
|
||||||
Message m = null;
|
Message m = null;
|
||||||
|
|
||||||
ButtonForm form = this.ButtonsForm.Duplicate();
|
ButtonForm form = this.ButtonsForm;
|
||||||
|
|
||||||
|
if (this.EnableSearch && this.SearchQuery != null && this.SearchQuery != "")
|
||||||
|
{
|
||||||
|
form = form.FilterDuplicate(this.SearchQuery);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
form = form.Duplicate();
|
||||||
|
}
|
||||||
|
|
||||||
if (this.EnablePaging)
|
if (this.EnablePaging)
|
||||||
{
|
{
|
||||||
@@ -363,10 +413,21 @@ namespace TelegramBotBase.Controls
|
|||||||
bf.AddButtonRow(new ButtonBase(NoItemsLabel, "$"));
|
bf.AddButtonRow(new ButtonBase(NoItemsLabel, "$"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//🔍
|
||||||
|
List<ButtonBase> lst = new List<ButtonBase>();
|
||||||
|
lst.Add(new ButtonBase(PreviousPageLabel, "$previous$"));
|
||||||
|
lst.Add(new ButtonBase(String.Format(Localizations.Default.Language["ButtonGrid_CurrentPage"], this.CurrentPageIndex + 1, this.PageCount), "$site$"));
|
||||||
|
lst.Add(new ButtonBase(NextPageLabel, "$next$"));
|
||||||
|
|
||||||
bf.InsertButtonRow(0, new ButtonBase(PreviousPageLabel, "$previous$"), new ButtonBase(String.Format(Localizations.Default.Language["ButtonGrid_CurrentPage"], this.CurrentPageIndex + 1, this.PageCount), "$site$"), new ButtonBase(NextPageLabel, "$next$"));
|
|
||||||
|
|
||||||
bf.AddButtonRow(new ButtonBase(PreviousPageLabel, "$previous$"), new ButtonBase(String.Format(Localizations.Default.Language["ButtonGrid_CurrentPage"], this.CurrentPageIndex + 1, this.PageCount), "$site$"), new ButtonBase(NextPageLabel, "$next$"));
|
if (this.EnableSearch)
|
||||||
|
{
|
||||||
|
lst.Insert(2, new ButtonBase("🔍 " + (this.SearchQuery ?? ""), "$search$"));
|
||||||
|
}
|
||||||
|
|
||||||
|
bf.InsertButtonRow(0, lst);
|
||||||
|
|
||||||
|
bf.AddButtonRow(lst);
|
||||||
|
|
||||||
return bf;
|
return bf;
|
||||||
}
|
}
|
||||||
@@ -428,7 +489,14 @@ namespace TelegramBotBase.Controls
|
|||||||
if (this.ButtonsForm.Count == 0)
|
if (this.ButtonsForm.Count == 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return (int)Math.Ceiling((decimal)(this.ButtonsForm.Rows / (decimal)(MaximumRow - 3)));
|
var bf = this.ButtonsForm;
|
||||||
|
|
||||||
|
if (this.EnableSearch && this.SearchQuery != null && this.SearchQuery != "")
|
||||||
|
{
|
||||||
|
bf = bf.FilterDuplicate(this.SearchQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int)Math.Ceiling((decimal)(bf.Rows / (decimal)(MaximumRow - 3)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ namespace TelegramBotBase.Controls
|
|||||||
|
|
||||||
public String UncheckedString { get; set; } = Localizations.Default.Language["ToggleButton_Off"];
|
public String UncheckedString { get; set; } = Localizations.Default.Language["ToggleButton_Off"];
|
||||||
|
|
||||||
|
public String ChangedString { get; set; } = Localizations.Default.Language["ToggleButton_Changed"];
|
||||||
|
|
||||||
public String Title { get; set; } = Localizations.Default.Language["ToggleButton_Title"];
|
public String Title { get; set; } = Localizations.Default.Language["ToggleButton_Title"];
|
||||||
|
|
||||||
public int? MessageId { get; set; }
|
public int? MessageId { get; set; }
|
||||||
@@ -68,7 +70,7 @@ namespace TelegramBotBase.Controls
|
|||||||
if (result.Handled)
|
if (result.Handled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await result.ConfirmAction();
|
await result.ConfirmAction(this.ChangedString);
|
||||||
|
|
||||||
switch (value ?? "unknown")
|
switch (value ?? "unknown")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.ComponentModel;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using TelegramBotBase.Attributes;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
|
|
||||||
namespace TelegramBotBase.Form
|
namespace TelegramBotBase.Form
|
||||||
@@ -11,6 +12,7 @@ namespace TelegramBotBase.Form
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A simple prompt dialog with one ok Button
|
/// A simple prompt dialog with one ok Button
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[IgnoreState]
|
||||||
public class AlertDialog : ConfirmDialog
|
public class AlertDialog : ConfirmDialog
|
||||||
{
|
{
|
||||||
public String ButtonText { get; set; }
|
public String ButtonText { get; set; }
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
|
using TelegramBotBase.Attributes;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
|
|
||||||
namespace TelegramBotBase.Form
|
namespace TelegramBotBase.Form
|
||||||
@@ -12,11 +13,11 @@ namespace TelegramBotBase.Form
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A prompt with a lot of buttons
|
/// A prompt with a lot of buttons
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[IgnoreState]
|
||||||
public class ArrayPromptDialog : FormBase
|
public class ArrayPromptDialog : FormBase
|
||||||
{
|
{
|
||||||
public String Message { get; set; }
|
public String Message { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public ButtonBase[][] Buttons { get; set; }
|
public ButtonBase[][] Buttons { get; set; }
|
||||||
|
|
||||||
[Obsolete]
|
[Obsolete]
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
|
using TelegramBotBase.Attributes;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Enums;
|
using TelegramBotBase.Enums;
|
||||||
|
|
||||||
@@ -15,17 +16,20 @@ namespace TelegramBotBase.Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class AutoCleanForm : FormBase
|
public class AutoCleanForm : FormBase
|
||||||
{
|
{
|
||||||
List<Message> OldMessages { get; set; }
|
[SaveState]
|
||||||
|
public List<int> OldMessages { get; set; }
|
||||||
|
|
||||||
|
[SaveState]
|
||||||
public eDeleteMode DeleteMode { get; set; }
|
public eDeleteMode DeleteMode { get; set; }
|
||||||
|
|
||||||
|
[SaveState]
|
||||||
public eDeleteSide DeleteSide { get; set; }
|
public eDeleteSide DeleteSide { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public AutoCleanForm()
|
public AutoCleanForm()
|
||||||
{
|
{
|
||||||
this.OldMessages = new List<Message>();
|
this.OldMessages = new List<int>();
|
||||||
this.DeleteMode = eDeleteMode.OnEveryCall;
|
this.DeleteMode = eDeleteMode.OnEveryCall;
|
||||||
this.DeleteSide = eDeleteSide.BotOnly;
|
this.DeleteSide = eDeleteSide.BotOnly;
|
||||||
|
|
||||||
@@ -52,7 +56,7 @@ namespace TelegramBotBase.Form
|
|||||||
if (this.DeleteSide == eDeleteSide.BotOnly)
|
if (this.DeleteSide == eDeleteSide.BotOnly)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.OldMessages.Add(e.Message);
|
this.OldMessages.Add(e.Message.MessageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Device_MessageSent(object sender, MessageSentEventArgs e)
|
private void Device_MessageSent(object sender, MessageSentEventArgs e)
|
||||||
@@ -60,7 +64,7 @@ namespace TelegramBotBase.Form
|
|||||||
if (this.DeleteSide == eDeleteSide.UserOnly)
|
if (this.DeleteSide == eDeleteSide.UserOnly)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.OldMessages.Add(e.Message);
|
this.OldMessages.Add(e.Message.MessageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task PreLoad(MessageResult message)
|
public override async Task PreLoad(MessageResult message)
|
||||||
@@ -77,7 +81,17 @@ namespace TelegramBotBase.Form
|
|||||||
/// <param name="Id"></param>
|
/// <param name="Id"></param>
|
||||||
public void AddMessage(Message m)
|
public void AddMessage(Message m)
|
||||||
{
|
{
|
||||||
this.OldMessages.Add(m);
|
this.OldMessages.Add(m.MessageId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a message to this of removable ones
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Id"></param>
|
||||||
|
public void AddMessage(int messageId)
|
||||||
|
{
|
||||||
|
this.OldMessages.Add(messageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -86,11 +100,7 @@ namespace TelegramBotBase.Form
|
|||||||
/// <param name="Id"></param>
|
/// <param name="Id"></param>
|
||||||
public void LeaveMessage(int Id)
|
public void LeaveMessage(int Id)
|
||||||
{
|
{
|
||||||
var m = this.OldMessages.FirstOrDefault(a => a.MessageId == Id);
|
this.OldMessages.Remove(Id);
|
||||||
if (m == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
this.OldMessages.Remove(m);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -120,7 +130,7 @@ namespace TelegramBotBase.Form
|
|||||||
{
|
{
|
||||||
while (this.OldMessages.Count > 0)
|
while (this.OldMessages.Count > 0)
|
||||||
{
|
{
|
||||||
if (!await this.Device.DeleteMessage(this.OldMessages[0].MessageId))
|
if (!await this.Device.DeleteMessage(this.OldMessages[0]))
|
||||||
{
|
{
|
||||||
//Message can't be deleted cause it seems not to exist anymore
|
//Message can't be deleted cause it seems not to exist anymore
|
||||||
if (this.OldMessages.Count > 0)
|
if (this.OldMessages.Count > 0)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace TelegramBotBase.Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ButtonBase
|
public class ButtonBase
|
||||||
{
|
{
|
||||||
public String Text { get; set; }
|
public virtual String Text { get; set; }
|
||||||
|
|
||||||
public String Value { get; set; }
|
public String Value { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -188,10 +188,10 @@ namespace TelegramBotBase.Form
|
|||||||
DependencyControl = this.DependencyControl
|
DependencyControl = this.DependencyControl
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach(var b in Buttons)
|
foreach (var b in Buttons)
|
||||||
{
|
{
|
||||||
var lst = new List<ButtonBase>();
|
var lst = new List<ButtonBase>();
|
||||||
foreach(var b2 in b)
|
foreach (var b2 in b)
|
||||||
{
|
{
|
||||||
lst.Add(b2);
|
lst.Add(b2);
|
||||||
}
|
}
|
||||||
@@ -200,5 +200,35 @@ namespace TelegramBotBase.Form
|
|||||||
|
|
||||||
return bf;
|
return bf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a copy of this form and filters by the parameter.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ButtonForm FilterDuplicate(String filter)
|
||||||
|
{
|
||||||
|
var bf = new ButtonForm()
|
||||||
|
{
|
||||||
|
Markup = this.Markup,
|
||||||
|
DependencyControl = this.DependencyControl
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var b in Buttons)
|
||||||
|
{
|
||||||
|
var lst = new List<ButtonBase>();
|
||||||
|
foreach (var b2 in b)
|
||||||
|
{
|
||||||
|
if (b2.Text.IndexOf(filter, StringComparison.InvariantCultureIgnoreCase) == -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
lst.Add(b2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lst.Count > 0)
|
||||||
|
bf.Buttons.Add(lst);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,16 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
|
using TelegramBotBase.Attributes;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
|
|
||||||
namespace TelegramBotBase.Form
|
namespace TelegramBotBase.Form
|
||||||
{
|
{
|
||||||
|
[IgnoreState]
|
||||||
public class ConfirmDialog : ModalDialog
|
public class ConfirmDialog : ModalDialog
|
||||||
{
|
{
|
||||||
public String Message { get; set; }
|
public String Message { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public List<ButtonBase> Buttons { get; set; }
|
public List<ButtonBase> Buttons { get; set; }
|
||||||
|
|
||||||
private EventHandlerList __Events { get; set; } = new EventHandlerList();
|
private EventHandlerList __Events { get; set; } = new EventHandlerList();
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TelegramBotBase.Form
|
||||||
|
{
|
||||||
|
public class DynamicButton : ButtonBase
|
||||||
|
{
|
||||||
|
public override string Text
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return GetText?.Invoke() ?? m_text;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
m_text = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String m_text = "";
|
||||||
|
|
||||||
|
private Func<String> GetText;
|
||||||
|
|
||||||
|
public DynamicButton(String Text, String Value, String Url = null)
|
||||||
|
{
|
||||||
|
this.Text = Text;
|
||||||
|
this.Value = Value;
|
||||||
|
this.Url = Url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DynamicButton(Func<String> GetText, String Value, String Url = null)
|
||||||
|
{
|
||||||
|
this.GetText = GetText;
|
||||||
|
this.Value = Value;
|
||||||
|
this.Url = Url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,10 +5,12 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Telegram.Bot.Types.ReplyMarkups;
|
using Telegram.Bot.Types.ReplyMarkups;
|
||||||
|
using TelegramBotBase.Attributes;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
|
|
||||||
namespace TelegramBotBase.Form
|
namespace TelegramBotBase.Form
|
||||||
{
|
{
|
||||||
|
[IgnoreState]
|
||||||
public class PromptDialog : ModalDialog
|
public class PromptDialog : ModalDialog
|
||||||
{
|
{
|
||||||
public String Message { get; set; }
|
public String Message { get; set; }
|
||||||
|
|||||||
@@ -11,13 +11,22 @@ namespace TelegramBotBase.Localizations
|
|||||||
Values["Language"] = "English";
|
Values["Language"] = "English";
|
||||||
Values["ButtonGrid_Title"] = "Menu";
|
Values["ButtonGrid_Title"] = "Menu";
|
||||||
Values["ButtonGrid_NoItems"] = "There are no items.";
|
Values["ButtonGrid_NoItems"] = "There are no items.";
|
||||||
|
Values["ButtonGrid_PreviousPage"] = "◀️";
|
||||||
|
Values["ButtonGrid_NextPage"] = "▶️";
|
||||||
Values["ButtonGrid_CurrentPage"] = "Page {0} of {1}";
|
Values["ButtonGrid_CurrentPage"] = "Page {0} of {1}";
|
||||||
|
Values["ButtonGrid_SearchFeature"] = "💡 Send a message to filter the list. Click the 🔍 to reset the filter.";
|
||||||
Values["CalendarPicker_Title"] = "Pick date";
|
Values["CalendarPicker_Title"] = "Pick date";
|
||||||
|
Values["CalendarPicker_PreviousPage"] = "◀️";
|
||||||
|
Values["CalendarPicker_NextPage"] = "▶️";
|
||||||
Values["TreeView_Title"] = "Select node";
|
Values["TreeView_Title"] = "Select node";
|
||||||
Values["TreeView_LevelUp"] = "🔼 level up";
|
Values["TreeView_LevelUp"] = "🔼 level up";
|
||||||
Values["ToggleButton_On"] = "On";
|
Values["ToggleButton_On"] = "On";
|
||||||
Values["ToggleButton_Off"] = "Off";
|
Values["ToggleButton_Off"] = "Off";
|
||||||
|
Values["ToggleButton_OnIcon"] = "⚫";
|
||||||
|
Values["ToggleButton_OffIcon"] = "⚪";
|
||||||
Values["ToggleButton_Title"] = "Toggle";
|
Values["ToggleButton_Title"] = "Toggle";
|
||||||
|
Values["PromptDialog_Back"] = "Back";
|
||||||
|
Values["ToggleButton_Changed"] = "Setting changed";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace TelegramBotBase.Localizations
|
|||||||
Values["ButtonGrid_PreviousPage"] = "◀️";
|
Values["ButtonGrid_PreviousPage"] = "◀️";
|
||||||
Values["ButtonGrid_NextPage"] = "▶️";
|
Values["ButtonGrid_NextPage"] = "▶️";
|
||||||
Values["ButtonGrid_CurrentPage"] = "Seite {0} von {1}";
|
Values["ButtonGrid_CurrentPage"] = "Seite {0} von {1}";
|
||||||
|
Values["ButtonGrid_SearchFeature"] = "💡 Sende eine Nachricht um die Liste zu filtern. Klicke die 🔍 um den Filter zurückzusetzen.";
|
||||||
Values["CalendarPicker_Title"] = "Datum auswählen";
|
Values["CalendarPicker_Title"] = "Datum auswählen";
|
||||||
Values["CalendarPicker_PreviousPage"] = "◀️";
|
Values["CalendarPicker_PreviousPage"] = "◀️";
|
||||||
Values["CalendarPicker_NextPage"] = "▶️";
|
Values["CalendarPicker_NextPage"] = "▶️";
|
||||||
@@ -35,6 +36,7 @@ namespace TelegramBotBase.Localizations
|
|||||||
Values["ToggleButton_OffIcon"] = "⚪";
|
Values["ToggleButton_OffIcon"] = "⚪";
|
||||||
Values["ToggleButton_Title"] = "Schalter";
|
Values["ToggleButton_Title"] = "Schalter";
|
||||||
Values["PromptDialog_Back"] = "Zurück";
|
Values["PromptDialog_Back"] = "Zurück";
|
||||||
|
Values["ToggleButton_Changed"] = "Einstellung geändert";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("Florian Dahn")]
|
[assembly: AssemblyCompany("Florian Dahn")]
|
||||||
[assembly: AssemblyProduct("TelegramBotBase Framework")]
|
[assembly: AssemblyProduct("TelegramBotBase Framework")]
|
||||||
[assembly: AssemblyCopyright("Copyright © Florian Dahn 2019")]
|
[assembly: AssemblyCopyright("Copyright © Florian Dahn 2020")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||||
// übernehmen, indem Sie "*" eingeben:
|
// übernehmen, indem Sie "*" eingeben:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("2.1.0.0")]
|
[assembly: AssemblyVersion("3.1.0.0")]
|
||||||
[assembly: AssemblyFileVersion("2.1.0.0")]
|
[assembly: AssemblyFileVersion("3.1.0.0")]
|
||||||
|
|||||||
@@ -145,6 +145,16 @@ namespace TelegramBotBase
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (f.PropertyType.IsEnum)
|
||||||
|
{
|
||||||
|
var ent = Enum.Parse(f.PropertyType, p.Value.ToString());
|
||||||
|
|
||||||
|
f.SetValue(form, ent);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
f.SetValue(form, p.Value);
|
f.SetValue(form, p.Value);
|
||||||
}
|
}
|
||||||
catch (ArgumentException ex)
|
catch (ArgumentException ex)
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ namespace TelegramBotBase.Sessions
|
|||||||
this.ActiveForm.Device = this;
|
this.ActiveForm.Device = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Edits the text message
|
/// Edits the text message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -723,6 +724,19 @@ namespace TelegramBotBase.Sessions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual async Task UnbanUser(int userId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await this.Client.TelegramClient.UnbanChatMemberAsync(this.DeviceId, userId);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Eventhandler for sent messages
|
/// Eventhandler for sent messages
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace TelegramBotBase.States
|
|||||||
|
|
||||||
this.FallbackStateForm = fallbackStateForm;
|
this.FallbackStateForm = fallbackStateForm;
|
||||||
|
|
||||||
if (!this.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
if (this.FallbackStateForm != null && !this.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace TelegramBotBase.States
|
|||||||
|
|
||||||
this.FallbackStateForm = fallbackStateForm;
|
this.FallbackStateForm = fallbackStateForm;
|
||||||
|
|
||||||
if (!this.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
if (this.FallbackStateForm != null && !this.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace TelegramBotBase.States
|
|||||||
|
|
||||||
this.FallbackStateForm = fallbackStateForm;
|
this.FallbackStateForm = fallbackStateForm;
|
||||||
|
|
||||||
if (!this.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
if (this.FallbackStateForm != null && !this.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,28 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.0;net461;netcoreapp3.1</TargetFrameworks>
|
<TargetFrameworks>netstandard2.1;net461;netcoreapp3.1</TargetFrameworks>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||||
<PackageProjectUrl>https://github.com/MajMcCloud/TelegramBotFramework</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/MajMcCloud/TelegramBotFramework</PackageProjectUrl>
|
||||||
<RepositoryUrl>https://github.com/MajMcCloud/TelegramBotFramework</RepositoryUrl>
|
<RepositoryUrl>https://github.com/MajMcCloud/TelegramBotFramework</RepositoryUrl>
|
||||||
<PackageReleaseNotes>- moving from .Net Framework 4.7.2 to .Net Standard 2.1 for the Library and .Net Core 3.0 for the test project!</PackageReleaseNotes>
|
<PackageReleaseNotes>- moving from .Net Framework 4.7.2 to .Net Standard 2.1 for the Library and .Net Core 3.1 for the test project!</PackageReleaseNotes>
|
||||||
<Configurations>Debug;Release;</Configurations>
|
<Configurations>Debug;Release;</Configurations>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
|
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
|
||||||
<RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
|
<RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||||
|
<IncludeSymbols>true</IncludeSymbols>
|
||||||
|
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
@@ -56,6 +64,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="cpack.ps1" />
|
<None Remove="cpack.ps1" />
|
||||||
|
<None Remove="cpack_bak.ps1" />
|
||||||
<None Remove="cpush.ps1" />
|
<None Remove="cpush.ps1" />
|
||||||
<None Remove="nuget.exe" />
|
<None Remove="nuget.exe" />
|
||||||
<None Remove="TelegramBotBase.1.5.0.nupkg" />
|
<None Remove="TelegramBotBase.1.5.0.nupkg" />
|
||||||
@@ -64,6 +73,11 @@
|
|||||||
<None Remove="TelegramBotBase.1.5.1.zip" />
|
<None Remove="TelegramBotBase.1.5.1.zip" />
|
||||||
<None Remove="TelegramBotBase.1.5.2.nupkg" />
|
<None Remove="TelegramBotBase.1.5.2.nupkg" />
|
||||||
<None Remove="TelegramBotBase.1.5.2.zip" />
|
<None Remove="TelegramBotBase.1.5.2.zip" />
|
||||||
|
<None Remove="TelegramBotBase.2.0.0.nupkg" />
|
||||||
|
<None Remove="TelegramBotBase.2.1.0.nupkg" />
|
||||||
|
<None Remove="TelegramBotBase.2.1.0.zip" />
|
||||||
|
<None Remove="TelegramBotBase.3.0.0.nupkg" />
|
||||||
|
<None Remove="TelegramBotBase.3.0.0.zip" />
|
||||||
<None Remove="TelegramBotBase.nuspec" />
|
<None Remove="TelegramBotBase.nuspec" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Telegram.Bot.Types;
|
||||||
|
using TelegramBotBase;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
using TelegramBotBaseTest.Tests;
|
||||||
|
|
||||||
|
namespace TelegramBotBaseTest
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
|
||||||
|
BotBase<Start> bb = new BotBase<Start>(APIKey);
|
||||||
|
|
||||||
|
bb.BotCommands.Add(new BotCommand() { Command = "start", Description = "Starts the bot" });
|
||||||
|
bb.BotCommands.Add(new BotCommand() { Command = "form1", Description = "Opens test form 1" });
|
||||||
|
bb.BotCommands.Add(new BotCommand() { Command = "form2", Description = "Opens test form 2" });
|
||||||
|
bb.BotCommands.Add(new BotCommand() { Command = "params", Description = "Returns all send parameters as a message." });
|
||||||
|
|
||||||
|
bb.BotCommand += async (s, en) =>
|
||||||
|
{
|
||||||
|
switch (en.Command)
|
||||||
|
{
|
||||||
|
case "/start":
|
||||||
|
|
||||||
|
var start = new Menu();
|
||||||
|
|
||||||
|
await en.Device.ActiveForm.NavigateTo(start);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "/form1":
|
||||||
|
|
||||||
|
var form1 = new TestForm();
|
||||||
|
|
||||||
|
await en.Device.ActiveForm.NavigateTo(form1);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "/form2":
|
||||||
|
|
||||||
|
var form2 = new TestForm2();
|
||||||
|
|
||||||
|
await en.Device.ActiveForm.NavigateTo(form2);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "/params":
|
||||||
|
|
||||||
|
String m = en.Parameters.DefaultIfEmpty("").Aggregate((a, b) => a + " and " + b);
|
||||||
|
|
||||||
|
await en.Device.Send("Your parameters are: " + m, replyTo: en.Device.LastMessageId);
|
||||||
|
|
||||||
|
en.Handled = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
//Update Bot commands to botfather
|
||||||
|
bb.UploadBotCommands().Wait();
|
||||||
|
|
||||||
|
bb.SetSetting(TelegramBotBase.Enums.eSettings.LogAllMessages, true);
|
||||||
|
|
||||||
|
bb.Message += (s,en) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(en.DeviceId + " " + en.Message.MessageText + " " + (en.Message.RawData ?? ""));
|
||||||
|
};
|
||||||
|
|
||||||
|
bb.Start();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine("Telegram Bot started...");
|
||||||
|
|
||||||
|
Console.WriteLine("Press q to quit application.");
|
||||||
|
|
||||||
|
|
||||||
|
Console.ReadLine();
|
||||||
|
|
||||||
|
bb.Stop();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,7 +44,7 @@ namespace TelegramBotBaseTest.Tests.Controls
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
private async Task Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Button == null)
|
if (e.Button == null)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TelegramBotBase.Args;
|
||||||
|
using TelegramBotBase.Controls;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
|
namespace TelegramBotBaseTest.Tests.Controls
|
||||||
|
{
|
||||||
|
public class ButtonGridPagingForm : AutoCleanForm
|
||||||
|
{
|
||||||
|
|
||||||
|
ButtonGrid m_Buttons = null;
|
||||||
|
|
||||||
|
public ButtonGridPagingForm()
|
||||||
|
{
|
||||||
|
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
||||||
|
|
||||||
|
this.Init += ButtonGridForm_Init;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ButtonGridForm_Init(object sender, InitEventArgs e)
|
||||||
|
{
|
||||||
|
m_Buttons = new ButtonGrid();
|
||||||
|
|
||||||
|
m_Buttons.KeyboardType = TelegramBotBase.Enums.eKeyboardType.ReplyKeyboard;
|
||||||
|
|
||||||
|
m_Buttons.EnablePaging = true;
|
||||||
|
m_Buttons.EnableSearch = true;
|
||||||
|
|
||||||
|
m_Buttons.HeadLayoutButtonRow = new List<ButtonBase>() { new ButtonBase("Back", "back") };
|
||||||
|
|
||||||
|
var countries = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
|
||||||
|
|
||||||
|
ButtonForm bf = new ButtonForm();
|
||||||
|
|
||||||
|
foreach (var c in countries)
|
||||||
|
{
|
||||||
|
bf.AddButtonRow(new ButtonBase(c.EnglishName, c.EnglishName));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Buttons.ButtonsForm = bf;
|
||||||
|
|
||||||
|
m_Buttons.ButtonClicked += Bg_ButtonClicked;
|
||||||
|
|
||||||
|
this.AddControl(m_Buttons);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Button == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (e.Button.Value == "back")
|
||||||
|
{
|
||||||
|
var start = new Menu();
|
||||||
|
await this.NavigateTo(start);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
await this.Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -146,6 +146,16 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
await this.NavigateTo(bg);
|
await this.NavigateTo(bg);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "buttongridfilter":
|
||||||
|
|
||||||
|
message.Handled = true;
|
||||||
|
|
||||||
|
var bg2 = new Controls.ButtonGridPagingForm();
|
||||||
|
|
||||||
|
await this.NavigateTo(bg2);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,6 +185,8 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
btn.AddButtonRow(new ButtonBase("#12 ButtonGrid", new CallbackData("a", "buttongrid").Serialize()));
|
btn.AddButtonRow(new ButtonBase("#12 ButtonGrid", new CallbackData("a", "buttongrid").Serialize()));
|
||||||
|
|
||||||
|
btn.AddButtonRow(new ButtonBase("#13 ButtonGrid Paging & Filter", new CallbackData("a", "buttongridfilter").Serialize()));
|
||||||
|
|
||||||
await this.Device.Send("Choose your test:", btn);
|
await this.Device.Send("Choose your test:", btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
Reference in New Issue
Block a user