コード例 #1
0
        /// <summary>
        /// Show User Balance
        /// </summary>
        /// <param name="sender"></param>
        /// <returns></returns>
        private async Task cmd_ShowUserBalance(ApplicationUser sender)
        {
            try
            {
                await _botService.Client.SendChatActionAsync(sender.TelegramId, ChatAction.Typing);

                coinQuoteCol = _appdb.CoinQuotes.Where(x => x.TimeStamp >= DateTime.Now.AddDays(-1)).ToList();
                var quote = LastAllQuote();

                if (!string.IsNullOrEmpty(sender.Address))
                {
                    RiseManager rm          = new RiseManager();
                    var         balance     = Math.Round(await rm.AccountBalanceAsync(sender.Address), 4);
                    var         strResponse = "<b>Current Balance for </b>@" + sender.UserName + Environment.NewLine +
                                              "Address: <b>" + sender.Address + "</b>" + Environment.NewLine +
                                              "Balance: <b>" + balance + " RISE </b>" + Environment.NewLine +
                                              "USD: <b>" + Math.Round(balance * quote.USDPrice, 4) + "$</b>";

                    if (string.IsNullOrEmpty(sender.UserName))
                    {
                        strResponse += Environment.NewLine + " Note: Please configure your Telegram UserName if you want to Receive <b>RISE</b>";
                    }

                    await _botService.Client.SendTextMessageAsync(sender.TelegramId, strResponse, ParseMode.Html);
                }
            }
            catch (Exception ex)
            {
                var log = new Log();
                log.LogMessage(ex.Message + " " + ex.StackTrace + " " + ex.InnerException);
                _appdb.Logger.Add(log);
                _appdb.SaveChangesAsync().Wait();
            }
        }
コード例 #2
0
        /// <summary>
        /// The ExecuteAsync
        /// </summary>
        /// <param name="cancellationToken">The cancellationToken<see cref="CancellationToken"/></param>
        /// <returns>The <see cref="Task"/></returns>
        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            try
            {
                using (var scope = _scopeFactory.CreateScope())
                {
                    var dbContext = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>();

                    var UsersLst = dbContext.ApplicationUsers.ToList <ApplicationUser>();
                    TipAccountStats.UsersCount = UsersLst.Count();

                    // List all account address
                    TipAccountStats.AddressLst = dbContext.ApplicationUsers.Select(x => x.Address).ToList();

                    // Reset the balance
                    double TotalBalance            = 0;
                    int    TotalTransactions       = 0;
                    long   TotalAmountTransactions = 0;

                    foreach (var account in UsersLst)
                    {
                        if (account.Address != null)
                        {
                            RiseManager rm = new RiseManager();

                            TotalBalance += await rm.AccountBalanceAsync(account.Address);

                            var tx = TransactionsFetcher.FetchAllUserTransactions(account.Address).Result.transactions.ToList();
                            TotalTransactions       += tx.Count();
                            TotalAmountTransactions += tx.Sum(x => x.amount / 100000000);

                            if (tx == null && account.UserName == null)
                            {
                                dbContext.Users.Remove(account);
                                dbContext.SaveChanges();
                            }
                        }
                    }

                    TipAccountStats.TotalBalance            = TotalBalance;
                    TipAccountStats.TotalTransactions       = TotalTransactions;
                    TipAccountStats.TotalAmountTransactions = TotalAmountTransactions;
                    TipAccountStats.LastGenerated           = DateTime.Now;
                }
            }
            catch (Exception e)
            {
                Console.Write(e.InnerException);
            }
        }
