Пример #1
0
        public async Task SetProfileBackgroundAsync(EventContext e)
        {
            int?backgroundId = e.Arguments.First().AsInt();

            if (backgroundId == null)
            {
                throw new ArgumentNullException("background");
            }

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

            using (var context = new MikiContext())
            {
                BackgroundsOwned bo = await context.BackgroundsOwned.FindAsync(userId, backgroundId ?? 0);

                if (bo == null)
                {
                    throw new BackgroundNotOwnedException();
                }

                ProfileVisuals v = await ProfileVisuals.GetAsync(userId, context);

                v.BackgroundId = bo.BackgroundId;

                await context.SaveChangesAsync();
            }

            Utils.SuccessEmbed(e.Channel.Id, "Successfully set background.")
            .QueueToChannel(e.Channel);
        }
Пример #2
0
        public async Task SetProfileBackgroundAsync(CommandContext e)
        {
            if (!e.Arguments.Take(out int backgroundId))
            {
                throw new ArgumentNullException("background");
            }

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

            var context = e.GetService <MikiDbContext>();

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

            if (bo == null)
            {
                throw new BackgroundNotOwnedException();
            }

            ProfileVisuals v = await ProfileVisuals.GetAsync(userId, context);

            v.BackgroundId = bo.BackgroundId;
            await context.SaveChangesAsync();

            await e.SuccessEmbed("Successfully set background.")
            .QueueToChannelAsync(e.Channel);
        }
Пример #3
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();
                            }
                        }
                    }
                }
            }
        }
Пример #4
0
        public async Task BuyProfileBackgroundAsync(EventContext e)
        {
            ArgObject arguments = e.Arguments.FirstOrDefault();

            if (arguments == null)
            {
                e.Channel.QueueMessageAsync("Enter a number after `>buybackground` to check the backgrounds! (e.g. >buybackground 1)");
            }
            else
            {
                if (arguments.TryParseInt(out int id))
                {
                    if (id >= Global.Backgrounds.Backgrounds.Count || id < 0)
                    {
                        e.ErrorEmbed("This background does not exist!")
                        .ToEmbed()
                        .QueueToChannel(e.Channel);
                        return;
                    }

                    Background background = Global.Backgrounds.Backgrounds[id];

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

                    if (background.Price > 0)
                    {
                        embed.SetDescription($"This background for your profile will cost {background.Price.ToFormattedString()} mekos, Type `>buybackground {id} yes` to buy.");
                    }
                    else
                    {
                        embed.SetDescription($"This background is not for sale.");
                    }

                    arguments = arguments.Next();

                    if (arguments?.Argument.ToLower() == "yes")
                    {
                        if (background.Price > 0)
                        {
                            using (var context = new MikiContext())
                            {
                                User user = await User.GetAsync(context, e.Author.Id, e.Author.Username);

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

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

                                if (bo == null)
                                {
                                    user.RemoveCurrency(background.Price);
                                    await context.BackgroundsOwned.AddAsync(new BackgroundsOwned()
                                    {
                                        UserId       = e.Author.Id.ToDbLong(),
                                        BackgroundId = background.Id,
                                    });

                                    await context.SaveChangesAsync();

                                    e.SuccessEmbed("Background purchased!")
                                    .QueueToChannel(e.Channel);
                                }
                                else
                                {
                                    throw new BackgroundOwnedException();
                                }
                            }
                        }
                    }
                    else
                    {
                        embed.ToEmbed()
                        .QueueToChannel(e.Channel);
                    }
                }
            }
        }
Пример #5
0
        public async Task BuyProfileBackgroundAsync(CommandContext e)
        {
            var backgrounds = e.GetService <BackgroundStore>();

            if (!e.Arguments.Take(out int id))
            {
                e.Channel.QueueMessage("Enter a number after `>buybackground` to check the backgrounds! (e.g. >buybackground 1)");
            }

            if (id >= backgrounds.Backgrounds.Count || id < 0)
            {
                await e.ErrorEmbed("This background does not exist!")
                .ToEmbed()
                .QueueToChannelAsync(e.Channel);

                return;
            }

            Background background = backgrounds.Backgrounds[id];

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

            if (background.Price > 0)
            {
                embed.SetDescription($"This background for your profile will cost {background.Price.ToFormattedString()} mekos, Type `>buybackground {id} yes` to buy.");
            }
            else
            {
                embed.SetDescription($"This background is not for sale.");
            }

            if (e.Arguments.Take(out string confirmation))
            {
                if (confirmation.ToLower() == "yes")
                {
                    if (background.Price > 0)
                    {
                        var context = e.GetService <MikiDbContext>();

                        User user = await User.GetAsync(context, e.Author.Id, e.Author.Username);

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

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

                        if (bo == null)
                        {
                            user.RemoveCurrency(background.Price);
                            await context.BackgroundsOwned.AddAsync(new BackgroundsOwned()
                            {
                                UserId       = e.Author.Id.ToDbLong(),
                                BackgroundId = background.Id,
                            });

                            await context.SaveChangesAsync();

                            await e.SuccessEmbed("Background purchased!")
                            .QueueToChannelAsync(e.Channel);
                        }
                        else
                        {
                            throw new BackgroundOwnedException();
                        }
                    }
                    return;
                }
            }

            await embed.ToEmbed()
            .QueueToChannelAsync(e.Channel);
        }