Beispiel #1
0
        private void LogMessageCount(MomentumDiscordDbContext dbContext, DiscordMessage message)
        {
            var user = dbContext.DailyMessageCount
                       .SingleOrDefault(x => x.UserId == message.Author.Id &&
                                        x.ChannelId == message.Channel.Id &&
                                        x.Date == message.CreationTimestamp.UtcDateTime.Date);

            if (user != null)
            {
                // If they have a message count for that day, just increment
                user.MessageCount++;
            }
            else
            {
                // No data for the current state, make a new message count
                var newUser = new DailyMessageCount
                {
                    ChannelId    = message.Channel.Id,
                    Date         = message.CreationTimestamp.UtcDateTime.Date,
                    UserId       = message.Author.Id,
                    MessageCount = 1
                };

                dbContext.Add(newUser);
            }

            dbContext.SaveChanges();
        }