From fd9d4c73c956c1ea678f4407b486801517ebf486 Mon Sep 17 00:00:00 2001 From: lifyxus Date: Sat, 8 Oct 2022 16:35:44 +0300 Subject: [PATCH] fix: ref -> out --- .../Extensions/MessageExtensions.cs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Discord.Net.Commands/Extensions/MessageExtensions.cs b/src/Discord.Net.Commands/Extensions/MessageExtensions.cs index 9aa83d418..b12c7e23d 100644 --- a/src/Discord.Net.Commands/Extensions/MessageExtensions.cs +++ b/src/Discord.Net.Commands/Extensions/MessageExtensions.cs @@ -16,35 +16,44 @@ namespace Discord.Commands /// /// true if the message begins with the char ; otherwise false. /// - public static bool HasCharPrefix(this IUserMessage msg, char c, ref int argPos) + public static bool HasCharPrefix(this IUserMessage msg, char c, out int argPos) { - var text = msg.Content; + string text = msg.Content; + if (!string.IsNullOrEmpty(text) && text[0] == c) { argPos = 1; return true; } + + argPos = -1; return false; } + /// /// Gets whether the message starts with the provided string. /// - public static bool HasStringPrefix(this IUserMessage msg, string str, ref int argPos, StringComparison comparisonType = StringComparison.Ordinal) + public static bool HasStringPrefix(this IUserMessage msg, string str, out int argPos, StringComparison comparisonType = StringComparison.Ordinal) { - var text = msg.Content; + string text = msg.Content; + if (!string.IsNullOrEmpty(text) && text.StartsWith(str, comparisonType)) { argPos = str.Length; return true; } + + argPos = -1; return false; } + /// /// Gets whether the message starts with the user's mention string. /// - public static bool HasMentionPrefix(this IUserMessage msg, IUser user, ref int argPos) + public static bool HasMentionPrefix(this IUserMessage msg, IUser user, out int argPos) { - var text = msg.Content; + string text = msg.Content; + argPos = -1; if (string.IsNullOrEmpty(text) || text.Length <= 3 || text[0] != '<' || text[1] != '@') return false; int endPos = text.IndexOf('>');