コード例 #1
0
        /// <summary>
        /// Checks if money were deposited to an address associated with any user who has a deposit address.
        /// When money are deposited user's balance is updated.
        /// </summary>
        private void CheckDeposits(BotDbContext context)
        {
            this.logger.Trace("()");

            List <DiscordUserModel> usersToTrack = context.Users.AsQueryable().Where(x => x.DepositAddress != null).ToList();

            this.logger.Trace("Tracking {0} users.", usersToTrack.Count);
            try
            {
                foreach (DiscordUserModel user in usersToTrack)
                {
                    var addressHistory = blockCoreNodeAPI.GetAddressesHistory(user.DepositAddress).Result;

                    var transactionHistory = addressHistory.history.Where(x => x.accountName == AccountName).SelectMany(x => x.transactionsHistory);

                    var receivedByAddress = transactionHistory.Where(x => x.type == "received");

                    if (receivedByAddress.Count() > 0)
                    {
                        decimal totalRecivedByAddress = receivedByAddress.Sum(x => x.amount);

                        decimal balance = Money.FromUnit(totalRecivedByAddress, MoneyUnit.Satoshi).ToUnit(MoneyUnit.BTC);

                        if (balance > user.LastCheckedReceivedAmountByAddress)
                        {
                            decimal recentlyReceived = balance - user.LastCheckedReceivedAmountByAddress;

                            // Prevent users from spamming small amounts of coins.
                            // Also keep in mind if you'd like to change that- EF needs to be configured to track such changes.
                            // https://stackoverflow.com/questions/25891795/entityframework-not-detecting-changes-to-decimals-after-a-certain-precision
                            if (recentlyReceived < 0.01m)
                            {
                                this.logger.Trace("Skipping dust {0} for user {1}.", recentlyReceived, user);
                                continue;
                            }

                            this.logger.Debug("New value for received by address is {0}. Old was {1}. Address is {2}.", receivedByAddress, user.LastCheckedReceivedAmountByAddress, user.DepositAddress);

                            user.LastCheckedReceivedAmountByAddress = balance;
                            user.Balance += recentlyReceived;

                            context.Attach(user);
                            context.Entry(user).Property(x => x.Balance).IsModified = true;
                            context.Entry(user).Property(x => x.LastCheckedReceivedAmountByAddress).IsModified = true;
                            context.SaveChanges();

                            this.logger.Info("User '{0}' deposited {1}!. New balance is {2}.", user, recentlyReceived, user.Balance);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.logger.Error(ex.ToString);
            }

            this.logger.Trace("(-)");
        }
コード例 #2
0
    public async Task <IResult> Execute(Message msg, BotUser user)
    {
        var parameters = msg.Text.Split(' ', 3)[1..];

        user = _db.Entry(user).Entity;
        if (parameters.Length < 2)
        {
            return(new FailedResult("Укажите 2 параметра команды." +
                                    "Пример использования: установить город Москва / установить группу 123456"));
        }

        var whatToSet = parameters[0];
        var dataToSet = parameters[1];

        if (whatToSet.Contains("город", StringComparison.InvariantCultureIgnoreCase))
        {
            return(await SetCity(dataToSet, user));
        }

        if (whatToSet.Contains("групп", StringComparison.InvariantCultureIgnoreCase))
        {
            return(await SetGroup(dataToSet, user));
        }

        return(new FailedResult("Укажите что вы хотите установить: группу или город. \n" +
                                "Пример использования: установить город Москва / установить группу 123456"));
    }
コード例 #3
0
ファイル: MuteCommand.cs プロジェクト: equuskk/Goblin
    public async Task <IResult> Execute(Message msg, BotUser user)
    {
        user = _db.Entry(user).Entity;
        user.SetErrorNotification(!user.IsErrorsEnabled);
        await _db.SaveChangesAsync();

        return(new SuccessfulResult
        {
            Message = user.IsErrorsEnabled ? "Ошибки включены" : "Ошибки отключены"
        });
    }
コード例 #4
0
        /// <summary>
        /// Checks if money were deposited to an address associated with any user who has a deposit address.
        /// When money are deposited user's balance is updated.
        /// </summary>
        private void CheckDeposits(BotDbContext context)
        {
            this.logger.Trace("()");

            List <DiscordUserModel> usersToTrack = context.Users.Where(x => x.DepositAddress != null).ToList();

            this.logger.Trace("Tracking {0} users.", usersToTrack.Count);

            foreach (DiscordUserModel user in usersToTrack)
            {
                decimal receivedByAddress = this.coinService.GetReceivedByAddress(user.DepositAddress, this.settings.MinConfirmationsForDeposit);

                if (receivedByAddress > user.LastCheckedReceivedAmountByAddress)
                {
                    decimal recentlyReceived = receivedByAddress - user.LastCheckedReceivedAmountByAddress;

                    // Prevent users from spamming small amounts of coins.
                    // Also keep in mind if you'd like to change that- EF needs to be configured to track such changes.
                    // https://stackoverflow.com/questions/25891795/entityframework-not-detecting-changes-to-decimals-after-a-certain-precision
                    if (recentlyReceived < 0.01m)
                    {
                        this.logger.Trace("Skipping dust {0} for user {1}.", recentlyReceived, user);
                        continue;
                    }

                    this.logger.Debug("New value for received by address is {0}. Old was {1}. Address is {2}.", receivedByAddress, user.LastCheckedReceivedAmountByAddress, user.DepositAddress);

                    user.LastCheckedReceivedAmountByAddress = receivedByAddress;
                    user.Balance += recentlyReceived;

                    context.Attach(user);
                    context.Entry(user).Property(x => x.Balance).IsModified = true;
                    context.Entry(user).Property(x => x.LastCheckedReceivedAmountByAddress).IsModified = true;
                    context.SaveChanges();

                    this.logger.Info("User '{0}' deposited {1}!. New balance is {2}.", user, recentlyReceived, user.Balance);
                }
            }

            this.logger.Trace("(-)");
        }
コード例 #5
0
ファイル: MailingCommand.cs プロジェクト: equuskk/Goblin
    public async Task <IResult> Execute(Message msg, BotUser user)
    {
        user = _db.Entry(user).Entity;
        var choose     = msg.ParsedPayload[Trigger];
        var isSchedule = user.HasScheduleSubscription;
        var isWeather  = user.HasWeatherSubscription;

        if (choose.Equals("weather", StringComparison.OrdinalIgnoreCase))
        {
            return(await SetWeatherMailing(user, isWeather));
        }

        if (choose.Equals("schedule", StringComparison.OrdinalIgnoreCase))
        {
            return(await SetScheduleMailing(user, isSchedule));
        }

        return(new FailedResult("Действие не найдено"));
    }
コード例 #6
0
 public void Update(User user)
 {
     _context.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 }
コード例 #7
0
 public virtual void Update(T entity)
 {
     dbSet.Attach(entity);
     dataContext.Entry(entity).State = EntityState.Modified;
 }
コード例 #8
0
 public void Update(User user)
 {
     _context.Entry(user).State = EntityState.Modified;
 }