Exemplo n.º 1
0
        public int GiveCard(SocketUser sender, SocketUser user, string reason, Cards card, ulong serverId, SocketCommandContext context)
        {
            try
            {
                using (var db = new CardContext())
                {
                    var giver      = Commands.GetDBUser(sender, db);
                    var degenerate = Commands.GetDBUser(user, db);
                    var givenCard  = db.Cards.AsQueryable().Where(c => c.Id == card.Id).FirstOrDefault();

                    var newCard = new CardGivings
                    {
                        Id           = Guid.NewGuid(),
                        CardId       = givenCard.Id,
                        Card         = givenCard,
                        GiverId      = giver.Id,
                        Giver        = giver,
                        DegenerateId = degenerate.Id,
                        Degenerate   = degenerate,
                        CardReason   = reason,
                        ServerId     = serverId,
                        TimeStamp    = DateTime.Now
                    };

                    db.CardGivings.Add(newCard);

                    db.SaveChanges();

                    return(db.CardGivings.AsQueryable()
                           .Where(c => c.Degenerate.Id == degenerate.Id)
                           .Where(c => c.Card.Id == card.Id)
                           .Where(c => c.ServerId == serverId)
                           .Count());
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                throw;
            }
        }
Exemplo n.º 2
0
        public async Task GiveCard(string color, string user, params string[] reason)
        {
            if (reason.Length == 0)
            {
                reason = new[] { "being an ass" };
            }

            string r = string.Join(' ', reason);

            var serverId = Context.Guild.Id;

            var mention = GetUser(user, Context);

            if (null == mention)
            {
                await ReplyAsync($"Cannot find user {user}. This is a discord error not a database error.");

                return;
            }

            var   card           = GetCard(color, serverId);
            Cards failedPollCard = null;

            if (card == null)
            {
                await ReplyAsync("This card does not exist. Please create it with !create");

                return;
            }

            if (!card.Poll)
            {
                await AddCard(mention, card, r);

                return;
            }

            failedPollCard = GetCard(card.FailedId, serverId);
            var dbUser_rec = GetDBUser(mention, new CardContext());
            var dbUser_giv = GetDBUser(Context.User, new CardContext());

            var giving = new CardGivings()
            {
                Card         = card,
                CardId       = card.Id,
                CardReason   = r,
                Degenerate   = dbUser_rec,
                DegenerateId = dbUser_rec.Id,
                Giver        = dbUser_giv,
                GiverId      = dbUser_giv.Id,
                Id           = Guid.NewGuid(),
                ServerId     = serverId,
                TimeStamp    = DateTime.Now
            };

            var roleTag = Context.Guild.Roles.First(r => r.Name == CardRole).Mention;

            var message = await ReplyAsync($"{roleTag}: {Context.User.Mention} is proposing to give {mention.Mention} a {card.Name} card worth {card.Value} points.\n\n" +
                                           $"Place your votes below.  The votes will be counted in {Poll.HOURS_OF_GIVE_POLL} hours.");

            await message.AddReactionsAsync(new[] { new Emoji("👍"), new Emoji("👎") });

            var polls = PollSingleton.Instance;

            polls.NewPoll(new Poll(
                              mention,
                              PollType.GIVE,
                              Context,
                              message.Id,
                              giving,
                              failedPollCard));
        }