예제 #1
0
        public async Task CreateAlert(string name, int time, int?day, string text, List <ulong> roles, ulong channel, ulong user)
        {
            var timeInfo = await _timeZoneService.GetTime(user, day, time);

            var alert = new Alert
            {
                Name          = name,
                Description   = text,
                Roles         = roles.ConcatenateULongs(),
                Time          = timeInfo.Item2,
                Day           = timeInfo.Item1,
                ChannelId     = channel,
                DiscordUserId = user
            };

            _plogDbContext.Add(alert);
            await _plogDbContext.SaveChangesAsync();
        }
예제 #2
0
        public async Task Process()
        {
            var alerts = await _alertService.GetReadyAlerts();

            var tasks = alerts.Select(a => _alertService.BlastAlert(a.Name, a.Description, a.Time, a.Roles.GetULongs(), a.ChannelId));
            await Task.WhenAll(tasks);

            var processedTime = DateTime.UtcNow;

            alerts.ForEach(a => a.LastProcessed = processedTime);
            _plogDbContext.UpdateRange(alerts);
            await _plogDbContext.SaveChangesAsync();
        }
예제 #3
0
        private async Task ProcessAdd(List <string> args)
        {
            if (args.Count == 1)
            {
                var name = args[0];
                var plog = await _plogDbContext.Plogs.Where(p => p.Name.ToLower() == name.ToLower()).FirstOrDefaultAsync();

                if (plog == null)
                {
                    var character = await _bladeAndSoulService.GetBladeAndSoulCharacter(name);

                    if (character == null || character.Clan.ToLower() != "ploggystyle")
                    {
                        _response = $"{name} is not in Ploggystyle.";
                    }
                    else
                    {
                        plog = new ClanMember
                        {
                            RealName = character.AccountName,
                            Name     = name,
                            Active   = true,
                            Class    = character.Class,
                            Created  = DateTime.UtcNow,
                            ImageUrl = character.ProfileImageUrl
                        };
                        _plogDbContext.Add(plog);
                        await _plogDbContext.SaveChangesAsync();

                        _response = $"{name} has been added to the clan.";
                    }
                }
                else
                {
                    _response = "This plog already exists!";
                    if (plog.DiscordId.HasValue && plog.DiscordId.Value != _event.Message.Author.Id)
                    {
                        _response += $" <@{plog.DiscordId}> has claimed this character.";
                    }
                }
            }
            else
            {
                _response = "Incorrect command format: !plog add [name]";
            }

            await _messageService.SendMessage(_event.Message.ChannelId, new OutgoingMessage
            {
                Content = _response
            });
        }
예제 #4
0
        public async Task SaveTimeZonePreference(string abbreviation, ulong discordUserId)
        {
            var timePref = await _plogDbContext.Times.FirstOrDefaultAsync(t => t.DiscordUserId == discordUserId);

            if (timePref == null)
            {
                timePref = new TimeZonePreference
                {
                    DiscordUserId = discordUserId,
                    TimeZone      = abbreviation
                };
                _plogDbContext.Add(timePref);
            }
            else
            {
                timePref.TimeZone = abbreviation;
                _plogDbContext.Update(timePref);
            }

            await _plogDbContext.SaveChangesAsync();
        }
예제 #5
0
        public async Task SaveNewLogs()
        {
            using (var client = new HttpClient())
                using (var db = new PlogDbContext())
                {
                    client.BaseAddress = new Uri("http://na-bns.ncsoft.com");
                    var batchNumber = await db.Logs.MaxAsync(l => (int?)l.BatchId);

                    if (batchNumber.HasValue)
                    {
                        batchNumber++;
                    }
                    else
                    {
                        batchNumber = 1;
                    }
                    var loggingProcesses = db.Plogs.Select(p => ForEachPlog_GetInformation(p)).ToList();
                    await Task.WhenAll(loggingProcesses);

                    // Filter out unprocessable entities
                    loggingProcesses = loggingProcesses.Where(lp => lp.Result != null).ToList();

                    var items = await ProcessItems(
                        loggingProcesses.Select(lp => lp.Result?.Items)
                        .Where(i => i != null)
                        .ToList(), db);

                    var saves = loggingProcesses.Select(lp => ForEachPlog_Add(lp.Result, db, items, batchNumber.Value));
                    await Task.WhenAll(saves);

                    try
                    {
                        await db.SaveChangesAsync();
                    }
                    catch (Exception e)
                    {
                        await _loggingService.LogErrorAsync(e.StackTrace);
                    }
                }
        }
