mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Support for commands without a prefix using new attribute NoPrefixRequired
This commit is contained in:
@@ -47,14 +47,11 @@ internal class BotCommands
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!message.MessageRaw.StartsWith(CommandPrefix))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var messageTrimmed = message.MessageRaw.TrimStart(CommandPrefix);
|
var messageTrimmed = message.MessageRaw.TrimStart(CommandPrefix);
|
||||||
foreach (var command in Commands)
|
foreach (var command in Commands)
|
||||||
{
|
{
|
||||||
|
var noPrefixCommand = HasAttribute<NoPrefixRequired>(command);
|
||||||
|
if (!noPrefixCommand && !message.MessageRaw.StartsWith(CommandPrefix)) return;
|
||||||
foreach (var regex in command.Patterns)
|
foreach (var regex in command.Patterns)
|
||||||
{
|
{
|
||||||
var match = regex.Match(messageTrimmed);
|
var match = regex.Match(messageTrimmed);
|
||||||
@@ -253,3 +250,9 @@ internal class WagerCommand : Attribute;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[AttributeUsage(AttributeTargets.Class)]
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
internal class KasinoCommand : Attribute;
|
internal class KasinoCommand : Attribute;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Use this on commands where the Regex should be tested even if there's no command prefix
|
||||||
|
/// </summary>
|
||||||
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
internal class NoPrefixRequired : Attribute;
|
||||||
Reference in New Issue
Block a user