public async Task BTCToDallar(CommandContext Context, [Description("Optional amount of BTC to covert to Dallar, default is 1")] params decimal[] Amount) { decimal ParsedAmount = 1m; if (Amount.Length > 0) { ParsedAmount = Amount[0]; } await LogHandlerService.LogUserActionAsync(Context, $"Invoked BTC command with amount {ParsedAmount}."); if (true)//!Program.DigitalPriceExchange.GetPriceInfo(out DigitalPriceCurrencyInfo PriceInfo, out bool bPriceStale)) { await DiscordHelpers.PromptUserToDeleteMessage(Context, $"{Context.User.Mention}: It appears that Dallar Bot is unable to evaluate the price of Dallar at the moment. Perhaps an exchange is down?"); return; } await Context.TriggerTypingAsync(); var Info = "error"; //String.Format("{0:#,##0.00000000}", ParsedAmount) + " BTC is " + String.Format("{0:#,##0.00000000}", decimal.Round(ParsedAmount / PriceInfo.Price, 8)) + " DAL."; if (true) //bPriceStale) { Info += "\n:warning: Info potentially out of date due to Exchange API lag."; } await DiscordHelpers.PromptUserToDeleteMessage(Context, $"{Context.User.Mention}: {Info}"); }
public async Task GetDallarDeposit(CommandContext Context) { if (Program.DaemonClient.GetWalletAddressFromAccount(Context.User.Id.ToString(), true, out string Wallet)) { DiscordEmbedBuilder EmbedBuilder = new DiscordEmbedBuilder(); EmbedBuilder.WithTitle("Dallar Bot Depositing Help"); EmbedBuilder.WithDescription("DallarBot is a Discord bot dedicated to allowing individual users on the server to easily tip each other in the chatbox. It generates a wallet for every Discord user, and you can withdraw into any address any time." + Environment.NewLine + Environment.NewLine + "Dallar Bot does not access anyone's wallets directly in order to protect everyone's privacy."); EmbedBuilder.AddField("Warning About Storage", "Dallar Bot should not be used as a long term storage for your Dallar. Dallar Bot is only accessible through Discord and if the Bot or Discord are down for any reason, you will *not* be able to access your stored Dallar."); EmbedBuilder.AddField("Dallar Bot Fees", $"All transactions with Dallar Bot incur a flat {Program.SettingsHandler.Dallar.Txfee} DAL fee to cover the Dallar blockchain transaction fees as well as funding and maintenance costs sent to the Dallar Bot server hoster."); EmbedBuilder.AddField("Blockchain Transactions", $"Dallar Bot uses the blockchain to keep track of its transactions, meaning your transactions will require 6 confirmation blocks before they are completed. This should take approximately 5 to 10 minutes under normal Dallar network conditions."); EmbedBuilder.AddField("Depositing", $"You can deposit Dallar into your Dallar Bot balance by sending Dallar to this address generated specifically for you: `{Wallet}`"); EmbedBuilder.WithImageUrl($"https://api.qrserver.com/v1/create-qr-code/?data=dallar:{Wallet}&qzone=2"); await LogHandlerService.LogUserActionAsync(Context, $"Fetched deposit info."); await DiscordHelpers.RespondAsDM(Context, EmbedBuilder.Build()); } else { await DiscordHelpers.RespondAsDM(Context, $"{Context.User.Mention}: Failed to fetch your wallet address. Please contact an Administrator."); await LogHandlerService.LogUserActionAsync(Context, $"Failed to fetch deposit info."); } DiscordHelpers.DeleteNonPrivateMessage(Context); }
public async Task FetchAllarJoke(CommandContext Context) { await LogHandlerService.LogUserActionAsync(Context, "Invoked Allar Joke"); if (!await DiscordHelpers.AttemptChargeDallarForCommand(Context, 1)) { await LogHandlerService.LogUserActionAsync(Context, "Failed charged for Allar Joke"); return; } await LogHandlerService.LogUserActionAsync(Context, "Successfully charged for Allar Joke"); await Context.TriggerTypingAsync(); var httpClient = new HttpClient(); var content = await httpClient.GetStringAsync("http://api.icndb.com/jokes/random?firstName=Michael&lastName=Allar"); try { dynamic jokeResult = JsonConvert.DeserializeObject(content); string joke = jokeResult.value.joke; joke = System.Net.WebUtility.HtmlDecode(joke); await Context.RespondAsync($"{Context.User.Mention} : {joke}"); } catch { await LogHandlerService.LogUserActionAsync(Context, "Failed to perform Allar Joke"); await Context.RespondAsync($"{Context.User.Mention}: Failed to fetch joke. Please contact an Administrator."); } }
public async Task GetDallarDifficulty(CommandContext Context) { await Context.TriggerTypingAsync(); int BlockCount = Program.DaemonClient.GetBlockCount(); float Difficulty = Program.DaemonClient.GetDifficulty(); await LogHandlerService.LogUserActionAsync(Context, $"Fetched block details. {BlockCount} with difficulty {Difficulty}."); await Context.RespondAsync($"{Context.User.Mention}: Difficulty for block {BlockCount}: {Difficulty}"); }
public async Task GiveAFuck(CommandContext Context) { if (DiscordHelpers.IsUserAdmin(Context) || DiscordHelpers.IsUserModerator(Context) || DiscordHelpers.IsUserDallarDevTeam(Context)) { await LogHandlerService.LogUserActionAsync(Context, "Invoked GiveAFuck"); await Context.TriggerTypingAsync(); await Context.RespondAsync(":regional_indicator_g: :regional_indicator_i: :regional_indicator_v: :regional_indicator_e: :a: :regional_indicator_f: :regional_indicator_u: :regional_indicator_c: :regional_indicator_k:"); } }
public async Task FetchMommaJoke(CommandContext Context) { await LogHandlerService.LogUserActionAsync(Context, "Invoked mom joke."); if (!await DiscordHelpers.AttemptChargeDallarForCommand(Context, 1)) { await LogHandlerService.LogUserActionAsync(Context, "Failed charged for mom Joke"); return; } await LogHandlerService.LogUserActionAsync(Context, "Successfully charged for mom Joke"); await Context.TriggerTypingAsync(); await Context.RespondAsync($"{Context.User.Mention}: {Program.YoMommaJokes.GetRandomYoMommaJoke()}"); }
public async Task GetAccountBalance(CommandContext Context) { await Context.TriggerTypingAsync(); bool bDisplayUSD = false; // if (Program.DigitalPriceExchange.GetPriceInfo(out DigitalPriceCurrencyInfo PriceInfo, out bool bPriceStale)) // { // bDisplayUSD = true; // } if (Program.DaemonClient.GetWalletAddressFromAccount(Context.User.Id.ToString(), true, out string Wallet)) { decimal balance = Program.DaemonClient.GetRawAccountBalance(Context.User.Id.ToString()); decimal pendingBalance = Program.DaemonClient.GetUnconfirmedAccountBalance(Context.User.Id.ToString()); string pendingBalanceStr = pendingBalance != 0 ? $" with {pendingBalance} DAL Pending" : ""; string resultStr = $"{Context.User.Mention}: Your balance is {balance} DAL"; if (bDisplayUSD) { //resultStr += $" (${decimal.Round(balance * PriceInfo.USDValue.GetValueOrDefault(), 4)} USD){pendingBalanceStr}"; } else { resultStr += pendingBalanceStr; } await LogHandlerService.LogUserActionAsync(Context, $"Checked balance. {balance} DAL with {pendingBalance} DAL pending."); await Context.RespondAsync(resultStr); } else { await LogHandlerService.LogUserActionAsync(Context, $"Failed to check balance. Getting wallet address failed."); await Context.RespondAsync($"{Context.User.Mention}: Failed to check balance. Getting wallet address failed. Please contact an Administrator."); } DiscordHelpers.DeleteNonPrivateMessage(Context); }
public async Task FetchDadJoke(CommandContext Context) { await LogHandlerService.LogUserActionAsync(Context, "Invoked Dad Joke"); if (!await DiscordHelpers.AttemptChargeDallarForCommand(Context, 1)) { await LogHandlerService.LogUserActionAsync(Context, "Failed charged for dad Joke"); return; } await LogHandlerService.LogUserActionAsync(Context, "Successfully charged for dad Joke"); await Context.TriggerTypingAsync(); var client = new WebClient(); client.Headers.Add("Accept", "text/plain"); var joke = await client.DownloadStringTaskAsync("https://icanhazdadjoke.com/"); await Context.RespondAsync($"{Context.User.Mention} : {joke}"); }
public async Task DallarValueInfo(CommandContext Context, [Description("Optional amount of DAL to covert to BTC and USD, default is 1")] params decimal[] Amount) { await Context.TriggerTypingAsync(); decimal ParsedAmount = 1m; if (Amount.Length > 0) { ParsedAmount = Amount[0]; } await LogHandlerService.LogUserActionAsync(Context, $"Invoked DAL command with amount {ParsedAmount}."); if (true)//!Program.DigitalPriceExchange.GetPriceInfo(out DigitalPriceCurrencyInfo PriceInfo, out bool bPriceStale)) { await DiscordHelpers.PromptUserToDeleteMessage(Context, $"{Context.User.Mention}: It appears that Dallar Bot is unable to evaluate the price of Dallar at the moment. Perhaps an exchange is down?"); return; } // float.TryParse(PriceInfo.PriceChange.TrimEnd('%'), out float PercentChange); // string ChangeEmoji = PercentChange >= 0.0f ? ":chart_with_upwards_trend:" : ":chart_with_downwards_trend:"; // decimal UsdValue = PriceInfo.USDValue.GetValueOrDefault(); // var Info = $"{ParsedAmount} DAL to BTC: {decimal.Round((PriceInfo.Price * ParsedAmount), 8, MidpointRounding.AwayFromZero):F8} BTC" + Environment.NewLine + // $"{ParsedAmount} DAL to USD: ${UsdValue * ParsedAmount} :dollar:" + Environment.NewLine + // $"24 Hour Stats: :arrow_down_small: {decimal.Round((PriceInfo.Low.GetValueOrDefault() * 100000000.0m), 0, MidpointRounding.AwayFromZero)} sats / :arrow_up_small: {decimal.Round((PriceInfo.High.GetValueOrDefault() * 100000000.0m), 0, MidpointRounding.AwayFromZero)} sats / :arrows_counterclockwise: {PriceInfo.VolumeMarket} BTC" + Environment.NewLine + // $"{ChangeEmoji} {PriceInfo.PriceChange} Change in 24 Hours"; // if (bPriceStale) // { // Info += "\n:warning: Info potentially out of date due to Exchange API lag."; // } //await DiscordHelpers.PromptUserToDeleteMessage(Context, $"{Context.User.Mention}: {Info}"); }
public async Task SendRandomUserInternal(CommandContext Context, decimal Amount, UserStatus MinimumStatus = UserStatus.Offline) { await Context.TriggerTypingAsync(); await LogHandlerService.LogUserActionAsync(Context, $"Invoked sending {Amount} to a random user with minimum status {MinimumStatus.ToString()}."); var Members = DiscordHelpers.GetHumansInContextGuild(Context, true, MinimumStatus); int randomIndex = Program.RandomManager.GetRandomInteger(0, Members.Count() - 1); var Member = Members.ElementAt(randomIndex); if (Member.Value != null) { await SendDallarToUserInternal(Context, Amount.ToString(), Member.Value, true); } else { // failed to get random member? await LogHandlerService.LogUserActionAsync(Context, $"Failed to get a random user from the guild."); await Context.RespondAsync($"{Context.User.Mention}: DallarBot has failed to get a random user from the guild. Please contact an Administrator."); _ = Context.Message.DeleteAsync(); } }
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); }
// 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; } }
static async Task MainAsync(string[] args) { Console.WriteLine(LogHandlerService.CenterString("▒█▀▀▄ █▀▀█ █░░ █░░ █▀▀█ █▀▀█ ▒█▀▀█ █▀▀█ ▀▀█▀▀ ")); Console.WriteLine(LogHandlerService.CenterString("▒█░▒█ █▄▄█ █░░ █░░ █▄▄█ █▄▄▀ ▒█▀▀▄ █░░█ ░░█░░ ")); Console.WriteLine(LogHandlerService.CenterString("▒█▄▄▀ ▀░░▀ ▀▀▀ ▀▀▀ ▀░░▀ ▀░▀▀ ▒█▄▄█ ▀▀▀▀ ░░▀░░ ")); Console.WriteLine(); Console.WriteLine(LogHandlerService.CenterString("----------------------------")); Console.WriteLine(); Console.WriteLine(LogHandlerService.CenterString("Initializing bot...")); DiscordClient = new DiscordShardedClient(new DiscordConfiguration { Token = SettingsHandler.Discord.BotToken, TokenType = TokenType.Bot, MinimumLogLevel = Microsoft.Extensions.Logging.LogLevel.Information, }); //DiscordClient.DebugLogger.LogMessageReceived += LogHandlerService.DiscordLogMessageReceived; DiscordClient.MessageCreated += async(s, e) => { if (e.Message.Content.ToLower().StartsWith("ping")) { await e.Message.RespondAsync("pong!"); } }; await DiscordClient.UseCommandsNextAsync(new CommandsNextConfiguration { StringPrefixes = new string[] { "d!" }, EnableDms = true, EnableMentionPrefix = true, EnableDefaultHelp = false }); var Values = await DiscordClient.GetCommandsNextAsync(); foreach (System.Collections.Generic.KeyValuePair <int, CommandsNextExtension> CommandsModule in Values) { CommandsModule.Value.RegisterCommands <HelpCommands>(); CommandsModule.Value.RegisterCommands <TipCommands>(); CommandsModule.Value.RegisterCommands <MiscCommands>(); CommandsModule.Value.RegisterCommands <ExchangeCommands>(); CommandsModule.Value.RegisterCommands <DallarCommands>(); CommandsModule.Value.SetHelpFormatter <HelpFormatter>(); CommandsModule.Value.CommandErrored += async(s, e) => { // first command failure on boot throws a null exception. Not sure why? // Afterwards, this event logic always seems to work okay without error if (e.Exception is ChecksFailedException) { return; } if (e.Command == null) { return; } await LogHandlerService.LogUserActionAsync(e.Context, "Failed to invoke " + e.Command.ToString()); DiscordChannel Channel = e.Context.Channel; if (e.Context.Member != null) { Channel = await e.Context.Member.CreateDmChannelAsync(); } //await e.Context.Client.GetCommandsNext().SudoAsync(e.Context.User, Channel, "d!help " + e.Command.Name); DiscordHelpers.DeleteNonPrivateMessage(e.Context); }; } await DiscordClient.UseInteractivityAsync(new InteractivityConfiguration { }); await DiscordClient.StartAsync(); await Task.Delay(-1); }