예제 #6
0
        private async Task <Dictionary <string, Item> > ProcessItems(List <BladeAndSoulItems> itemGroups, PlogDbContext db)
        {
            var start = DateTime.UtcNow;

            var allItems = await db.Items.ToDictionaryAsync(i => i.Name, i => i);

            foreach (var itemGroup in itemGroups)
            {
                if (itemGroup.Weapon != null && !allItems.ContainsKey(itemGroup.Weapon))
                {
                    allItems.Add(itemGroup.Weapon, CreateNewItem(db, new Item {
                        ItemType = ItemType.Weapon, Name = itemGroup.Weapon, ImgUrl = itemGroup.WeaponImg
                    }));
                }

                if (itemGroup.Gem1 != null && !allItems.ContainsKey(itemGroup.Gem1))
                {
                    allItems.Add(itemGroup.Gem1, CreateNewItem(db, new Item {
                        ItemType = ItemType.Gem, Name = itemGroup.Gem1, ImgUrl = itemGroup.Gem1Img
                    }));
                }

                if (itemGroup.Gem2 != null && !allItems.ContainsKey(itemGroup.Gem2))
                {
                    allItems.Add(itemGroup.Gem2, CreateNewItem(db, new Item {
                        ItemType = ItemType.Gem, Name = itemGroup.Gem2, ImgUrl = itemGroup.Gem2Img
                    }));
                }

                if (itemGroup.Gem3 != null && !allItems.ContainsKey(itemGroup.Gem3))
                {
                    allItems.Add(itemGroup.Gem3, CreateNewItem(db, new Item {
                        ItemType = ItemType.Gem, Name = itemGroup.Gem3, ImgUrl = itemGroup.Gem3Img
                    }));
                }

                if (itemGroup.Gem4 != null && !allItems.ContainsKey(itemGroup.Gem4))
                {
                    allItems.Add(itemGroup.Gem4, CreateNewItem(db, new Item {
                        ItemType = ItemType.Gem, Name = itemGroup.Gem4, ImgUrl = itemGroup.Gem4Img
                    }));
                }

                if (itemGroup.Gem5 != null && !allItems.ContainsKey(itemGroup.Gem5))
                {
                    allItems.Add(itemGroup.Gem5, CreateNewItem(db, new Item {
                        ItemType = ItemType.Gem, Name = itemGroup.Gem5, ImgUrl = itemGroup.Gem5Img
                    }));
                }

                if (itemGroup.Gem6 != null && !allItems.ContainsKey(itemGroup.Gem6))
                {
                    allItems.Add(itemGroup.Gem6, CreateNewItem(db, new Item {
                        ItemType = ItemType.Gem, Name = itemGroup.Gem6, ImgUrl = itemGroup.Gem6Img
                    }));
                }

                if (itemGroup.Ring != null && !allItems.ContainsKey(itemGroup.Ring))
                {
                    allItems.Add(itemGroup.Ring, CreateNewItem(db, new Item {
                        ItemType = ItemType.Ring, Name = itemGroup.Ring, ImgUrl = itemGroup.RingImg
                    }));
                }

                if (itemGroup.Earring != null && !allItems.ContainsKey(itemGroup.Earring))
                {
                    allItems.Add(itemGroup.Earring, CreateNewItem(db, new Item {
                        ItemType = ItemType.Earring, Name = itemGroup.Earring, ImgUrl = itemGroup.EarringImg
                    }));
                }

                if (itemGroup.Necklace != null && !allItems.ContainsKey(itemGroup.Necklace))
                {
                    allItems.Add(itemGroup.Necklace, CreateNewItem(db, new Item {
                        ItemType = ItemType.Necklace, Name = itemGroup.Necklace, ImgUrl = itemGroup.NecklaceImg
                    }));
                }

                if (itemGroup.Bracelet != null && !allItems.ContainsKey(itemGroup.Bracelet))
                {
                    allItems.Add(itemGroup.Bracelet, CreateNewItem(db, new Item {
                        ItemType = ItemType.Bracelet, Name = itemGroup.Bracelet, ImgUrl = itemGroup.BraceletImg
                    }));
                }

                if (itemGroup.Belt != null && !allItems.ContainsKey(itemGroup.Belt))
                {
                    allItems.Add(itemGroup.Belt, CreateNewItem(db, new Item {
                        ItemType = ItemType.Belt, Name = itemGroup.Belt, ImgUrl = itemGroup.BeltImg
                    }));
                }

                if (itemGroup.Gloves != null && !allItems.ContainsKey(itemGroup.Gloves))
                {
                    allItems.Add(itemGroup.Gloves, CreateNewItem(db, new Item {
                        ItemType = ItemType.Gloves, Name = itemGroup.Gloves, ImgUrl = itemGroup.GlovesImg
                    }));
                }

                if (itemGroup.Pet != null && !allItems.ContainsKey(itemGroup.Pet))
                {
                    allItems.Add(itemGroup.Pet, CreateNewItem(db, new Item {
                        ItemType = ItemType.Pet, Name = itemGroup.Pet, ImgUrl = itemGroup.PetImg
                    }));
                }

                if (itemGroup.Soul != null && !allItems.ContainsKey(itemGroup.Soul))
                {
                    allItems.Add(itemGroup.Soul, CreateNewItem(db, new Item {
                        ItemType = ItemType.Soul, Name = itemGroup.Soul, ImgUrl = itemGroup.SoulImg
                    }));
                }

                if (itemGroup.Heart != null && !allItems.ContainsKey(itemGroup.Heart))
                {
                    allItems.Add(itemGroup.Heart, CreateNewItem(db, new Item {
                        ItemType = ItemType.Heart, Name = itemGroup.Heart, ImgUrl = itemGroup.HeartImg
                    }));
                }

                if (itemGroup.SoulBadge != null && !allItems.ContainsKey(itemGroup.SoulBadge))
                {
                    allItems.Add(itemGroup.SoulBadge, CreateNewItem(db, new Item {
                        ItemType = ItemType.SoulBadge, Name = itemGroup.SoulBadge, ImgUrl = itemGroup.SoulBadgeImg
                    }));
                }

                if (itemGroup.MysticBadge != null && !allItems.ContainsKey(itemGroup.MysticBadge))
                {
                    allItems.Add(itemGroup.MysticBadge, CreateNewItem(db, new Item {
                        ItemType = ItemType.MysticBadge, Name = itemGroup.MysticBadge, ImgUrl = itemGroup.MysticBadgeImg
                    }));
                }
            }

            // Save all items to the database.
            await db.SaveChangesAsync();

            var end = DateTime.UtcNow;
            await _loggingService.LogAsync($"Processing time to save items to the database: {(end - start).TotalMilliseconds}");

            return(allItems);
        }