diff --git a/Examples/BotAndWebApplication/BotStuff/StartForm.cs b/Examples/BotAndWebApplication/BotStuff/StartForm.cs index dbb2a99..f721ede 100644 --- a/Examples/BotAndWebApplication/BotStuff/StartForm.cs +++ b/Examples/BotAndWebApplication/BotStuff/StartForm.cs @@ -6,7 +6,7 @@ namespace BotAndWebApplication.BotStuff { public class StartForm : FormBase { - ButtonGrid _grid = null; + ButtonGrid? _grid = null; int MyCounter { get; set; } = 0; @@ -34,10 +34,10 @@ namespace BotAndWebApplication.BotStuff AddControl(_grid); } - private async Task _grid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e) + private Task _grid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e) { if (e.Button == null || e.Button.Value == null) - return; + return Task.CompletedTask; switch (e.Button.Value) { @@ -60,6 +60,7 @@ namespace BotAndWebApplication.BotStuff } + return Task.CompletedTask; } } } diff --git a/Examples/InlineAndReplyCombination/Baseclasses/MultipleChoiceForm.cs b/Examples/InlineAndReplyCombination/Baseclasses/MultipleChoiceForm.cs index ace5620..fce1a74 100644 --- a/Examples/InlineAndReplyCombination/Baseclasses/MultipleChoiceForm.cs +++ b/Examples/InlineAndReplyCombination/Baseclasses/MultipleChoiceForm.cs @@ -14,9 +14,9 @@ namespace InlineAndReplyCombination.Baseclasses public class MultipleChoiceForm : AutoCleanForm { [SaveState] - public UserDetails UserDetails { get; set; } + public UserDetails? UserDetails { get; set; } - ButtonGrid ReplyButtonGrid; + ButtonGrid? ReplyButtonGrid; public String ReplyButtonTitle { get; set; } = "Restart"; @@ -28,7 +28,7 @@ namespace InlineAndReplyCombination.Baseclasses this.Init += MultipleChoiceForm_Init; } - private async Task MultipleChoiceForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e) + private Task MultipleChoiceForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e) { //Reply keyboard var bf = new ButtonForm(); @@ -43,6 +43,8 @@ namespace InlineAndReplyCombination.Baseclasses ReplyButtonGrid.ButtonClicked += ReplyButtonGrid_ButtonClicked; AddControl(ReplyButtonGrid); + + return Task.CompletedTask; } diff --git a/Examples/InlineAndReplyCombination/Forms/StartForm.cs b/Examples/InlineAndReplyCombination/Forms/StartForm.cs index 34bf6c0..54ecd8f 100644 --- a/Examples/InlineAndReplyCombination/Forms/StartForm.cs +++ b/Examples/InlineAndReplyCombination/Forms/StartForm.cs @@ -13,7 +13,7 @@ namespace InlineAndReplyCombination.Forms { public class StartForm : AutoCleanForm { - ButtonGrid buttonGrid; + ButtonGrid? buttonGrid; public StartForm() { @@ -21,7 +21,7 @@ namespace InlineAndReplyCombination.Forms } - private async Task StartForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e) + private Task StartForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e) { var bf = new ButtonForm(); @@ -35,6 +35,7 @@ namespace InlineAndReplyCombination.Forms AddControl(buttonGrid); + return Task.CompletedTask; } private async Task ButtonGrid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e) diff --git a/Examples/InlineAndReplyCombination/Forms/Steps/MainForm.cs b/Examples/InlineAndReplyCombination/Forms/Steps/MainForm.cs index c9e5220..fc1d4f3 100644 --- a/Examples/InlineAndReplyCombination/Forms/Steps/MainForm.cs +++ b/Examples/InlineAndReplyCombination/Forms/Steps/MainForm.cs @@ -15,9 +15,9 @@ namespace InlineAndReplyCombination.Forms.Steps public class MainForm : MultipleChoiceForm { - ButtonGrid InlineButtonGrid; + ButtonGrid? InlineButtonGrid; - public static List> AllowedInlineInputs = null; + public static List> AllowedInlineInputs; static MainForm() { @@ -41,7 +41,7 @@ namespace InlineAndReplyCombination.Forms.Steps CurrentStep = 1; } - private async Task MainForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e) + private Task MainForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e) { //Inline Keyboard @@ -61,6 +61,7 @@ namespace InlineAndReplyCombination.Forms.Steps AddControl(InlineButtonGrid); + return Task.CompletedTask; } private async Task InlineButtonGrid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e) @@ -72,7 +73,12 @@ namespace InlineAndReplyCombination.Forms.Steps return; } - this.UserDetails.AgeRange = e.Button?.Value ?? "unknown"; + if (UserDetails == null) + { + return; + } + + UserDetails.AgeRange = e.Button?.Value ?? "unknown"; var sf = new SecondForm(); diff --git a/Examples/InlineAndReplyCombination/Forms/Steps/SecondForm.cs b/Examples/InlineAndReplyCombination/Forms/Steps/SecondForm.cs index 862f84e..8c9fd7a 100644 --- a/Examples/InlineAndReplyCombination/Forms/Steps/SecondForm.cs +++ b/Examples/InlineAndReplyCombination/Forms/Steps/SecondForm.cs @@ -15,9 +15,9 @@ namespace InlineAndReplyCombination.Forms.Steps public class SecondForm : MultipleChoiceForm { - ButtonGrid InlineButtonGrid; + ButtonGrid? InlineButtonGrid; - public static List> AllowedInlineInputs = null; + public static List> AllowedInlineInputs; static SecondForm() { @@ -42,7 +42,7 @@ namespace InlineAndReplyCombination.Forms.Steps } - private async Task SecondForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e) + private Task SecondForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e) { //Inline Keyboard @@ -60,6 +60,7 @@ namespace InlineAndReplyCombination.Forms.Steps AddControl(InlineButtonGrid); + return Task.CompletedTask; } private async Task InlineButtonGrid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e) @@ -71,7 +72,12 @@ namespace InlineAndReplyCombination.Forms.Steps return; } - this.UserDetails.FavouriteColor = e.Button?.Value ?? "unknown"; + if (UserDetails == null) + { + return; + } + + UserDetails.FavouriteColor = e.Button?.Value ?? "unknown"; var tf = new ThirdForm(); diff --git a/Examples/InlineAndReplyCombination/Forms/Steps/Summary.cs b/Examples/InlineAndReplyCombination/Forms/Steps/Summary.cs index 9a601cc..9e4ffe4 100644 --- a/Examples/InlineAndReplyCombination/Forms/Steps/Summary.cs +++ b/Examples/InlineAndReplyCombination/Forms/Steps/Summary.cs @@ -14,9 +14,9 @@ namespace InlineAndReplyCombination.Forms.Steps public class Summary : AutoCleanForm { [SaveState] - public UserDetails UserDetails { get; set; } + public UserDetails? UserDetails { get; set; } - ButtonGrid ReplyButtonGrid { get; set; } + ButtonGrid? ReplyButtonGrid { get; set; } public Summary() { @@ -24,7 +24,7 @@ namespace InlineAndReplyCombination.Forms.Steps } - private async Task Summary_Init(object sender, TelegramBotBase.Args.InitEventArgs e) + private Task Summary_Init(object sender, TelegramBotBase.Args.InitEventArgs e) { var bf = new ButtonForm(); @@ -39,6 +39,7 @@ namespace InlineAndReplyCombination.Forms.Steps AddControl(ReplyButtonGrid); + return Task.CompletedTask; } public override async Task Load(MessageResult message) diff --git a/Examples/InlineAndReplyCombination/Forms/Steps/ThirdForm.cs b/Examples/InlineAndReplyCombination/Forms/Steps/ThirdForm.cs index 5382db7..043b744 100644 --- a/Examples/InlineAndReplyCombination/Forms/Steps/ThirdForm.cs +++ b/Examples/InlineAndReplyCombination/Forms/Steps/ThirdForm.cs @@ -15,9 +15,9 @@ namespace InlineAndReplyCombination.Forms.Steps public class ThirdForm : MultipleChoiceForm { - ButtonGrid InlineButtonGrid; + ButtonGrid? InlineButtonGrid; - public static List> AllowedInlineInputs = null; + public static List> AllowedInlineInputs; static ThirdForm() { @@ -41,7 +41,7 @@ namespace InlineAndReplyCombination.Forms.Steps } - private async Task SecondForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e) + private Task SecondForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e) { //Inline Keyboard @@ -59,6 +59,7 @@ namespace InlineAndReplyCombination.Forms.Steps AddControl(InlineButtonGrid); + return Task.CompletedTask; } private async Task InlineButtonGrid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e) @@ -70,7 +71,12 @@ namespace InlineAndReplyCombination.Forms.Steps return; } - this.UserDetails.FavouriteCity = e.Button?.Value ?? "unknown"; + if (UserDetails == null) + { + return; + } + + UserDetails.FavouriteCity = e.Button?.Value ?? "unknown"; var sum = new Summary(); sum.UserDetails = this.UserDetails; diff --git a/Examples/InlineAndReplyCombination/Model/UserDetails.cs b/Examples/InlineAndReplyCombination/Model/UserDetails.cs index a3b410e..fc5409b 100644 --- a/Examples/InlineAndReplyCombination/Model/UserDetails.cs +++ b/Examples/InlineAndReplyCombination/Model/UserDetails.cs @@ -10,11 +10,11 @@ namespace InlineAndReplyCombination.Model [DebuggerDisplay("{AgeRange}, {FavouriteColor}, {FavouriteCity}")] public class UserDetails { - public String AgeRange { get; set; } + public String? AgeRange { get; set; } - public String FavouriteColor { get; set; } + public String? FavouriteColor { get; set; } - public String FavouriteCity { get; set; } + public String? FavouriteCity { get; set; } } } diff --git a/Examples/InlineAndReplyCombination/Program.cs b/Examples/InlineAndReplyCombination/Program.cs index 5e4e4fe..00372c7 100644 --- a/Examples/InlineAndReplyCombination/Program.cs +++ b/Examples/InlineAndReplyCombination/Program.cs @@ -6,7 +6,7 @@ namespace InlineAndReplyCombination { internal class Program { - public static BotBase BotBaseInstance { get; private set; } + public static BotBase? BotBaseInstance { get; private set; } static async Task Main(string[] args) {