示例#1
0
文件: Debug.cs 项目: fossabot/sanakan
        public async Task GenerateCardAsync([Summary("użytkownik")] SocketGuildUser user, [Summary("id postaci na shinden(nie podanie - losowo)")] ulong id = 0,
                                            [Summary("jakość karty(nie podanie - losowo)")] Rarity rarity = Rarity.E)
        {
            var character = (id == 0) ? await _waifu.GetRandomCharacterAsync() : (await _shClient.GetCharacterInfoAsync(id)).Body;

            var card = (rarity == Rarity.E) ? _waifu.GenerateNewCard(character) : _waifu.GenerateNewCard(character, rarity);

            card.Source = CardSource.GodIntervention;
            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(user.Id);

                botuser.GameDeck.Cards.Add(card);

                await db.SaveChangesAsync();

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

                await ReplyAsync("", embed : $"{user.Mention} otrzymał {card.GetString(false, false, true)}.".ToEmbedMessage(EMType.Success).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);
        }