Пример #1
0
        public async Task SetModuleAsync(EventContext e)
        {
            ArgObject arg = e.Arguments.FirstOrDefault();

            if (arg == null)
            {
                return;
            }

            string moduleName = arg.Argument;

            Module m = e.EventSystem.GetCommandHandler <SimpleCommandHandler>().Modules.FirstOrDefault(x => x.Name == moduleName);

            if (m == null)
            {
                e.ErrorEmbed($"{arg.Argument} is not a valid module.")
                .ToEmbed().QueueToChannel(e.Channel);
                return;
            }

            arg = arg?.Next();

            bool?setValue = arg.TakeBoolean();

            if (!setValue.HasValue)
            {
                setValue = arg.Argument.ToLower() == "yes" || arg.Argument == "1";
            }

            if (!m.CanBeDisabled && !setValue.Value)
            {
                e.ErrorEmbed(e.Locale.GetString("miki_admin_cannot_disable", $"`{moduleName}`"))
                .ToEmbed().QueueToChannel(e.Channel);
                return;
            }

            arg = arg?.Next();

            await m.SetEnabled(Global.RedisClient, e.Guild.Id, (setValue ?? false));

            e.SuccessEmbed(((setValue ?? false) ? e.Locale.GetString("miki_generic_enabled") : e.Locale.GetString("miki_generic_disabled")) + $" {m.Name}")
            .QueueToChannel(e.Channel);
        }
Пример #2
0
        public async Task SetGuildConfig(EventContext e)
        {
            using (MikiContext context = new MikiContext())
            {
                GuildUser g = await context.GuildUsers.FindAsync(e.Guild.Id.ToDbLong());

                ArgObject arg = e.Arguments.FirstOrDefault();

                if (arg != null)
                {
                    switch (arg.Argument)
                    {
                    case "expneeded":
                    {
                        arg = arg.Next();

                        if (arg != null)
                        {
                            if (int.TryParse(arg.Argument, out int value))
                            {
                                g.MinimalExperienceToGetRewards = value;

                                new EmbedBuilder()
                                .SetTitle(e.Locale.GetString("miki_terms_config"))
                                .SetDescription(e.Locale.GetString("guildconfig_expneeded", value))
                                .ToEmbed().QueueToChannel(e.Channel);
                            }
                        }
                    }
                    break;

                    case "visible":
                    {
                        arg = arg.Next();

                        if (arg != null)
                        {
                            bool?result = arg.TakeBoolean();

                            if (!result.HasValue)
                            {
                                return;
                            }

                            string resourceString = result.Value
                                                                        ? "guildconfig_visibility_true"
                                                                        : "guildconfig_visibility_false";

                            new EmbedBuilder()
                            .SetTitle(e.Locale.GetString("miki_terms_config"))
                            .SetDescription(resourceString)
                            .ToEmbed().QueueToChannel(e.Channel);
                        }
                    }
                    break;
                    }
                    await context.SaveChangesAsync();
                }
                else
                {
                    new EmbedBuilder()
                    {
                        Title       = e.Locale.GetString("guild_settings"),
                        Description = e.Locale.GetString("miki_command_description_guildconfig")
                    }.ToEmbed().QueueToChannel(e.Channel);
                }
            }
        }