Exemple #1
0
        public async Task ConfigRoleInteractiveAsync(EventContext e)
        {
            using (var context = new MikiContext())
            {
                IDiscordEmbed sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                                            .SetDescription("Type out the role name you want to config")
                                            .SetColor(138, 182, 239);
                IDiscordMessage sourceMessage = await sourceEmbed.SendToChannel(e.Channel);

                IDiscordMessage msg = null;

                while (true)
                {
                    msg = await EventSystem.Instance.ListenNextMessageAsync(e.Channel.Id, e.Author.Id);

                    if (msg.Content.Length < 20)
                    {
                        break;
                    }

                    sourceMessage.Modify("", e.ErrorEmbed("That role name is way too long! Try again."));
                }

                IDiscordRole role    = GetRoleByName(e.Guild, msg.Content.ToLower());
                LevelRole    newRole = await context.LevelRoles.FindAsync(e.Guild.Id.ToDbLong(), role.Id.ToDbLong());

                if (newRole == null)
                {
                    newRole = (await context.LevelRoles.AddAsync(new LevelRole()
                    {
                        RoleId = role.Id.ToDbLong(),
                        GuildId = e.Guild.Id.ToDbLong()
                    })).Entity;
                }

                sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                              .SetDescription("Is there a role that is needed to get this role? Type out the role name, or `-` to skip")
                              .SetColor(138, 182, 239);

                sourceMessage = await sourceEmbed.SendToChannel(e.Channel);


                while (true)
                {
                    msg = await EventSystem.Instance.ListenNextMessageAsync(e.Channel.Id, e.Author.Id);

                    IDiscordRole parentRole = GetRoleByName(e.Guild, msg.Content.ToLower());

                    if (parentRole != null || msg.Content == "-")
                    {
                        newRole.RequiredRole = (long?)parentRole?.Id ?? 0;
                        break;
                    }

                    sourceMessage.Modify(null, e.ErrorEmbed("I couldn't find that role. Try again!"));
                }

                sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                              .SetDescription($"Is there a level requirement? type a number, if there is no requirement type 0")
                              .SetColor(138, 182, 239);

                sourceMessage = await sourceEmbed.SendToChannel(e.Channel);

                while (true)
                {
                    msg = await EventSystem.Instance.ListenNextMessageAsync(e.Channel.Id, e.Author.Id);

                    if (int.TryParse(msg.Content, out int r))
                    {
                        if (r >= 0)
                        {
                            newRole.RequiredLevel = r;
                            break;
                        }
                        else
                        {
                            sourceMessage.Modify(null, sourceEmbed.SetDescription($"Please pick a number above 0. Try again"));
                        }
                    }
                    else
                    {
                        sourceMessage.Modify(null, sourceEmbed.SetDescription($"Are you sure `{msg.Content}` is a number? Try again"));
                    }
                }

                sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                              .SetDescription($"Should I give them when the user level ups? type `yes`, otherwise it will be considered as no")
                              .SetColor(138, 182, 239);

                sourceMessage = await sourceEmbed.SendToChannel(e.Channel);

                msg = await EventSystem.Instance.ListenNextMessageAsync(e.Channel.Id, e.Author.Id);

                if (msg == null)
                {
                    return;
                }

                newRole.Automatic = msg.Content.ToLower()[0] == 'y';

                sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                              .SetDescription($"Should users be able to opt in? type `yes`, otherwise it will be considered as no")
                              .SetColor(138, 182, 239);

                sourceMessage = await sourceEmbed.SendToChannel(e.Channel);

                msg = await EventSystem.Instance.ListenNextMessageAsync(e.Channel.Id, e.Author.Id);

                newRole.Optable = msg.Content.ToLower()[0] == 'y';

                if (newRole.Optable)
                {
                    sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                                  .SetDescription($"Do you want the user to pay mekos for the role? Enter any amount. Enter 0 to keep the role free.")
                                  .SetColor(138, 182, 239);

                    sourceMessage = await sourceEmbed.SendToChannel(e.Channel);

                    while (true)
                    {
                        msg = await EventSystem.Instance.ListenNextMessageAsync(e.Channel.Id, e.Author.Id);

                        if (msg == null)
                        {
                            return;
                        }

                        if (int.TryParse(msg.Content, out int r))
                        {
                            if (r >= 0)
                            {
                                newRole.Price = r;
                                break;
                            }
                            else
                            {
                                sourceMessage.Modify(null, e.ErrorEmbed($"Please pick a number above 0. Try again"));
                            }
                        }
                        else
                        {
                            sourceMessage.Modify(null, e.ErrorEmbed($"Not quite sure if this is a number 🤔"));
                        }
                    }
                }

                await context.SaveChangesAsync();

                Utils.Embed.SetTitle("⚙ Role Config")
                .SetColor(102, 117, 127)
                .SetDescription($"Updated {role.Name}!")
                .QueueToChannel(e.Channel);
            }
        }