Beispiel #1
0
        public async Task HandleMessage(IMessage message)
        {
            var services = BotServices.GetBotServices();

            foreach (var service in services)
            {
                var helpMessage      = "";
                var invokableMethods = service.GetMethodsWithAttribute <OnCommandAttribute>();

                foreach (var method in invokableMethods)
                {
                    var obsoleteAttribute     = method.GetCustomAttribute <ObsoleteAttribute>();
                    var commandAttribute      = method.GetCustomAttribute <OnCommandAttribute>();
                    var descriptionAttribute  = method.GetCustomAttribute <DescriptionAttribute>();
                    var usageAttribute        = method.GetCustomAttribute <CommandUsageAttribute>();
                    var restrictionAttributes = method.GetCustomAttributes <AuthorizeAttribute>();

                    if (obsoleteAttribute != null)
                    {
                        continue;
                    }

                    helpMessage += $"`{commandAttribute.Command}` ";

                    if (restrictionAttributes.Any())
                    {
                        helpMessage += "- 🔒 ";
                    }

                    if (descriptionAttribute != null)
                    {
                        helpMessage += $"- {descriptionAttribute.Description} ";
                    }

                    if (usageAttribute != null)
                    {
                        helpMessage += $"- {usageAttribute.UsageDescription} ";
                    }

                    helpMessage += "\n";
                }

                if (invokableMethods.Any() && !string.IsNullOrWhiteSpace(helpMessage))
                {
                    helpMessage += "\n";
                    await message.Channel.SendMessageAsync(helpMessage);

                    await Task.Delay(50);
                }
            }
        }