From ea971979e26e9b3d3d24f8e413b254afb10dcf4e Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sat, 4 May 2019 18:59:05 +0200 Subject: [PATCH] - Added comments - added Edit method --- TelegramBotBase/Form/AutoCleanForm.cs | 18 ++++++++++ TelegramBotBase/Sessions/DeviceSession.cs | 41 ++++++++++++++++++++--- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/TelegramBotBase/Form/AutoCleanForm.cs b/TelegramBotBase/Form/AutoCleanForm.cs index 18c32d1..099a057 100644 --- a/TelegramBotBase/Form/AutoCleanForm.cs +++ b/TelegramBotBase/Form/AutoCleanForm.cs @@ -21,15 +21,33 @@ namespace TelegramBotBase.Form public enum eDeleteMode { + /// + /// Don't delete any message. + /// None = 0, + /// + /// Delete messages on every callback/action. + /// OnEveryCall = 1, + /// + /// Delete on leaving this form. + /// OnLeavingForm = 2 } public enum eSide { + /// + /// Delete only messages from this bot. + /// BotOnly = 0, + /// + /// Delete only user messages. + /// UserOnly = 1, + /// + /// Delete all messages in this context. + /// Both = 2 } diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index aac08a4..6453010 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -83,7 +83,7 @@ namespace TelegramBotBase.Sessions } } - public EventHandlerList __Events = new EventHandlerList(); + private EventHandlerList __Events = new EventHandlerList(); private static object __evMessageSent = new object(); private static object __evMessageReceived = new object(); @@ -138,6 +138,39 @@ namespace TelegramBotBase.Sessions return null; } + /// + /// Edits the text message + /// + /// + /// + /// + /// + public async Task Edit(Message message, ButtonForm buttons = null) + { + if (this.ActiveForm == null) + return null; + + InlineKeyboardMarkup markup = null; + if (buttons != null) + { + markup = buttons; + } + + try + { + var m = await this.Client.TelegramClient.EditMessageTextAsync(this.DeviceId, message.MessageId, message.Text, replyMarkup: markup); + + return m; + } + catch + { + + } + + + return null; + } + /// /// Sends a simple text message /// @@ -163,7 +196,7 @@ namespace TelegramBotBase.Sessions { m = await (this.Client.TelegramClient.SendTextMessageAsync(this.DeviceId, text, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification)); - OnMessageSent(new MessageSentEventArgs( m)); + OnMessageSent(new MessageSentEventArgs(m)); } catch (ApiRequestException ex) { @@ -330,7 +363,7 @@ namespace TelegramBotBase.Sessions } var m = await this.Client.TelegramClient.SendDocumentAsync(this.DeviceId, document, caption, replyMarkup: markup, disableNotification: disableNotification, replyToMessageId: replyTo); - + OnMessageSent(new MessageSentEventArgs(m)); return m; @@ -384,7 +417,7 @@ namespace TelegramBotBase.Sessions try { await this.Client.TelegramClient.DeleteMessageAsync(this.DeviceId, messageId); - + return true; } catch (ApiRequestException ex)