Ejemplo n.º 1
0
        public async Task NotifyAdmins(string content)
        {
            var nicks = options.Value.Telegram.DevUsers;
            var users = await db.Set <User>().AsNoTracking()
                        .Where(x => nicks.Contains(x.Username))
                        .Select(x => x.Id)
                        .ToArrayAsync();

            var sent = users.Select(userId => SendText(userId, content))
                       .AsEnumerable();

            await Task.WhenAll(sent);
        }
Ejemplo n.º 2
0
 public List <User> GetUsers()
 {
     lock (_dbLock)
         return(_db.Set <User>().ToList());
 }
Ejemplo n.º 3
0
        public async Task Process(CycleCompletedEvent subject)
        {
            var delegateAddressList = await _db.Set <Delegate>().Select(x => x.Address).ToArrayAsync();

            var delegates = new Dictionary <string, DateTime?>();

            var delegators = await _db.Set <UserAddress>().AsNoTracking()
                             .Include(x => x.User)
                             .Where(x => !x.IsDeleted)
                             .Where(x => x.NotifyDelegateStatus && !delegateAddressList.Contains(x.Address))
                             .ToArrayAsync();

            var inactiveBound = _config.Value.DelegateInactiveTime;

            foreach (var delegator in delegators)
            {
                var account = _tzkt.GetAccount(delegator.Address);
                if (account.Delegate == null)
                {
                    continue;
                }

                var delegateName    = account.Delegate.Alias;
                var delegateAddress = account.Delegate.Address;
                if (delegates.ContainsKey(delegateAddress) is false)
                {
                    delegates.Add(delegateAddress, await _addressService.GetDelegateLastActive(delegateAddress));
                }

                var delegateLastActive = delegates[delegateAddress];
                if (delegateLastActive == null)
                {
                    continue;
                }

                // Skip if last active recently than `inactiveBound` time span
                if (DateTime.Now.Subtract((DateTime)delegateLastActive) < inactiveBound)
                {
                    continue;
                }

                // Bad hack
                var @delegate = new UserAddress
                {
                    Name    = delegateName,
                    Address = delegateAddress
                };

                var user = delegator.User;
                var text = _lang.Get(Res.DelegateInactive, user.Language, new
                {
                    t            = Explorer.FromId(user.Explorer), // TODO: Fix it
                    delegateName = @delegate.DisplayName(),
                    delegateAddress,
                    inactiveTime = inactiveBound.Humanize(culture: new CultureInfo(user.Language), toWords: false,
                                                          maxUnit: TimeUnit.Day),
                    delegatorName    = delegator.DisplayName(),
                    delegatorAddress = delegator.Address
                });

                var message = new MessageBuilder()
                              .AddLine(text)
                              .WithHashTag("delegate_inactive")
                              .WithHashTag(@delegate);

                await _db.AddAsync(Message.Push(user.Id, message.Build(!user.HideHashTags)));

                await _db.SaveChangesAsync();
            }
        }