/// <param name="requirePrefix">Prefix requirement for this command.</param> public PrefixAttribute(PrefixRequirement requirePrefix) : this(null, requirePrefix) { }
/// <summary>Sets prefix requirement.</summary> /// <param name="builder">Hosted Commands Service builder.</param> /// <param name="requirement">Prefix requirement.</param> /// <seealso cref="CommandsOptions.RequirePrefix"/> public static IHostedCommandsServiceBuilder SetPrefixRequirement(this IHostedCommandsServiceBuilder builder, PrefixRequirement requirement) => builder.Configure(options => options.RequirePrefix = requirement);
/// <summary>Checks if the message matches prefix requirements for command processing.</summary> /// <param name="message">Message to check.</param> /// <param name="prefix">Prefix.</param> /// <param name="requirement">Prefix requirement to check.</param> /// <param name="caseSensitive">Whether the check should be performed case-sensitively.</param> /// <param name="startIndex">Index of start of actual command message, without prefix.</param> /// <returns>True if the message matches prefix requirement; otherwise false.</returns> public static bool MatchesPrefixRequirement(this ChatMessage message, string prefix, PrefixRequirement requirement, bool caseSensitive, out int startIndex) { StringComparison comparison = caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; bool startsWithPrefix = message.Text.StartsWith(prefix, comparison); startIndex = startsWithPrefix ? prefix.Length : 0; // if it does start with prefix, we know for sure it matches requirement if (startsWithPrefix) { return(true); } // now we know it does NOT start with prefix // so let's check if prefix is required in group messages if the message is in group... if (message.IsGroupMessage && (requirement & PrefixRequirement.Group) == PrefixRequirement.Group) { return(false); } // ... or in private messages if the message is in group if (message.IsPrivateMessage && (requirement & PrefixRequirement.Private) == PrefixRequirement.Private) { return(false); } // if we got here, we know that the prefix is not required return(true); }
// general /// <summary>Sets prefix and prefix requirement.</summary> /// <param name="builder">Hosted Commands Service builder.</param> /// <param name="prefix">Prefix value.</param> /// <param name="requirement">Prefix requirement.</param> /// <seealso cref="CommandsOptions.Prefix"/> /// <seealso cref="CommandsOptions.RequirePrefix"/> public static IHostedCommandsServiceBuilder SetPrefix(this IHostedCommandsServiceBuilder builder, string prefix, PrefixRequirement requirement) => builder.SetPrefix(prefix).SetPrefixRequirement(requirement);