Exemplo n.º 1
0
        public async Task WithdrawFromWalletInstant(CommandContext Context, [Description("Amount of DAL to withdraw. Use 'all' for your entire balance")] string AmountStr, [Description("Dallar Wallet Address to withdraw Dallar to")] string PublicAddress)
        {
            // Make sure supplied address is a valid Dallar address
            if (!Program.DaemonClient.IsAddressValid(PublicAddress))
            {
                // handle invalid public address
                await LogHandlerService.LogUserActionAsync(Context, $"Tried to withdraw but PublicAddress ({PublicAddress}) is invalid.");

                await Context.RespondAsync($"{Context.User.Mention}: Seems like you tried withdrawing Dallar to an invalid Dallar address. You supplied: {PublicAddress}");

                DiscordHelpers.DeleteNonPrivateMessage(Context);
                return;
            }

            // Try to interpret the user's amount input as a sane value
            if (!DallarHelpers.TryParseUserAmountString(Context.User, AmountStr, out decimal Amount))
            {
                // handle amount parse fail
                await LogHandlerService.LogUserActionAsync(Context, $"Tried to withdraw {Amount} but value could not be parsed.");

                await Context.RespondAsync($"{Context.User.Mention}: The amount you tried to withdraw can not be parsed as a number. You tried withdrawing {Amount} DAL.");

                DiscordHelpers.DeleteNonPrivateMessage(Context);
                return;
            }

            // Make sure Amount is greater than zero
            if (Amount <= 0)
            {
                await LogHandlerService.LogUserActionAsync(Context, $"Tried to withdraw {Amount} but value is invalid.");

                await Context.RespondAsync($"{Context.User.Mention}: You can not withdraw 0 or less Dallar. You tried withdrawing {Amount} DAL.");

                DiscordHelpers.DeleteNonPrivateMessage(Context);
                return;
            }

            // Verify user has requested balance to withdraw
            if (!DallarHelpers.CanUserAffordTransactionAmount(Context.User, Amount))
            {
                // user can not afford requested withdraw amount
                await LogHandlerService.LogUserActionAsync(Context, $"Tried to withdraw {Amount} but has insufficient funds. ({Program.DaemonClient.GetRawAccountBalance(Context.User.Id.ToString())})");

                await Context.RespondAsync($"{Context.User.Mention}: Looks like you don't have enough funds withdraw {Amount} DAL! Remember, there is a {Program.SettingsHandler.Dallar.Txfee} DAL fee for performing bot transactions.");

                DiscordHelpers.DeleteNonPrivateMessage(Context);
                return;
            }

            // Amount should be guaranteed a good value to withdraw
            // Fetch user's wallet
            if (Program.DaemonClient.GetWalletAddressFromAccount(Context.User.Id.ToString(), true, out string Wallet))
            {
                if (Program.DaemonClient.SendMinusFees(Context.User.Id.ToString(), PublicAddress, Amount, Program.SettingsHandler.Dallar.Txfee, Program.SettingsHandler.Dallar.FeeAccount))
                {
                    // Successfully withdrew
                    await LogHandlerService.LogUserActionAsync(Context, $"Successfully withdrew {Amount} from wallet ({Wallet}).");

                    await Context.RespondAsync($"You have successfully withdrawn {Amount} DAL" + (Context.Member == null ? "." : $" to address {PublicAddress}."));
                }
                else
                {   // unable to send dallar
                    await LogHandlerService.LogUserActionAsync(Context, $"Tried to withdraw {Amount} from wallet ({Wallet}) but daemon failed to send transaction.");

                    await Context.RespondAsync("Something went wrong trying to send your Dallar through the Dallar daemon. (Please contact the Administrators!)");

                    DiscordHelpers.DeleteNonPrivateMessage(Context);
                    return;
                }
            }
            else
            {   // unable to fetch user's wallet
                await LogHandlerService.LogUserActionAsync(Context, $"Tried to withdraw {Amount} but bot could not determine user's wallet.");

                await Context.RespondAsync("Something went wrong trying to get your DallarBot Dallar Address. (Please contact the Administrators!)");

                DiscordHelpers.DeleteNonPrivateMessage(Context);
                return;
            }

            // After withdraw success
            DiscordHelpers.DeleteNonPrivateMessage(Context);
        }
