From 9400cfc74ef88cfa0af0bead03cd124a96a81515 Mon Sep 17 00:00:00 2001 From: ZavaruKitsu Date: Sat, 15 Oct 2022 21:59:12 +0300 Subject: [PATCH] refactor: rename MaxLengthException & fix naming --- .../DataSources/ButtonFormDataSource.cs | 10 +++++----- TelegramBotBase/Exceptions/MaxLengthException.cs | 11 ----------- .../Exceptions/MaximumColsException.cs | 8 +++----- .../Exceptions/MaximumRowsException.cs | 6 +++--- .../Exceptions/MessageTooLongException.cs | 16 ++++++++++++++++ TelegramBotBase/Sessions/DeviceSession.cs | 12 ++++++------ 6 files changed, 33 insertions(+), 30 deletions(-) delete mode 100644 TelegramBotBase/Exceptions/MaxLengthException.cs create mode 100644 TelegramBotBase/Exceptions/MessageTooLongException.cs diff --git a/TelegramBotBase/DataSources/ButtonFormDataSource.cs b/TelegramBotBase/DataSources/ButtonFormDataSource.cs index e91668c..c92a55a 100644 --- a/TelegramBotBase/DataSources/ButtonFormDataSource.cs +++ b/TelegramBotBase/DataSources/ButtonFormDataSource.cs @@ -8,22 +8,22 @@ namespace TelegramBotBase.DataSources; public class ButtonFormDataSource : IDataSource { - private ButtonForm _buttonform; + private ButtonForm _buttonForm; public ButtonFormDataSource() { - _buttonform = new ButtonForm(); + _buttonForm = new ButtonForm(); } public ButtonFormDataSource(ButtonForm bf) { - _buttonform = bf; + _buttonForm = bf; } public virtual ButtonForm ButtonForm { - get => _buttonform; - set => _buttonform = value; + get => _buttonForm; + set => _buttonForm = value; } diff --git a/TelegramBotBase/Exceptions/MaxLengthException.cs b/TelegramBotBase/Exceptions/MaxLengthException.cs deleted file mode 100644 index 2e93214..0000000 --- a/TelegramBotBase/Exceptions/MaxLengthException.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace TelegramBotBase.Exceptions; - -public class MaxLengthException : Exception -{ - public MaxLengthException(int length) : base( - $"Your messages with a length of {length} is too long for telegram. Actually is {Constants.Telegram.MaxMessageLength} characters allowed. Please split it.") - { - } -} \ No newline at end of file diff --git a/TelegramBotBase/Exceptions/MaximumColsException.cs b/TelegramBotBase/Exceptions/MaximumColsException.cs index 4209353..781ab40 100644 --- a/TelegramBotBase/Exceptions/MaximumColsException.cs +++ b/TelegramBotBase/Exceptions/MaximumColsException.cs @@ -2,13 +2,11 @@ namespace TelegramBotBase.Exceptions; -public class MaximumColsException : Exception +public sealed class MaximumColsException : Exception { public int Value { get; set; } - public int Maximum { get; set; } - public override string Message => - $"You have exceeded the maximum of columns by {Value.ToString()} / {Maximum.ToString()}"; -} \ No newline at end of file + $"You have exceeded the maximum of columns by {Value}/{Maximum}"; +} diff --git a/TelegramBotBase/Exceptions/MaximumRowsException.cs b/TelegramBotBase/Exceptions/MaximumRowsException.cs index be3ad7d..9b1beb8 100644 --- a/TelegramBotBase/Exceptions/MaximumRowsException.cs +++ b/TelegramBotBase/Exceptions/MaximumRowsException.cs @@ -2,7 +2,7 @@ namespace TelegramBotBase.Exceptions; -public class MaximumRowsReachedException : Exception +public sealed class MaximumRowsReachedException : Exception { public int Value { get; set; } @@ -10,5 +10,5 @@ public class MaximumRowsReachedException : Exception public override string Message => - $"You have exceeded the maximum of rows by {Value.ToString()} / {Maximum.ToString()}"; -} \ No newline at end of file + $"You have exceeded the maximum of rows by {Value}/{Maximum}"; +} diff --git a/TelegramBotBase/Exceptions/MessageTooLongException.cs b/TelegramBotBase/Exceptions/MessageTooLongException.cs new file mode 100644 index 0000000..44626db --- /dev/null +++ b/TelegramBotBase/Exceptions/MessageTooLongException.cs @@ -0,0 +1,16 @@ +using System; + +namespace TelegramBotBase.Exceptions; + +public sealed class MessageTooLongException : Exception +{ + public MessageTooLongException(int length) + { + Length = length; + } + + public int Length { get; set; } + + public override string Message => + $"You have exceeded the maximum of message length by {Length}/{Constants.Telegram.MaxMessageLength}"; +} diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index 5da18ab..f823c59 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -155,7 +155,7 @@ public class DeviceSession : IDeviceSession if (text.Length > Constants.Telegram.MaxMessageLength) { - throw new MaxLengthException(text.Length); + throw new MessageTooLongException(text.Length); } try @@ -183,7 +183,7 @@ public class DeviceSession : IDeviceSession { if (text.Length > Constants.Telegram.MaxMessageLength) { - throw new MaxLengthException(text.Length); + throw new MessageTooLongException(text.Length); } try @@ -213,7 +213,7 @@ public class DeviceSession : IDeviceSession if (message.Text.Length > Constants.Telegram.MaxMessageLength) { - throw new MaxLengthException(message.Text.Length); + throw new MessageTooLongException(message.Text.Length); } try @@ -270,7 +270,7 @@ public class DeviceSession : IDeviceSession if (text.Length > Constants.Telegram.MaxMessageLength) { - throw new MaxLengthException(text.Length); + throw new MessageTooLongException(text.Length); } if (parseMode == ParseMode.MarkdownV2 && markdownV2AutoEscape) @@ -329,7 +329,7 @@ public class DeviceSession : IDeviceSession if (text.Length > Constants.Telegram.MaxMessageLength) { - throw new MaxLengthException(text.Length); + throw new MessageTooLongException(text.Length); } if (parseMode == ParseMode.MarkdownV2 && markdownV2AutoEscape) @@ -372,7 +372,7 @@ public class DeviceSession : IDeviceSession if (text.Length > Constants.Telegram.MaxMessageLength) { - throw new MaxLengthException(text.Length); + throw new MessageTooLongException(text.Length); } if (parseMode == ParseMode.MarkdownV2 && markdownV2AutoEscape)