コード例 #3
0
        /// <summary>
        /// Check Before Sending
        /// </summary>
        /// <param name="amount"></param>
        /// <param name="command"></param>
        /// <param name="numReceivers"></param>
        /// <param name="chatId"></param>
        /// <param name="appuser"></param>
        /// <returns></returns>
        private async Task <bool> cmd_preSend(double amount, string command, int numReceivers, long chatId, ApplicationUser appuser)
        {
            try
            {
                if (numReceivers > 30)
                {
                    await _botService.Client.SendTextMessageAsync(chatId, Emoji.Point_Up + " Please use a maximum of 30 users!", ParseMode.Html);

                    return(false);
                }

                if (numReceivers == 0)
                {
                    await _botService.Client.SendTextMessageAsync(chatId, Emoji.No_Good + " Sorry I did not find any user to send RISE :(", ParseMode.Html);

                    return(false);
                }

                if (amount <= 0.1)
                {
                    await _botService.Client.SendTextMessageAsync(chatId, Emoji.Scream_Cat + "It make no sense to " + command + " amount lower than 0.1! (network fees are 0.1 RISE!!)", ParseMode.Html);

                    return(false);
                }

                RiseManager rm = new RiseManager();

                var balance = await rm.AccountBalanceAsync(appuser.Address);

                if (balance < ((0.1 * numReceivers) + amount))
                {
                    await _botService.Client.SendTextMessageAsync(chatId, Emoji.Astonished + " Not enough RISE to " + command + " " + amount + " RISE to " + numReceivers + " users. RISE Balance:" + balance, ParseMode.Html);

                    return(false);
                }
            }
            catch (Exception ex)
            {
                var log = new Log();
                log.LogMessage(ex.Message + " " + ex.StackTrace + " " + ex.InnerException);
                _appdb.Logger.Add(log);
                _appdb.SaveChangesAsync().Wait();
                return(false);
            }

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Withdraw coin
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="amount"></param>
        /// <param name="recipientId"></param>
        /// <returns></returns>
        private async Task cmd_Withdraw(ApplicationUser sender, double amount, string recipientId)
        {
            RiseManager rm = new RiseManager();

            try
            {
                if (amount > 0 && !string.IsNullOrEmpty(recipientId))
                {
                    await _botService.Client.SendChatActionAsync(sender.TelegramId, ChatAction.Typing);

                    var balance = await rm.AccountBalanceAsync(sender.Address);

                    if (balance >= (amount + 0.1))
                    {
                        var tx = await rm.CreatePaimentAsync(amount * 100000000, sender.GetSecret(), recipientId);

                        if (tx.success)
                        {
                            await _botService.Client.SendTextMessageAsync(sender.TelegramId, "Successfully sent <b>" + amount + "</b> RISE to " + recipientId, ParseMode.Html);

                            var keyboard = new InlineKeyboardMarkup(InlineKeyboardButton.WithUrl("See Transaction", "https://explorer.rise.vision/tx/" + tx.transactionId));
                            await _botService.Client.SendTextMessageAsync(sender.TelegramId, "Transaction Id:" + tx.transactionId + "", replyMarkup : keyboard);
                        }
                        else
                        {
                            await _botService.Client.SendTextMessageAsync(sender.TelegramId, "Error withdrawing <b>" + amount + "</b> RISE to " + recipientId + " try to reduce the amount...", ParseMode.Html);
                        }
                    }
                    else
                    {
                        await _botService.Client.SendTextMessageAsync(sender.TelegramId, "Not enough RISE to Withdraw <b>" + amount + "</b> RISE balance" + balance + " RISE", ParseMode.Html);
                    }
                }
                else
                {
                    await _botService.Client.SendTextMessageAsync(sender.TelegramId, "Please specify amount and address ex: !withdraw 10 5953135380169360325R", ParseMode.Html);
                }
            }
            catch (Exception ex)
            {
                var log = new Log();
                log.LogMessage(ex.Message + " " + ex.StackTrace + " " + ex.InnerException);
                _appdb.Logger.Add(log);
                _appdb.SaveChangesAsync().Wait();
            }
        }
コード例 #5
0
        /// <summary>
        /// Withdraw coin
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="amount"></param>
        /// <param name="recipientId"></param>
        /// <returns></returns>
        private async Task cmd_Vote(ApplicationUser sender)
        {
            if (sender.UserName == "Dwildcash")
            {
                RiseManager rm = new RiseManager();

                try
                {
                    var balance = await rm.AccountBalanceAsync(sender.Address);

                    if (balance >= (1.1))
                    {
                        var tx = await rm.DelegateVoteAsync(sender.GetSecret());

                        if (tx.success)
                        {
                            await _botService.Client.SendTextMessageAsync(sender.TelegramId, "Successfully voted for dtpool, thanks you!", ParseMode.Html);
                        }
                        else
                        {
                            await _botService.Client.SendTextMessageAsync(sender.TelegramId, "Error voting...", ParseMode.Html);
                        }
                    }
                    else
                    {
                        await _botService.Client.SendTextMessageAsync(sender.TelegramId, "Not enough RISE to vote <b>1 requited</b> RISE balance: <b>" + balance + "</b>", ParseMode.Html);
                    }
                }
                catch (Exception ex)
                {
                    var log = new Log();
                    log.LogMessage(ex.Message + " " + ex.StackTrace + " " + ex.InnerException);
                    _appdb.Logger.Add(log);
                    _appdb.SaveChangesAsync().Wait();
                }
            }
        }