-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from MajMcCloud/development
Integrate development branch into master
- Loading branch information
Showing
37 changed files
with
1,038 additions
and
71 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
Examples/InlineAndReplyCombination/Baseclasses/MultipleChoiceForm.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using InlineAndReplyCombination.Forms; | ||
using InlineAndReplyCombination.Model; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using TelegramBotBase.Attributes; | ||
using TelegramBotBase.Controls.Hybrid; | ||
using TelegramBotBase.Form; | ||
|
||
namespace InlineAndReplyCombination.Baseclasses | ||
{ | ||
public class MultipleChoiceForm : AutoCleanForm | ||
{ | ||
[SaveState] | ||
public UserDetails? UserDetails { get; set; } | ||
|
||
ButtonGrid? ReplyButtonGrid; | ||
|
||
public String ReplyButtonTitle { get; set; } = "Restart"; | ||
|
||
protected int CurrentStep = 1; | ||
protected int MaxSteps = 3; | ||
|
||
public MultipleChoiceForm() | ||
{ | ||
this.Init += MultipleChoiceForm_Init; | ||
} | ||
|
||
private Task MultipleChoiceForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e) | ||
{ | ||
//Reply keyboard | ||
var bf = new ButtonForm(); | ||
|
||
bf.AddButtonRow(ReplyButtonTitle, "replyButtonID"); | ||
|
||
ReplyButtonGrid = new ButtonGrid(bf); | ||
|
||
ReplyButtonGrid.Title = $"Step {CurrentStep} / {MaxSteps}"; | ||
ReplyButtonGrid.KeyboardType = TelegramBotBase.Enums.EKeyboardType.ReplyKeyboard; | ||
|
||
ReplyButtonGrid.ButtonClicked += ReplyButtonGrid_ButtonClicked; | ||
|
||
AddControl(ReplyButtonGrid); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
|
||
private async Task ReplyButtonGrid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e) | ||
{ | ||
if (e.Button == null) | ||
return; | ||
|
||
switch (e.Button.Value) | ||
{ | ||
case "replyButtonID": | ||
|
||
await PressReplyButton(); | ||
|
||
|
||
break; | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
public virtual Task PressReplyButton() | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
public override Task NavigateTo(FormBase newForm, params object[] args) | ||
{ | ||
//Move user details over to navigating form | ||
if (newForm is MultipleChoiceForm mcf) | ||
{ | ||
mcf.UserDetails = UserDetails; | ||
} | ||
|
||
return base.NavigateTo(newForm, args); | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using InlineAndReplyCombination.Baseclasses; | ||
using InlineAndReplyCombination.Forms.Steps; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using TelegramBotBase.Base; | ||
using TelegramBotBase.Controls.Hybrid; | ||
using TelegramBotBase.Form; | ||
|
||
namespace InlineAndReplyCombination.Forms | ||
{ | ||
public class StartForm : AutoCleanForm | ||
{ | ||
ButtonGrid? buttonGrid; | ||
|
||
public StartForm() | ||
{ | ||
this.Init += StartForm_Init; | ||
|
||
} | ||
|
||
private Task StartForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e) | ||
{ | ||
var bf = new ButtonForm(); | ||
|
||
bf.AddButtonRow("Start registration", "start"); | ||
|
||
buttonGrid = new ButtonGrid(bf); | ||
|
||
buttonGrid.Title = "Welcome to The InlineAndReplyCombination Bot!"; | ||
buttonGrid.ButtonClicked += ButtonGrid_ButtonClicked; | ||
buttonGrid.KeyboardType = TelegramBotBase.Enums.EKeyboardType.ReplyKeyboard; | ||
|
||
AddControl(buttonGrid); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private async Task ButtonGrid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e) | ||
{ | ||
if(e.Button == null) | ||
{ | ||
return; | ||
} | ||
|
||
|
||
switch(e.Button.Value) | ||
{ | ||
case "start": | ||
|
||
var mf = new MainForm(); | ||
|
||
mf.UserDetails = new Model.UserDetails(); | ||
|
||
await NavigateTo(mf); | ||
|
||
break; | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
Examples/InlineAndReplyCombination/Forms/Steps/MainForm.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using InlineAndReplyCombination.Baseclasses; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Numerics; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Telegram.Bot.Types; | ||
using TelegramBotBase.Base; | ||
using TelegramBotBase.Controls.Hybrid; | ||
using TelegramBotBase.Form; | ||
|
||
namespace InlineAndReplyCombination.Forms.Steps | ||
{ | ||
public class MainForm : MultipleChoiceForm | ||
{ | ||
|
||
ButtonGrid? InlineButtonGrid; | ||
|
||
public static List<Tuple<String, String>> AllowedInlineInputs; | ||
|
||
static MainForm() | ||
{ | ||
AllowedInlineInputs = new List<Tuple<string, string>>() | ||
{ | ||
new("< 18", "<18"), | ||
new("18 to 25", "18t25"), | ||
new("25 to 35", "25t35"), | ||
new("35 to 50", "35t50"), | ||
new("over 50", "o50") | ||
}; | ||
|
||
} | ||
|
||
public MainForm() | ||
{ | ||
|
||
Init += MainForm_Init; | ||
|
||
ReplyButtonTitle = "Start over"; | ||
CurrentStep = 1; | ||
} | ||
|
||
private Task MainForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e) | ||
{ | ||
|
||
//Inline Keyboard | ||
var bf_ages = new ButtonForm(); | ||
|
||
//Add all options in a single column | ||
bf_ages.AddSplitted(AllowedInlineInputs.Select(a => new ButtonBase(a.Item1, a.Item2)), 1); | ||
|
||
bf_ages.AddButtonRow("Some invalid input", "Invalid"); | ||
|
||
InlineButtonGrid = new ButtonGrid(bf_ages); | ||
InlineButtonGrid.ConfirmationText = "Thank you"; | ||
InlineButtonGrid.Title = "Please choose your age:"; | ||
InlineButtonGrid.ButtonClicked += InlineButtonGrid_ButtonClicked; | ||
|
||
InlineButtonGrid.KeyboardType = TelegramBotBase.Enums.EKeyboardType.InlineKeyBoard; | ||
|
||
AddControl(InlineButtonGrid); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private async Task InlineButtonGrid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e) | ||
{ | ||
//Not found | ||
if (!AllowedInlineInputs.Any(a => a.Item2 == e.Button.Value)) | ||
{ | ||
await Device.Send("Invalid input!"); | ||
return; | ||
} | ||
|
||
if (UserDetails == null) | ||
{ | ||
return; | ||
} | ||
|
||
UserDetails.AgeRange = e.Button?.Value ?? "unknown"; | ||
|
||
var sf = new SecondForm(); | ||
|
||
await NavigateTo(sf); | ||
} | ||
|
||
|
||
public override async Task PressReplyButton() | ||
{ | ||
var sf = new StartForm(); | ||
|
||
await NavigateTo(sf); | ||
} | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
Examples/InlineAndReplyCombination/Forms/Steps/SecondForm.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using InlineAndReplyCombination.Baseclasses; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Numerics; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Telegram.Bot.Types; | ||
using TelegramBotBase.Base; | ||
using TelegramBotBase.Controls.Hybrid; | ||
using TelegramBotBase.Form; | ||
|
||
namespace InlineAndReplyCombination.Forms.Steps | ||
{ | ||
public class SecondForm : MultipleChoiceForm | ||
{ | ||
|
||
ButtonGrid? InlineButtonGrid; | ||
|
||
public static List<Tuple<String, String>> AllowedInlineInputs; | ||
|
||
static SecondForm() | ||
{ | ||
AllowedInlineInputs = new List<Tuple<string, string>>() | ||
{ | ||
new("Green", "green"), | ||
new("Yellow", "yellow"), | ||
new("Red", "red"), | ||
new("Purple", "purple"), | ||
new("Black", "black"), | ||
new("Gold", "gold") | ||
}; | ||
} | ||
|
||
public SecondForm() | ||
{ | ||
|
||
Init += SecondForm_Init; | ||
|
||
ReplyButtonTitle = "Go back"; | ||
CurrentStep = 2; | ||
|
||
} | ||
|
||
private Task SecondForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e) | ||
{ | ||
|
||
//Inline Keyboard | ||
var bf_ages = new ButtonForm(); | ||
|
||
//Add all options in a single column | ||
bf_ages.AddSplitted(AllowedInlineInputs.Select(a => new ButtonBase(a.Item1, a.Item2)), 1); | ||
|
||
InlineButtonGrid = new ButtonGrid(bf_ages); | ||
InlineButtonGrid.ConfirmationText = "Thank you"; | ||
InlineButtonGrid.Title = "Please choose your favourite color:"; | ||
InlineButtonGrid.ButtonClicked += InlineButtonGrid_ButtonClicked; | ||
|
||
InlineButtonGrid.KeyboardType = TelegramBotBase.Enums.EKeyboardType.InlineKeyBoard; | ||
|
||
AddControl(InlineButtonGrid); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private async Task InlineButtonGrid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e) | ||
{ | ||
//Not found | ||
if (!AllowedInlineInputs.Any(a => a.Item2 == e.Button.Value)) | ||
{ | ||
await Device.Send("Invalid input!"); | ||
return; | ||
} | ||
|
||
if (UserDetails == null) | ||
{ | ||
return; | ||
} | ||
|
||
UserDetails.FavouriteColor = e.Button?.Value ?? "unknown"; | ||
|
||
var tf = new ThirdForm(); | ||
|
||
await NavigateTo(tf); | ||
} | ||
|
||
|
||
public override async Task PressReplyButton() | ||
{ | ||
var mf = new MainForm(); | ||
|
||
await NavigateTo(mf); | ||
} | ||
} | ||
} |
Oops, something went wrong.