Пример #1
0
        public async Task Command([Remainder] string text)
        {
            Server server = await DatabaseQueries.GetOrCreateServerAsync(Context.Guild.Id);

            IEnumerable <Quote> quotes = server.Quotes;
            int quoteCount             = quotes?.Count() ?? 0;

            if (quoteCount > 0)
            {
                if (server.Quotes.Any(x => x.Text.Equals(text)))
                {
                    var cEmbed = new KaguyaEmbedBuilder(EmbedColor.YELLOW)
                    {
                        Description = "A quote with the same text already exists. Do you want to create this one anyway?"
                    };

                    var data = new ReactionCallbackData("", cEmbed.Build(), true, true, TimeSpan.FromSeconds(120));
                    data.AddCallBack(GlobalProperties.CheckMarkEmoji(), async(c, r) => { await InsertQuote(Context, server, text); });

                    data.AddCallBack(GlobalProperties.NoEntryEmoji(),
                                     async(c, r) => { await SendBasicErrorEmbedAsync("Okay, no action will be taken."); });

                    await InlineReactionReplyAsync(data);

                    return;
                }
            }

            await InsertQuote(Context, server, text);
        }
Пример #2
0
        public async Task Command()
        {
            User user = await DatabaseQueries.GetOrCreateUserAsync(Context.User.Id);

            Server server = await DatabaseQueries.GetOrCreateServerAsync(Context.Guild.Id);

            List <Fish> userFish = await DatabaseQueries.GetAllForUserAsync <Fish>(user.UserId);

            var countFishDicts = new List <Dictionary <FishType, int> >();

            if (userFish.Count == 0)
            {
                await SendBasicErrorEmbedAsync($"You have never fished before. Try it out with " +
                                               $"`{server.CommandPrefix}fish`!");

                return;
            }

            string ownedFishString  = "";
            int    curFishValue     = 0;
            int    allTimeFishValue = 0;

            foreach (FishType type in Enum.GetValues(typeof(FishType)))
            {
                // Creates a new dictionary of how many unsold fish the user has of the given type.
                var         dic = new Dictionary <FishType, int>();
                List <Fish> fishMatchingType = await DatabaseQueries.GetUnsoldFishForUserAsync(user.UserId);

                fishMatchingType = fishMatchingType.Where(x => x.FishType == type).ToList(); // Filter the fish.

                if (userFish.Count == 0)
                {
                    ownedFishString = $"You currently don't own any fish, go catch some!";

                    goto StatsEmbed;
                }

                // We don't care about BAIT_STOLEN because it's not actually a fish.
                if (fishMatchingType.Count != 0)
                {
                    dic.Add(type, fishMatchingType.Count);
                    countFishDicts.Add(dic);
                }
            }

            foreach (Fish fish in userFish)
            {
                allTimeFishValue += fish.Value;
                if (!fish.Sold)
                {
                    curFishValue += Fish.GetPayoutForFish(fish, user.FishExp);
                }
            }

            foreach (Dictionary <FishType, int> dic in countFishDicts)
            {
                ownedFishString += $"Fish: `{dic.Keys.First().ToString()}` - Count: `{dic.Values.First():N0}` - " +
                                   $"Value: `{Fish.GetPayoutForFish(userFish.Where(x => x.FishType == dic.Keys.First() && !x.Sold).ToList(), user.FishExp):N0}` points\n";
            }

            if (ownedFishString.IsNullOrEmpty())
            {
                ownedFishString = "`No fish currently owned.`";
            }

StatsEmbed:
            string rarestFish = null;

            if (userFish.Count(x => !x.Sold && x.FishType != FishType.BAIT_STOLEN) != 0)
            {
                rarestFish = userFish
                             .OrderBy(x => x.FishType)
                             .First(x => x.Sold == false && x.FishType != FishType.BAIT_STOLEN)
                             .FishType
                             .ToString();
            }

            var embed = new KaguyaEmbedBuilder
            {
                Title  = $"Kaguya Fishing - Stats for {Context.User}",
                Fields = new List <EmbedFieldBuilder>
                {
                    new EmbedFieldBuilder
                    {
                        Name  = "Fish Level",
                        Value = $"Fish Exp: `{user.FishExp:N0}` exp.\n" +
                                $"Fish Level: `{(int) FishHandler.GetFishLevel(user.FishExp):N0}`\n" +
                                $"{FishHandler.GetRewardString(user.FishExp, user, false)}"
                    },
                    new EmbedFieldBuilder
                    {
                        Name  = "Statistics",
                        Value = $"Bait stolen: `{userFish.Count(x => x.FishType == FishType.BAIT_STOLEN):N0} times`\n" +
                                $"All-time fish count: `{userFish.Count(x => x.FishType != FishType.BAIT_STOLEN):N0}`\n" +
                                $"All-time fish value: `{allTimeFishValue:N0}` points\n" +
                                $"Unsold fish value: `{curFishValue:N0}` points\n" +
                                $"Total fish sold: `{userFish.Count(x => x.Sold && x.FishType != FishType.BAIT_STOLEN):N0}`\n" +
                                $"Rarest owned fish: `{rarestFish ?? "No fish currently owned."}`\n" +
                                $"Number of owned, unsold fish: `{userFish.Count(x => x.FishType != FishType.BAIT_STOLEN && !x.Sold):N0}`"
                    },
                    new EmbedFieldBuilder
                    {
                        Name  = "Currently Owned Fish",
                        Value = ownedFishString
                    }
                },
                Footer = new EmbedFooterBuilder
                {
                    Text = $"React with a checkmark if you would like all of your Fish IDs DM'd to you!"
                }
            };

            // If they don't have any fish, we don't need to show them.
            if (rarestFish != null && rarestFish.ToLower().Contains("no fish"))
            {
                embed.Fields.RemoveAt(1);
            }

            await InlineReactionReplyAsync(new ReactionCallbackData("",
                                                                    embed.Build(), true, true, TimeSpan.FromSeconds(90))
                                           .AddCallBack(GlobalProperties.CheckMarkEmoji(), async(c, r) =>
            {
                using (var stream = new MemoryStream())
                {
                    var writer = new StreamWriter(stream);
                    foreach (Fish fish in userFish.Where(x => x.FishType != FishType.BAIT_STOLEN && !x.Sold))
                    {
                        await writer.WriteLineAsync($"Fish ID: {fish.FishId} - " +
                                                    $"Fish Type: {fish.FishType.ToString()} - " +
                                                    $"Value: {fish.Value}");
                    }

                    await writer.FlushAsync();
                    stream.Seek(0, SeekOrigin.Begin);

                    await c.User.SendFileAsync(stream, $"Fish for {c.User}.txt");
                    await c.Channel.SendBasicSuccessEmbedAsync($"{c.User.Mention} Alright, I've gone ahead " +
                                                               $"and DM'd you all of your fish!");
                }
            })
                                           .AddCallBack(GlobalProperties.NoEntryEmoji(),
                                                        async(c, r) => { await SendBasicErrorEmbedAsync("Okay, no action will be taken."); }));
        }
