示例#1
0
        public async Task GeneratePokeImageAsync([Summary("nr grafiki")] int index)
        {
            try
            {
                var reader = new JsonFileReader($"./Pictures/Poke/List.json");
                var images = reader.Load <List <SafariImage> >();

                var character = (await _shClient.GetCharacterInfoAsync(2)).Body;
                var channel   = Context.Channel as ITextChannel;

                _ = await _waifu.GetSafariViewAsync(images[index], _waifu.GenerateNewCard(null, character), channel);
            }
            catch (Exception ex)
            {
                await ReplyAsync("", embed : $"Coś poszło nie tak: {ex.Message}".ToEmbedMessage(EMType.Error).Build());
            }
        }
示例#2
0
        private async Task <bool> HandleReactionAsync(SessionContext context)
        {
            bool end = false;

            if (context.Message.Id != Message.Id)
            {
                return(false);
            }

            if (await Message.Channel.GetMessageAsync(Message.Id) is IUserMessage msg)
            {
                var reaction = context.ReactionAdded ?? context.ReactionRemoved;
                if (reaction == null)
                {
                    return(false);
                }

                if (reaction.Emote.Equals(DeclineEmote))
                {
                    await msg.ModifyAsync(x => x.Embed = $"{Name}\n\nOdrzucono tworzenie karty.".ToEmbedMessage(EMType.Bot).Build());

                    QueryCacheManager.ExpireTag(new string[] { $"user-{P1.User.Id}", "users" });

                    return(true);
                }

                if (reaction.Emote.Equals(AcceptEmote))
                {
                    bool error = true;

                    if (P1.Accepted)
                    {
                        error = false;
                        using (var db = new Database.UserContext(_config))
                        {
                            var user = await db.GetUserOrCreateAsync(P1.User.Id);

                            var newCard = _waifu.GenerateNewCard(P1.User, await _waifu.GetRandomCharacterAsync(), GetRarityFromValue(GetValue()));

                            newCard.Source    = CardSource.Crafting;
                            newCard.Affection = user.GameDeck.AffectionFromKarma();

                            foreach (var item in P1.Items)
                            {
                                var thisItem = user.GameDeck.Items.FirstOrDefault(x => x.Type == item.Type);
                                if (thisItem == null)
                                {
                                    error = true;
                                    break;
                                }

                                if (thisItem.Count < item.Count)
                                {
                                    error = true;
                                    break;
                                }
                                thisItem.Count -= item.Count;
                                if (thisItem.Count < 1)
                                {
                                    user.GameDeck.Items.Remove(thisItem);
                                }
                            }

                            user.GameDeck.Cards.Add(newCard);

                            await db.SaveChangesAsync();

                            await msg.ModifyAsync(x => x.Embed = $"{Name}\n\n**Utworzono:** {newCard.GetString(false, false, true)}".ToEmbedMessage(EMType.Success).Build());
                        }
                    }

                    if (error)
                    {
                        await msg.ModifyAsync(x => x.Embed = $"{Name}\n\nBrakuje przedmiotów, tworzenie karty nie powiodło się.".ToEmbedMessage(EMType.Bot).Build());
                    }

                    QueryCacheManager.ExpireTag(new string[] { $"user-{P1.User.Id}", "users" });

                    return(true);
                }

                try
                {
                    await msg.RemoveReactionAsync(reaction.Emote, context.User);
                }
                catch (Exception) { }
            }

            return(end);
        }