Exemplo n.º 2
0
        // The 'real' send function that all sends should filter into
        public async Task SendDallarToUserInternal(CommandContext Context, [Description("Amount of Dallar to send")] string AmountStr, DiscordMember Member, bool IsRandomSend = false)
        {
            await Context.TriggerTypingAsync();

            string RandomUserString = IsRandomSend ? " to a random user" : "";

            // Error out if this is a private message
            if (Context.Member == null)
            {
                await LogHandlerService.LogUserActionAsync(Context, $"Tried to send Dallar{RandomUserString} but user not in a guild.");

                await Context.RespondAsync($"{Context.User.Mention}: You must be in a Discord server with DallarBot to give to others.");

                return;
            }

            if (!DallarHelpers.TryParseUserAmountString(Context.User, AmountStr, out decimal Amount))
            {
                await LogHandlerService.LogUserActionAsync(Context, $"Tried to send Dallar but could not parse amount: {AmountStr}");

                await Context.RespondAsync($"{Context.User.Mention}: Could not parse amount.");

                return;
            }

            // Error out if trying to send an invalid amount
            if (Amount <= 0)
            {
                await LogHandlerService.LogUserActionAsync(Context, $"Tried to send Dallar{RandomUserString} but sender requested something less than or equal to zero.");

                await Context.RespondAsync($"{Context.User.Mention}: You can not send negative or zero Dallars.");

                _ = Context.Message.DeleteAsync();
                return;
            }

            // Error out if user is trying to send to themselves
            if (Context.User.Id == Member.Id)
            {
                await LogHandlerService.LogUserActionAsync(Context, $"Tried to send Dallar to themselves.");

                await Context.RespondAsync($"{Context.User.Mention}: You can not send Dallar to yourself.");

                _ = Context.Message.DeleteAsync();
                return;
            }

            // Failed to get senders wallet?
            if (!Program.DaemonClient.GetWalletAddressFromAccount(Context.User.Id.ToString(), true, out string FromWallet))
            {
                await LogHandlerService.LogUserActionAsync(Context, $"Tried to send Dallar{RandomUserString} but can not get sender's wallet.");

                await Context.RespondAsync($"{Context.User.Mention}: DallarBot failed to get your wallet. Please contact an Administrator.");

                _ = Context.Message.DeleteAsync();
                return;
            }

            // Failed to get receiver's wallet?
            if (!Program.DaemonClient.GetWalletAddressFromAccount(Member.Id.ToString(), true, out string ToWallet))
            {
                await LogHandlerService.LogUserActionAsync(Context, $"Tried to send Dallar{RandomUserString} but can not get receiver's wallet. Receiver: {Member.Id.ToString()} ({Member.Username.ToString()})");

                await Context.RespondAsync($"{Context.User.Mention}: DallarBot failed to get your wallet. Please contact an Administrator.");

                _ = Context.Message.DeleteAsync();
                return;
            }

            // Can user afford transaction?
            if (!DallarHelpers.CanUserAffordTransactionAmount(Context.User, Amount))
            {
                await LogHandlerService.LogUserActionAsync(Context, $"Tried to send {Amount} DAL{RandomUserString} but could not afford it.");

                await Context.RespondAsync($"{Context.User.Mention}: You do not have {Amount} DAL to send.");

                _ = Context.Message.DeleteAsync();
                return;
            }

            // Were we able to successfully send the transaction?
            if (Program.DaemonClient.SendMinusFees(Context.User.Id.ToString(), ToWallet, Amount, Program.SettingsHandler.Dallar.Txfee, Program.SettingsHandler.Dallar.FeeAccount))
            {
                bool bDisplayUSD = false;
                // if (Program.DigitalPriceExchange.GetPriceInfo(out DigitalPriceCurrencyInfo PriceInfo, out bool bPriceStale))
                // {
                //     bDisplayUSD = true;
                // }

                await LogHandlerService.LogUserActionAsync(Context, $"Sent {Amount} DAL ${(IsRandomSend ? "randomly " : "")}to User {Member.Id.ToString()} ({Member.Username.ToString()}) with address {ToWallet}.");

                string ReplyStr = $"{Context.User.Mention}: You have successfully {(IsRandomSend ? "randomly " : "")}sent {Member.Mention} {Amount} DAL.";

                if (bDisplayUSD)
                {
                    //ReplyStr += $" {decimal.Round(Amount * PriceInfo.USDValue.GetValueOrDefault(), 4)} USD)";
                }

                await Context.RespondAsync(ReplyStr);

                _ = Context.Message.DeleteAsync();
                return;
            }
            else
            {   // sending failed?
                await LogHandlerService.LogUserActionAsync(Context, $"Failed to have daemon send{RandomUserString} {Amount} DAL to User {Member.Id.ToString()} ({Member.Username.ToString()}) with address {ToWallet}.");

                await Context.RespondAsync($"{Context.User.Mention}: DallarBot has failed to send{RandomUserString} {Amount} DAL. Please contact an Administrator.");

                _ = Context.Message.DeleteAsync();
                return;
            }
        }