Exemplo n.º 1
0
        public async Task SetPrefixAsync(CommandContext context, [Description("PrefixParameter")][RemainingText] string prefix)
        {
            if (prefix == null)
            {
                throw new ArgumentException();
            }

            DiscordEmbedBuilder builder = new DiscordEmbedBuilder()
            {
                Color = new DiscordColor(ColorConstant.embedColor)
            };

            if (context.Channel.IsPrivate)
            {
                builder.Title = "This command can only be used in a guild.";
                await context.Channel.SendMessageAsync(embed : builder.Build());

                return;
            }

            GuildsModel guild = await new GuildsDAO().GetAsync(new GuildsModel {
                ID = context.Guild.Id
            });

            Locale locale = new LocaleExtension().GetLocale(guild);

            if (!prefix.Contains('`'))
            {
                if (prefix.Length <= 10)
                {
                    await new GuildsDAO().SetAsync(new GuildsModel {
                        ID     = context.Guild.Id,
                        Prefix = prefix
                    });
                    builder.Title = (await new StringsDAO().LoadAsync(new StringsModel {
                        Locale = locale,
                        Identifier = "PrefixUpdated".Replace("$prefix", prefix)
                    })).String.Replace("$prefix", prefix);
                }
                else
                {
                    builder.Title = (await new StringsDAO().LoadAsync(new StringsModel {
                        Locale = locale,
                        Identifier = "InvalidPrefixSize"
                    })).String;
                    await context.Channel.SendMessageAsync(embed : await new CommandUseExtension().GetCommandUseAsync(builder, context.Command, locale, new PrefixExtension().GetPrefix(guild)));
                }
            }
            else
            {
                builder.Title = (await new StringsDAO().LoadAsync(new StringsModel {
                    Locale = locale,
                    Identifier = "InvalidPrefix"
                })).String;
            }

            await context.Channel.SendMessageAsync(embed : builder.Build());
        }
Exemplo n.º 2
0
        private async Task CommandErroredAsync(CommandErrorEventArgs eventArgs)
        {
            switch (eventArgs.Exception)
            {
            case CommandNotFoundException _:
                break;

            case ChecksFailedException e:
                CheckBaseAttribute check = e.FailedChecks[0];
                switch (check)
                {
                case RequirePermissionsAttribute attr:
                    Console.WriteLine(attr.Permissions);
                    break;

                case RequireUserPermissionsAttribute attr:
                    Console.WriteLine(attr.Permissions);
                    break;
                }
                break;

            case ArgumentException _:
                GuildsModel guild = eventArgs.Context.Channel.IsPrivate ? null : new GuildsModel {
                    ID = eventArgs.Context.Guild.Id
                };
                Locale locale = new LocaleExtension().GetLocale(guild);
                DiscordEmbedBuilder builder = new DiscordEmbedBuilder {
                    Color = new DiscordColor(ColorConstant.embedColor),
                    Title = (await new StringsDAO().LoadAsync(new StringsModel {
                        Locale = locale,
                        Identifier = "ArgumentError"
                    })).String
                };
                await eventArgs.Context.Channel.SendMessageAsync(embed : await new CommandUseExtension().GetCommandUseAsync(builder, eventArgs.Context.Command, locale, new PrefixExtension().GetPrefix(guild)));

                break;

            default:
                eventArgs.Context.Client.DebugLogger.LogMessage(LogLevel.Error, "Handler", eventArgs.Exception.StackTrace, DateTime.Now);
                break;
            }
        }
Exemplo n.º 3
0
        public async Task HelpAsync(CommandContext context, [Description("HelpCommandParameter")] string commandName = null)
        {
            DiscordEmbedBuilder builder = new DiscordEmbedBuilder {
                Color = new DiscordColor(ColorConstant.embedColor)
            };

            GuildsModel guild = context.Channel.IsPrivate ? null : await new GuildsDAO().GetAsync(new GuildsModel {
                ID = context.Guild.Id
            });
            Locale locale = new LocaleExtension().GetLocale(guild);

            if (commandName == null)
            {
                builder.Title = (await new StringsDAO().LoadAsync(new StringsModel {
                    Identifier = "HelpTitle",
                    Locale = locale,
                })).String.Replace("$prefix", guild.Prefix);
                Type[] types = typeof(HelpModule).Assembly.GetTypes();
                for (int i = 0; i < types.Length; i++)
                {
                    ModuleAttribute moduleAttr = types[i].GetCustomAttribute <ModuleAttribute>();
                    if (moduleAttr != null)
                    {
                        MethodInfo[] methods  = types[i].GetMethods();
                        string       commands = string.Empty;
                        for (int j = 0; j < methods.Length; j++)
                        {
                            CommandAttribute commandAttr = methods[j].GetCustomAttribute <CommandAttribute>();
                            if (commandAttr != null && methods[j].GetCustomAttribute <HiddenAttribute>() == null)
                            {
                                commands += $"`{commandAttr.Name}`, ";
                            }
                        }
                        if (commands.Length != 0)
                        {
                            builder.AddField((await new StringsDAO().LoadAsync(new StringsModel {
                                Locale = locale,
                                Identifier = moduleAttr.Name
                            })).String, commands[..^ 2]);