Пример #1
0
        private async Task CheckMessageDate(int timeoutInMin)
        {
            while (true)
            {
                await Task.Delay(5000);

                try
                {
                    foreach (var message in CurrentMessages.ToList())
                    {
                        if (message.CreatedAt.DateTime.ToLocalTime().AddMinutes(timeoutInMin) < DateTime.Now)
                        {
                            CurrentMessages.Remove(message);
                            await message.DeleteAsync();

                            using (var db = Database.Open())
                            {
                                var easterevent = db.EasterEvents.FirstOrDefault(p => p.MessageId == message.Id);
                                if (easterevent != null)
                                {
                                    easterevent.DespawnTime = DateTime.Now;
                                }
                                await db.SaveChangesAsync();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Can't remove a message");
                }
            }
        }
Пример #2
0
        public async Task CatchEgg(ulong userId, ulong messageId)
        {
            var message = CurrentMessages.FirstOrDefault(p => p.Id == messageId);

            if (message == null)
            {
                return;
            }

            var channel = message.Channel;
            var author  = Guild.Users.FirstOrDefault(p => p.Id == userId);

            int eggs = 0;

            using (var db = Database.Open())
            {
                var user = db.Users.FirstOrDefault(p => p.Id == userId) ?? db.Users.AddAsync(new UserEntity {
                    Id = userId, Name = $"{author.Username}#{author.Discriminator}"
                }).Result.Entity;
                var feature = db.Features.FirstOrDefault(p => p.GuildId == Guild.Id && p.UserId == userId) ?? db.Features.AddAsync(new FeatureEntity {
                    UserId = userId, GuildId = Guild.Id
                }).Result.Entity;
                if (feature == null)
                {
                    return;
                }

                feature.Eggs++;
                eggs = feature.Eggs;
                var easterevent = db.EasterEvents.FirstOrDefault(p => p.MessageId == messageId);
                if (easterevent != null)
                {
                    easterevent.UserId    = userId;
                    easterevent.CatchTime = DateTime.Now;
                }

                await db.SaveChangesAsync();
            }
            const int delay = 8000;
            var       embed = new EmbedBuilder();

            embed.WithDescription($"Glückwunsch! {author.Mention} du hast jetzt {eggs} {Constants.EggGoatR} gefangen!");
            embed.WithColor(new Color(90, 92, 96));
            CurrentMessages.Remove(message);
            await message.ModifyAsync(p =>
            {
                p.Content = "";
                p.Embed   = embed.Build();
            });

            await Task.Delay(delay);

            await message.DeleteAsync();
        }