Ejemplo n.º 1
0
        public async Task CallAchievementUnlockEventAsync(IAchievement achievement, IDiscordUser user, IDiscordTextChannel channel)
        {
            if (achievement as AchievementAchievement == null)
            {
                return;
            }

            long id = user.Id.ToDbLong();

            using (var scope = MikiApp.Instance.Services.CreateScope())
            {
                var context = scope.ServiceProvider
                              .GetService <MikiDbContext>();
                int achievementCount = await context.Achievements
                                       .Where(q => q.UserId == id)
                                       .CountAsync();

                AchievementPacket p = new AchievementPacket()
                {
                    discordUser    = user,
                    discordChannel = channel,
                    achievement    = achievement,
                    count          = achievementCount
                };

                await OnAchievementUnlocked?.Invoke(p);
            }
        }
Ejemplo n.º 2
0
        public async Task CallAchievementUnlockEventAsync(BaseAchievement achievement, IDiscordUser user, IDiscordChannel channel)
        {
            DogStatsd.Counter("achievements.gained", 1);

            if (achievement as AchievementAchievement != null)
            {
                return;
            }

            long id = user.Id.ToDbLong();

            using (var context = new MikiContext())
            {
                int achievementCount = await context.Achievements
                                       .Where(q => q.UserId == id)
                                       .CountAsync();

                AchievementPacket p = new AchievementPacket()
                {
                    discordUser    = user,
                    discordChannel = channel,
                    achievement    = achievement,
                    count          = achievementCount
                };

                await OnAchievementUnlocked?.Invoke(p);
            }
        }
Ejemplo n.º 3
0
        public async Task CallAchievementUnlockEventAsync(BaseAchievement achievement, IDiscordUser user, IDiscordMessageChannel channel)
        {
            if (achievement as AchievementAchievement != null)
            {
                return;
            }

            using (var context = new MikiContext())
            {
                long id = user.Id.ToDbLong();

                List <Achievement> achs = context.Achievements.Where(q => q.Id == id).ToList();
                int achievementCount    = achs.Sum(x => x.Rank + 1);

                AchievementPacket p = new AchievementPacket()
                {
                    discordUser    = user,
                    discordChannel = channel,
                    achievement    = achievement,
                    count          = achievementCount
                };

                await OnAchievementUnlocked?.Invoke(p);
            }
        }