From 28d70f3489fac83a691d635b91cfcf7996a9a795 Mon Sep 17 00:00:00 2001 From: devsdocs <73208025+devsdocs@users.noreply.github.com> Date: Thu, 6 Jul 2023 13:51:28 +0900 Subject: [PATCH] Typesafe for args --- lib/src/televerse/context/message.dart | 2 +- lib/src/utils/utils.dart | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/televerse/context/message.dart b/lib/src/televerse/context/message.dart index 5e7443ba..eae6f677 100644 --- a/lib/src/televerse/context/message.dart +++ b/lib/src/televerse/context/message.dart @@ -55,6 +55,6 @@ class MessageContext extends Context with MessageMixin, ManagementMixin { List get args { if (!(message.text?.startsWith('/') ?? false)) return []; - return message.text!.split(' ').sublist(1); + return message.text!.clean.split(' ').sublist(1); } } diff --git a/lib/src/utils/utils.dart b/lib/src/utils/utils.dart index 7486e286..c7cbdf59 100644 --- a/lib/src/utils/utils.dart +++ b/lib/src/utils/utils.dart @@ -5,3 +5,9 @@ extension Filename on io.File { /// The filename of this file. String get filename => path.split('/').last; } + +/// [String] extension, to clean the [String] +extension CleanString on String { + /// Typesafe for args, replace all white space or multiple space in [String] into single space + String get clean => trim().replaceAll(RegExp(r'\s{2,}|[\t\r\n]'), ' '); +}