Beispiel #1
0
        public async Task SetProfileForeColorAsync(EventContext e)
        {
            using (var context = new MikiContext())
            {
                User user = await User.GetAsync(context, e.Author);

                new EmbedBuilder()
                .SetTitle("Hold on!")
                .SetDescription("Changing your foreground(text) color costs 250 mekos. type a hex(e.g. #00FF00) to purchase")
                .ToEmbed().QueueToChannel(e.Channel);

                IDiscordMessage msg = await e.EventSystem.GetCommandHandler <MessageListener>()
                                      .WaitForNextMessage(e.CreateSession());

                var x = Regex.Matches(msg.Content.ToUpper(), "(#)?([A-F0-9]{6})");

                if (x.Count > 0)
                {
                    ProfileVisuals visuals = await ProfileVisuals.GetAsync(e.Author.Id, context);

                    var hex = x.First().Groups.Last().Value;

                    visuals.ForegroundColor = hex;
                    await user.AddCurrencyAsync(-250, e.Channel);

                    await context.SaveChangesAsync();

                    Utils.SuccessEmbed(e.Channel.Id,
                                       $"Your foreground color has been successfully changed to `{hex}`")
                    .QueueToChannel(e.Channel);
                }
                else
                {
                    throw new ArgumentException("Argument was not a hex color");
                }
            }
        }
Beispiel #2
0
        public async Task ConfigRoleInteractiveAsync(EventContext e)
        {
            using (var context = new MikiContext())
            {
                EmbedBuilder sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                                           .SetDescription("Type out the role name you want to config")
                                           .SetColor(138, 182, 239);
                IDiscordMessage sourceMessage = await sourceEmbed.ToEmbed().SendToChannel(e.Channel);

                IDiscordMessage msg = null;

                while (true)
                {
                    msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession());

                    if (msg.Content.Length < 20)
                    {
                        break;
                    }
                    else
                    {
                        await sourceMessage.EditAsync(new EditMessageArgs
                        {
                            embed = e.ErrorEmbed("That role name is way too long! Try again.")
                                    .ToEmbed()
                        });
                    }
                }

                string roleName = msg.Content;

                List <IDiscordRole> rolesFound = await GetRolesByName(e.Guild, roleName.ToLower());

                IDiscordRole role = null;

                if (rolesFound.Count == 0)
                {
                    // Hey, I couldn't find this role, Can I make a new one?
                    await sourceMessage.EditAsync(new EditMessageArgs
                    {
                        embed = e.ErrorEmbed($"There's no role that is named `{roleName}`, Shall I create it? Y/N").ToEmbed()
                    });

                    msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession());

                    if (msg.Content.ToLower()[0] != 'y')
                    {
                        throw new RoleNullException();
                    }

                    role = await e.Guild.CreateRoleAsync(new CreateRoleArgs
                    {
                        Name = roleName,
                    });
                }
                else if (rolesFound.Count > 1)
                {
                    string roleIds = string.Join("\n", rolesFound.Select(x => $"`{x.Name}`: {x.Id}"));

                    if (roleIds.Length > 1024)
                    {
                        roleIds = roleIds.Substring(0, 1024);
                    }

                    sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                                  .SetDescription("I found multiple roles with that name, which one would you like? please enter the ID")
                                  .AddInlineField("Roles - Ids", roleIds)
                                  .SetColor(138, 182, 239);

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

                    while (true)
                    {
                        msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession());

                        if (ulong.TryParse(msg.Content, out ulong id))
                        {
                            role = rolesFound.Where(x => x.Id == id)
                                   .FirstOrDefault();

                            if (role != null)
                            {
                                break;
                            }
                            else
                            {
                                await sourceMessage.EditAsync(new EditMessageArgs {
                                    embed = e.ErrorEmbed("I couldn't find that role id in the list. Try again!")
                                            .AddInlineField("Roles - Ids", string.Join("\n", roleIds)).ToEmbed()
                                });
                            }
                        }
                        else
                        {
                            await sourceMessage.EditAsync(new EditMessageArgs
                            {
                                embed = e.ErrorEmbed("I couldn't find that role. Try again!")
                                        .AddInlineField("Roles - Ids", string.Join("\n", roleIds)).ToEmbed()
                            });
                        }
                    }
                }
                else
                {
                    role = rolesFound.FirstOrDefault();
                }

                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.ToEmbed().SendToChannel(e.Channel);

                while (true)
                {
                    msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession());

                    rolesFound = (await GetRolesByName(e.Guild, msg.Content.ToLower()));
                    IDiscordRole parentRole = null;

                    if (rolesFound.Count > 1)
                    {
                        string roleIds = string.Join("\n", rolesFound.Select(x => $"`{x.Name}`: {x.Id}"));

                        if (roleIds.Length > 1024)
                        {
                            roleIds = roleIds.Substring(0, 1024);
                        }

                        sourceEmbed = Utils.Embed.SetTitle("⚙ Interactive Mode")
                                      .SetDescription("I found multiple roles with that name, which one would you like? please enter the ID")
                                      .AddInlineField("Roles - Ids", roleIds)
                                      .SetColor(138, 182, 239);

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

                        while (true)
                        {
                            msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession());

                            if (ulong.TryParse(msg.Content, out ulong id))
                            {
                                parentRole = rolesFound.Where(x => x.Id == id)
                                             .FirstOrDefault();

                                if (parentRole != null)
                                {
                                    break;
                                }
                                else
                                {
                                    await sourceMessage.EditAsync(new EditMessageArgs {
                                        embed = e.ErrorEmbed("I couldn't find that role id in the list. Try again!")
                                                .AddInlineField("Roles - Ids", string.Join("\n", roleIds)).ToEmbed()
                                    });
                                }
                            }
                            else
                            {
                                await sourceMessage.EditAsync(new EditMessageArgs
                                {
                                    embed = e.ErrorEmbed("I couldn't find that role. Try again!")
                                            .AddInlineField("Roles - Ids", string.Join("\n", roleIds)).ToEmbed()
                                });
                            }
                        }
                    }
                    else
                    {
                        parentRole = rolesFound.FirstOrDefault();
                    }

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

                    await sourceMessage.EditAsync(new EditMessageArgs
                    {
                        embed = e.ErrorEmbed("I couldn't find that role. Try again!").ToEmbed()
                    });
                }

                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.ToEmbed().SendToChannel(e.Channel);

                while (true)
                {
                    msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession());

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

                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.ToEmbed().SendToChannel(e.Channel);

                msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession());

                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.ToEmbed().SendToChannel(e.Channel);

                msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession());

                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.ToEmbed().SendToChannel(e.Channel);

                    while (true)
                    {
                        msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession());

                        if (msg == null)
                        {
                            return;
                        }

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

                await context.SaveChangesAsync();

                Utils.Embed.SetTitle("⚙ Role Config")
                .SetColor(102, 117, 127)
                .SetDescription($"Updated {role.Name}!")
                .ToEmbed().QueueToChannel(e.Channel);
            }
        }
