From deb886066bcb4a4bf0c01b93af30bc5e0ddfbc22 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Wed, 14 Oct 2020 14:24:53 +0200 Subject: [PATCH] Misc --- ArchiSteamFarm/Commands.cs | 4 ++-- ArchiSteamFarm/IPC/Controllers/Api/CommandController.cs | 7 ++++--- ArchiSteamFarm/NLog/Logging.cs | 7 ++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ArchiSteamFarm/Commands.cs b/ArchiSteamFarm/Commands.cs index 9451a3ba2..13c828405 100644 --- a/ArchiSteamFarm/Commands.cs +++ b/ArchiSteamFarm/Commands.cs @@ -294,7 +294,7 @@ namespace ArchiSteamFarm { string? commandPrefix = ASF.GlobalConfig != null ? ASF.GlobalConfig.CommandPrefix : GlobalConfig.DefaultCommandPrefix; if (!string.IsNullOrEmpty(commandPrefix)) { - if (!message.StartsWith(commandPrefix!, StringComparison.OrdinalIgnoreCase)) { + if (!message.StartsWith(commandPrefix!, StringComparison.Ordinal)) { string? pluginsResponse = await PluginsCore.OnBotMessage(Bot, steamID, message).ConfigureAwait(false); if (!string.IsNullOrEmpty(pluginsResponse)) { @@ -356,7 +356,7 @@ namespace ArchiSteamFarm { string? commandPrefix = ASF.GlobalConfig != null ? ASF.GlobalConfig.CommandPrefix : GlobalConfig.DefaultCommandPrefix; if (!string.IsNullOrEmpty(commandPrefix)) { - if (!message.StartsWith(commandPrefix!, StringComparison.OrdinalIgnoreCase)) { + if (!message.StartsWith(commandPrefix!, StringComparison.Ordinal)) { string? pluginsResponse = await PluginsCore.OnBotMessage(Bot, steamID, message).ConfigureAwait(false); if (!string.IsNullOrEmpty(pluginsResponse)) { diff --git a/ArchiSteamFarm/IPC/Controllers/Api/CommandController.cs b/ArchiSteamFarm/IPC/Controllers/Api/CommandController.cs index 9c24c273a..b6eb69b0e 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/CommandController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/CommandController.cs @@ -67,11 +67,12 @@ namespace ArchiSteamFarm.IPC.Controllers.Api { string? commandPrefix = ASF.GlobalConfig != null ? ASF.GlobalConfig.CommandPrefix : GlobalConfig.DefaultCommandPrefix; if (!string.IsNullOrEmpty(commandPrefix) && command.StartsWith(commandPrefix!, StringComparison.Ordinal)) { - command = command.Substring(commandPrefix!.Length); - - if (string.IsNullOrEmpty(command)) { + if (command.Length == commandPrefix!.Length) { + // If the message starts with command prefix and is of the same length as command prefix, then it's just empty command trigger, useless return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(command)))); } + + command = command.Substring(commandPrefix!.Length); } string? response = await targetBot.Commands.Response(steamOwnerID, command).ConfigureAwait(false); diff --git a/ArchiSteamFarm/NLog/Logging.cs b/ArchiSteamFarm/NLog/Logging.cs index 67c5869b8..4664281e4 100644 --- a/ArchiSteamFarm/NLog/Logging.cs +++ b/ArchiSteamFarm/NLog/Logging.cs @@ -286,11 +286,12 @@ namespace ArchiSteamFarm.NLog { string? commandPrefix = ASF.GlobalConfig != null ? ASF.GlobalConfig.CommandPrefix : GlobalConfig.DefaultCommandPrefix; if (!string.IsNullOrEmpty(commandPrefix) && command!.StartsWith(commandPrefix!, StringComparison.Ordinal)) { - command = command.Substring(commandPrefix!.Length); - - if (string.IsNullOrEmpty(command)) { + if (command.Length == commandPrefix!.Length) { + // If the message starts with command prefix and is of the same length as command prefix, then it's just empty command trigger, useless continue; } + + command = command.Substring(commandPrefix!.Length); } Bot? targetBot = Bot.Bots?.OrderBy(bot => bot.Key, Bot.BotsComparer).Select(bot => bot.Value).FirstOrDefault();