Пример #3
0
        public async Task DeleteRoles()
        {
            KaguyaEmbedBuilder embed;

            var confirmEmbed = new KaguyaEmbedBuilder
            {
                Description = $"{Context.User.Username}, are you sure you " +
                              $"wish to preform this action?"
            };

            confirmEmbed.SetColor(EmbedColor.VIOLET);

            var timeoutEmbed = new KaguyaEmbedBuilder
            {
                Description = "Timeout reached - reactions disabled. No action will be taken."
            };

            timeoutEmbed.SetColor(EmbedColor.RED);

            await InlineReactionReplyAsync(new ReactionCallbackData("", confirmEmbed.Build(), true, true, TimeSpan.FromSeconds(60))
                                           .WithCallback(GlobalProperties.CheckMarkEmoji(), async(c, r) =>
            {
                int i = 0;
                int j = 0;
                string failString = "";

                foreach (SocketRole role in Context.Guild.Roles.Where(x =>
                                                                      !x.Members.Any() && x.Name.ToLower() != "kaguya-mute"))
                {
                    try
                    {
                        await role.DeleteAsync();
                        i++;
                    }
                    catch (Exception)
                    {
                        j++;
                    }
                }

                if (j != 0)
                {
                    failString = $"However, I failed to delete `{j}` roles. These roles are likely " +
                                 "managed by integrations, therefore they cannot be deleted. \n" +
                                 "*Hint: Is my role at the top of the hierarchy?*";
                }

                if (i == 0 && j == 0)
                {
                    embed = new KaguyaEmbedBuilder
                    {
                        Description = "Actually, there weren't any roles to delete - no action has been taken."
                    };

                    await ReplyAsync(embed: embed.Build());
                }

                else
                {
                    embed = new KaguyaEmbedBuilder
                    {
                        Description = $"Successfully deleted `{i}` roles. {failString}"
                    };

                    await ReplyAsync(embed: embed.Build());
                }
            })
                                           .WithCallback(new Emoji("⛔"), async(c, r) =>
            {
                embed = new KaguyaEmbedBuilder
                {
                    Description = $"Okay, no action will be taken."
                };

                await ReplyAsync(embed: embed.Build());
            }));
        }