示例#1
0
        public async Task <GuildsModel> GetAsync(GuildsModel guild)
        {
            GuildsModel dbGuild = await(await _collection.FindAsync(x => x.ID == guild.ID)).FirstOrDefaultAsync();

            return(new GuildsModel {
                ID = guild.ID, Locale = dbGuild?.Locale, Prefix = dbGuild?.Prefix
            });
        }
示例#2
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());
        }
示例#3
0
        public async Task SetLocaleAsync(CommandContext context, [Description("LocaleParameter")][RemainingText] string locale)
        {
            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
            });

            switch (locale.ToLower())
            {
            case "pt-br":
                guild.Locale = Locale.PT_BR;
                await new GuildsDAO().SetAsync(guild);

                builder.Title = (await new StringsDAO().LoadAsync(new StringsModel {
                    Identifier = "LocaleUpdated",
                    Locale = Locale.PT_BR,
                })).String.Replace("$lang", "pt-BR");
                break;

            case "en-us":
                guild.Locale = Locale.EN_US;
                await new GuildsDAO().SetAsync(guild);
                builder.Title = (await new StringsDAO().LoadAsync(new StringsModel {
                    Identifier = "LocaleUpdated",
                    Locale = Locale.EN_US,
                })).String.Replace("$lang", "en-US");
                break;

            default:
                builder.Title = (await new StringsDAO().LoadAsync(new StringsModel {
                    Identifier = "InvalidLocale",
                    Locale = new LocaleExtension().GetLocale(guild)
                })).String;

                throw new ArgumentException();
            }
            await context.Channel.SendMessageAsync(embed : builder.Build());
        }
示例#4
0
        public async Task SetAsync(GuildsModel guild)
        {
            UpdateDefinition <GuildsModel> update = new BsonDocument();

            if (guild.Locale != null)
            {
                update = update.Set(x => x.Locale, guild.Locale);
            }
            if (guild.Prefix != null)
            {
                update = update.Set(x => x.Prefix, guild.Prefix);
            }

            await _collection.UpdateOneAsync(x => x.ID == guild.ID, update, new UpdateOptions { IsUpsert = true });
        }
示例#5
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;
            }
        }
示例#6
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]);
示例#7
0
 internal string GetPrefix(GuildsModel guild)
 {
     return(guild?.Prefix ?? "s.");
 }
示例#8
0
 internal Locale GetLocale(GuildsModel guild)
 {
     return(guild?.Locale ?? Locale.EN_US);
 }