Beispiel #3
0
        public async Task IAmAsync(EventContext e)
        {
            using (var context = new MikiContext())
            {
                string roleName = e.Arguments.ToString();

                List <IDiscordRole> roles = await GetRolesByName(e.Guild, roleName);

                IDiscordRole role = null;

                if (roles.Count > 1)
                {
                    List <LevelRole> levelRoles = await context.LevelRoles.Where(x => x.GuildId == (long)e.Guild.Id).ToListAsync();

                    if (levelRoles.Where(x => x.Role.Name.ToLower() == roleName.ToLower()).Count() > 1)
                    {
                        e.ErrorEmbed("two roles configured have the same name.")
                        .ToEmbed().QueueToChannel(e.Channel);
                        return;
                    }
                    else
                    {
                        role = levelRoles.Where(x => x.Role.Name.ToLower() == roleName.ToLower()).FirstOrDefault().Role;
                    }
                }
                else
                {
                    role = roles.FirstOrDefault();
                }

                if (role == null)
                {
                    e.ErrorEmbedResource("error_role_null")
                    .ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                IDiscordGuildUser author = await e.Guild.GetUserAsync(e.Author.Id);

                if (author.RoleIds.Contains(role.Id))
                {
                    e.ErrorEmbed(e.GetResource("error_role_already_given"))
                    .ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                LevelRole newRole = await context.LevelRoles.FindAsync(e.Guild.Id.ToDbLong(), role.Id.ToDbLong());

                User user = (await context.Users.FindAsync(e.Author.Id.ToDbLong()));

                IDiscordGuildUser discordUser = await e.Guild.GetUserAsync(user.Id.FromDbLong());

                LocalExperience localUser = await LocalExperience.GetAsync(context, e.Guild.Id.ToDbLong(), discordUser);

                if (!newRole?.Optable ?? false)
                {
                    await e.ErrorEmbed(e.GetResource("error_role_forbidden"))
                    .ToEmbed().SendToChannel(e.Channel);

                    return;
                }

                int level = User.CalculateLevel(localUser.Experience);

                if (newRole.RequiredLevel > level)
                {
                    await e.ErrorEmbed(e.GetResource("error_role_level_low", newRole.RequiredLevel - level))
                    .ToEmbed().SendToChannel(e.Channel);

                    return;
                }

                if (newRole.RequiredRole != 0 && !discordUser.RoleIds.Contains(newRole.RequiredRole.FromDbLong()))
                {
                    await e.ErrorEmbed(
                        e.GetResource(
                            "error_role_required",
                            $"**{(await e.Guild.GetRoleAsync(newRole.RequiredRole.FromDbLong())).Name}**"
                            )).ToEmbed().SendToChannel(e.Channel);

                    return;
                }

                if (newRole.Price > 0)
                {
                    if (user.Currency >= newRole.Price)
                    {
                        await e.Channel.SendMessageAsync($"Getting this role costs you {newRole.Price} mekos! type `yes` to proceed.");

                        IDiscordMessage m = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession());

                        if (m.Content.ToLower()[0] == 'y')
                        {
                            await user.AddCurrencyAsync(-newRole.Price);

                            await context.SaveChangesAsync();
                        }
                        else
                        {
                            await e.ErrorEmbed("Purchase Cancelled")
                            .ToEmbed().SendToChannel(e.Channel);

                            return;
                        }
                    }
                    else
                    {
                        await e.ErrorEmbed(e.GetResource("user_error_insufficient_mekos"))
                        .ToEmbed().SendToChannel(e.Channel);

                        return;
                    }
                }

                await author.AddRoleAsync(newRole.Role);

                Utils.Embed.SetTitle("I AM")
                .SetColor(128, 255, 128)
                .SetDescription($"You're a(n) {role.Name} now!")
                .ToEmbed().QueueToChannel(e.Channel);
            }
        }
Beispiel #4
0
        public async Task BuyProfileBackgroundAsync(EventContext e)
        {
            int?backgroundId = e.Arguments.First().AsInt();

            if (backgroundId.HasValue)
            {
                Background background = Global.Backgrounds.Backgrounds[backgroundId.Value];


                var embed = new EmbedBuilder();
                embed.SetTitle("Buy Background");

                if (background.Price > 0)
                {
                    embed.SetDescription($"This background for your profile will cost {background.Price} mekos, Type yes to buy.");
                }
                else
                {
                    embed.SetDescription($"This background is not for sale.");
                }
                embed.SetImage(background.ImageUrl)
                .ToEmbed().QueueToChannel(e.Channel);

                if (background.Price > 0)
                {
                    IDiscordMessage msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession());

                    if (msg.Content.ToLower()[0] == 'y')
                    {
                        using (var context = new MikiContext())
                        {
                            User user = await User.GetAsync(context, e.Author);

                            long userId = e.Author.Id.ToDbLong();

                            BackgroundsOwned bo = await context.BackgroundsOwned.FindAsync(userId, background.Id);

                            if (bo == null)
                            {
                                await user.AddCurrencyAsync(-background.Price, e.Channel);

                                await context.BackgroundsOwned.AddAsync(new BackgroundsOwned()
                                {
                                    UserId       = e.Author.Id.ToDbLong(),
                                    BackgroundId = background.Id,
                                });

                                await context.SaveChangesAsync();

                                Utils.SuccessEmbed(e.Channel.Id, "Background purchased!")
                                .QueueToChannel(e.Channel);
                            }
                            else
                            {
                                throw new BackgroundOwnedException();
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public async Task SetupNotificationsInteractive <T>(EventContext e, DatabaseSettingId settingId)
        {
            List <string> options = Enum.GetNames(typeof(T))
                                    .Select(x => x.ToLower()
                                            .Replace('_', ' '))
                                    .ToList();

            string settingName = settingId.ToString().ToLower().Replace('_', ' ');

            var sEmbed = SettingsBaseEmbed;

            sEmbed.Description = ($"What kind of {settingName} do you want");
            sEmbed.AddInlineField("Options", string.Join("\n", options));
            var sMsg = await sEmbed.ToEmbed().SendToChannel(e.Channel);

            int newSetting;

            IDiscordMessage msg = null;

            while (true)
            {
                msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession());

                if (Enum.TryParse <LevelNotificationsSetting>(msg.Content.Replace(" ", "_"), true, out var setting))
                {
                    newSetting = (int)setting;
                    break;
                }

                await sMsg.EditAsync(new EditMessageArgs()
                {
                    embed = e.ErrorEmbed("Oh, that didn't seem right! Try again")
                            .AddInlineField("Options", string.Join("\n", options))
                            .ToEmbed()
                });
            }

            sMsg = await SettingsBaseEmbed
                   .SetDescription("Do you want this to apply for every channel? say `yes` if you do.")
                   .ToEmbed().SendToChannel(e.Channel as IDiscordGuildChannel);

            msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession());

            bool global = (msg.Content.ToLower()[0] == 'y');

            await SettingsBaseEmbed
            .SetDescription($"Setting `{settingName}` Updated!")
            .ToEmbed().SendToChannel(e.Channel as IDiscordGuildChannel);

            if (!global)
            {
                await Setting.UpdateAsync(e.Channel.Id, settingId, newSetting);
            }
            else
            {
                await Setting.UpdateGuildAsync(e.Guild, settingId, newSetting);
            }
        }
Beispiel #6
0
        private async Task <UserMarriedTo> SelectMarriageAsync(EventContext e, MikiContext context, List <UserMarriedTo> marriages)
        {
            EmbedBuilder embed = new EmbedBuilder()
            {
                Title       = "💔  Select marriage to divorce",
                Description = "Please type in the number of which marriage you want to divorce.",
                Color       = new Color(231, 90, 112)
            };

            var m = marriages.OrderBy(x => x.Marriage.TimeOfMarriage);

            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < m.Count(); i++)
            {
                builder.AppendLine($"`{(i+1).ToString().PadLeft(2)}:` {await User.GetNameAsync(context, m.ElementAt(i).GetOther(e.Author.Id.ToDbLong()))}");
            }

            embed.Description += "\n\n" + builder.ToString();

            embed.ToEmbed().QueueToChannel(e.Channel);

            IDiscordMessage msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession());

            if (int.TryParse(msg.Content, out int response))
            {
                if (response > 0 && response <= marriages.Count)
                {
                    return(m.ElementAt(response - 1));
                }
                throw new Exception("This number is not listed, cancelling divorce.");
            }
            throw new Exception("This is not a number, cancelling divorce.");
        }
Beispiel #7
0
        public async Task BuyMarriageSlotAsync(EventContext e)
        {
            using (var context = new MikiContext())
            {
                User user = await User.GetAsync(context, e.Author);

                int  limit     = 10;
                bool isDonator = await user.IsDonatorAsync(context);

                if (isDonator)
                {
                    limit += 5;
                }

                EmbedBuilder embed = new EmbedBuilder();

                if (user.MarriageSlots >= limit)
                {
                    embed.Description = $"For now, **{limit} slots** is the max. sorry :(";

                    if (limit == 10 && !isDonator)
                    {
                        embed.AddField("Pro tip!", "Donators get 5 more slots!")
                        .SetFooter("Check `>donate` for more information!", "");
                    }

                    embed.Color = new Color(1f, 0.6f, 0.4f);
                    embed.ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                int costForUpgrade = (user.MarriageSlots - 4) * 2500;

                embed.Description = $"Do you want to buy a Marriage slot for **{costForUpgrade}**?\n\nType `yes` to confirm.";
                embed.Color       = new Color(0.4f, 0.6f, 1f);

                SimpleCommandHandler commandHandler = new SimpleCommandHandler(new CommandMap());
                commandHandler.AddPrefix("");
                commandHandler.AddCommand(new CommandEvent("yes")
                                          .Default(async(cx) => await ConfirmBuyMarriageSlot(cx, costForUpgrade)));

                e.EventSystem.GetCommandHandler <SessionBasedCommandHandler>().AddSession(e.CreateSession(), commandHandler, new TimeSpan(0, 0, 20));

                embed.ToEmbed().QueueToChannel(e.Channel);
            }
        }