public async Task DifficultyAsync([Remainder] string Remainder = "") { decimal Difficulty = TrtlBotSharp.GetDifficulty(); // Send reply await ReplyAsync(string.Format("The current difficulty is **{0:N0}**", Difficulty)); }
public async Task RedirectTipsAsync(bool Redirect, [Remainder] string Remainder = "") { // Delete original message try { await Context.Message.DeleteAsync(); } catch { } // Check that user has registered an address if (!TrtlBotSharp.CheckUserExists(Context.Message.Author.Id)) { await Context.Message.Author.SendMessageAsync(string.Format("You must register a wallet before you can recieve tips! Use {0}help if you need any help.", TrtlBotSharp.botPrefix)); } // User is registered else { // Set redirect preference TrtlBotSharp.SetRedirect(Context.Message.Author.Id, Redirect); // Send reply if (Redirect) { await Context.Message.Author.SendMessageAsync("**Tip redirect preference changed**\nTips you receive will now go to your tip jar"); } else { await Context.Message.Author.SendMessageAsync("**Tip redirect preference changed**\nTips you receive will now go to your registered wallet"); } } }
public async Task HeightAsync([Remainder] string Remainder = "") { decimal Height = TrtlBotSharp.GetHeight(); // Send reply await ReplyAsync(string.Format("The current block height is **{0:N0}**", Height)); }
public async Task HashrateAsync([Remainder] string Remainder = "") { decimal Hashrate = TrtlBotSharp.GetHashrate(); // Send reply await ReplyAsync("The current global hashrate is **" + TrtlBotSharp.FormatHashrate(Hashrate) + "**"); }
public async Task SupplyAsync([Remainder] string Remainder = "") { // Get supply decimal Supply = TrtlBotSharp.GetSupply(); // Send reply await ReplyAsync(string.Format("The current circulating supply is **{0:n8}** {1}", Supply, TrtlBotSharp.coinSymbol)); }
public async Task HashrateAsync([Remainder] string Remainder = "") { // Get last block header from daemon and calculate hashrate decimal Hashrate = 0; JObject Result = Request.RPC(TrtlBotSharp.daemonHost, TrtlBotSharp.daemonPort, "getlastblockheader"); if (Result.Count > 0 && !Result.ContainsKey("error")) { Hashrate = (decimal)Result["block_header"]["difficulty"] / 144; } // Send reply await ReplyAsync("The current global hashrate is **" + TrtlBotSharp.FormatHashrate(Hashrate) + "**"); }
public async Task DynamitAsync([Remainder] string Remainder = "") { // Get supply decimal Supply = TrtlBotSharp.GetSupply(); decimal Height = TrtlBotSharp.GetHeight(); decimal Hashrate = TrtlBotSharp.GetHashrate(); decimal Difficulty = TrtlBotSharp.GetDifficulty(); string Message = string.Format("The current block height is **{0:N0}**" + "\nThe current global hashrate is **" + TrtlBotSharp.FormatHashrate(Hashrate) + "**" + "\nThe current difficulty is **{1:N0}**" + "\nThe current circulating supply is **{2:N4}** {3}", Height, Difficulty, Supply, TrtlBotSharp.coinSymbol); await ReplyAsync(string.Format(Message)); }
[Command("wallet")] // Get by uid public async Task WalletAsync(ulong UID, [Remainder] string Remainder = "") { // Delete original message try { await Context.Message.DeleteAsync(); } catch { } // Try to grab address from the database string Address = ""; if (TrtlBotSharp.CheckUserExists(UID)) { Address = TrtlBotSharp.GetAddress(UID); } // Get requested user string Username = ""; SocketUser User = Context.Client.GetUser(UID); if (User != null) { Username = User.Username; } if (string.IsNullOrEmpty(Username)) { Username = UID.ToString(); } // Check if result is empty if (string.IsNullOrEmpty(Address)) { await Context.Message.Author.SendMessageAsync(string.Format("{0} hasn't registered a wallet!", Username)); } // Check if user is requesting their own wallet else if (Context.Message.Author.Id == UID) { await Context.Message.Author.SendMessageAsync(string.Format("**Your wallet:**```{0}```", Address)); } // User is requesting someone else's wallet else { await Context.Message.Author.SendMessageAsync(string.Format("**{0}'s wallet:**```{1}```", Username, Address)); } }
// Gets page source public static JObject GET(string Host) { JObject Result = new JObject(); try { // Create a disposable web client using (WebClient client = new WebClient()) { // Get response Result = JObject.Parse(client.DownloadString(Host)); } } catch { TrtlBotSharp.Log(2, "TrtlBotSharp", "Failed while fetching data from host {0}", Host); } return(Result); }
public async Task DepositAsync([Remainder] string Remainder = "") { // Delete original message try { await Context.Message.DeleteAsync(); } catch { } // Check if user exists in user table if (!TrtlBotSharp.CheckUserExists(Context.Message.Author.Id)) { await Context.Message.Author.SendMessageAsync(string.Format("You must register a wallet before you can deposit! Use {0}help if you need any help.", TrtlBotSharp.botPrefix)); } // Send reply else { await Context.Message.Author.SendMessageAsync(string.Format("**Deposit {0} to start tipping!**```Address:\n{1}\n\nPayment ID:\n{2}```", TrtlBotSharp.coinSymbol, TrtlBotSharp.tipDefaultAddress, TrtlBotSharp.GetPaymentId(Context.Message.Author.Id))); } }
public async Task CalculateReward(decimal hashvalue, [Remainder] string Remainder = "") { if (!(hashvalue > 0)) { //await Context.Message.Author.SendMessageAsync(string.Format("No valid Hashrate entered !", TrtlBotSharp.coinName)); } else { decimal diff = TrtlBotSharp.GetDifficulty(); decimal avgsec = (diff / hashvalue); // max 720 blocks / day fehlt noch decimal blockperday = (86400 / avgsec); decimal rewardperday = (blockperday * 1862621) / coinUnits; await ReplyAsync(string.Format("Depending on difficulty and your hashrate you might find around **{0:N2}** Blocks per Day \n this corresponds to a reward of **{1:N4}** {2} per day", blockperday, rewardperday, TrtlBotSharp.coinSymbol)); } }
public async Task PriceAsync([Remainder] string Remainder = "") { // Begin building a response await TrtlBotSharp.GetMarketCache(); // Exchange Data var Response = new EmbedBuilder(); if (TrtlBotSharp.marketCacheArray[0] == "01/01/2019 12:00:00 PM") { Response.WithTitle("Current Price of ARMS: " + TrtlBotSharp.marketSource); Response.WithUrl(TrtlBotSharp.marketEndpoint); Response.AddInlineField("--Note--", "Data is not currently available"); } else { Response.WithTitle("Current Price of ARMS: " + TrtlBotSharp.marketSource); Response.WithUrl(TrtlBotSharp.marketEndpoint); Response.AddInlineField("Low", string.Format("{0} sats", Math.Round((decimal)decimal.Parse(TrtlBotSharp.marketCacheArray[1]) * 100000000))); Response.AddInlineField("Current", string.Format("{0} sats", Math.Round((decimal)decimal.Parse(TrtlBotSharp.marketCacheArray[3]) * 100000000))); Response.AddInlineField("High", string.Format("{0} sats", Math.Round((decimal)decimal.Parse(TrtlBotSharp.marketCacheArray[2]) * 100000000))); Response.AddInlineField(TrtlBotSharp.coinSymbol + "-USD", string.Format("${0:N5} USD", (decimal)decimal.Parse(TrtlBotSharp.marketCacheArray[3]) * (decimal)decimal.Parse(TrtlBotSharp.marketCacheArray[11]))); Response.AddInlineField("Volume BTC/USD", string.Format("{0:F4}/{1:C}", (decimal)decimal.Parse(TrtlBotSharp.marketCacheArray[4]), (decimal)decimal.Parse(TrtlBotSharp.marketCacheArray[4]) * (decimal)decimal.Parse(TrtlBotSharp.marketCacheArray[11]))); Response.AddInlineField("BTC-USD", string.Format("{0:C} USD", (decimal)decimal.Parse(TrtlBotSharp.marketCacheArray[11]))); DateTime cachedDate = DateTime.Parse(TrtlBotSharp.marketCacheArray[0]); Response.AddInlineField("Data as of", string.Format("{0}", cachedDate)); } // Send Exchange data reply if (Context.Guild != null && TrtlBotSharp.marketDisallowedServers.Contains(Context.Guild.Id)) { try { await Context.Message.DeleteAsync(); } catch { } await Context.Message.Author.SendMessageAsync("", false, Response); } else { await ReplyAsync("", false, Response); } }
public async Task RegisterWalletAsync(string Address, [Remainder] string Remainder = "") { // Delete original message try { await Context.Message.DeleteAsync(); } catch { } // Check that user hasn't already registered an address if (TrtlBotSharp.CheckUserExists(Context.Message.Author.Id)) { await Context.Message.Author.SendMessageAsync(string.Format("You have already registered an address, use {0}updatewallet if you'd like to update it", TrtlBotSharp.botPrefix)); } // Check address validity else if (!TrtlBotSharp.VerifyAddress(Address)) { await Context.Message.Author.SendMessageAsync(string.Format("Address is not a valid {0} address!", TrtlBotSharp.coinName)); } // Check that address isn't in use by another user else if (TrtlBotSharp.CheckAddressExists(Address)) { await Context.Message.Author.SendMessageAsync("Address is in use by another user"); } // Passed checks else { // Register wallet into database string PaymentId = TrtlBotSharp.RegisterWallet(Context.Message.Author.Id, Address); // Begin building a response var Response = new EmbedBuilder(); Response.WithTitle("Successfully registered your wallet!"); Response.Description = string.Format("Deposit {0} to start tipping!\n\n" + "Address:\n**{1}**\n\nPayment ID:\n**{2}**", TrtlBotSharp.coinSymbol, TrtlBotSharp.tipDefaultAddress, PaymentId); // Send reply await Context.Message.Author.SendMessageAsync("", false, Response); } }
// Gets page source public static JObject GET(string Host) { JObject Result = new JObject(); try { // Create a disposable web client using (WebClient client = new WebClient()) { // Add user-agent headers client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)"); client.Timeout = 30 * 1000; // timeout after 30 seconds // Get response Result = JObject.Parse(client.DownloadString(Host)); } } catch (Exception e) { TrtlBotSharp.Log(2, "ARMSBot", "Failed while fetching data from host {0}: {1}", Host, e.Message); } return(Result); }
public async Task WithdrawAsync(string Amount, [Remainder] string Remainder = "") { // Delete original message try { await Context.Message.DeleteAsync(); } catch { } // Check if user exists in user table if (!TrtlBotSharp.CheckUserExists(Context.Message.Author.Id)) { await Context.Message.Author.SendMessageAsync(string.Format("You must register a wallet before you can withdraw! Use {0}help if you need any help.", TrtlBotSharp.botPrefix)); return; } // Check that amount is over the minimum fee else if (Convert.ToDecimal(Amount) < TrtlBotSharp.Minimum)//TrtlBotSharp.Fee) { await ReplyAsync(string.Format("Amount must be at least {0:N} {1}", TrtlBotSharp.Minimum /*Fee*/, TrtlBotSharp.coinSymbol)); return; } // Check if user has enough balance else if (TrtlBotSharp.GetBalance(Context.Message.Author.Id) < Convert.ToDecimal(Amount) + TrtlBotSharp.tipFee) { await Context.Message.Author.SendMessageAsync(string.Format("Your balance is too low! Amount + Fee = **{0:N}** {1}", Convert.ToDecimal(Amount) + TrtlBotSharp.tipFee, TrtlBotSharp.coinSymbol)); await Context.Message.AddReactionAsync(new Emoji(TrtlBotSharp.tipLowBalanceReact)); } // Send withdrawal else if (TrtlBotSharp.Tip(Context.Message.Author.Id, TrtlBotSharp.GetAddress(Context.Message.Author.Id), Convert.ToDecimal(Amount))) { // Send success react await Context.Message.AddReactionAsync(new Emoji(TrtlBotSharp.tipSuccessReact)); } }
public async Task BalanceAsync([Remainder] string Remainder = "") { // Delete original message try { await Context.Message.DeleteAsync(); } catch { } // Check if user exists in user table if (!TrtlBotSharp.CheckUserExists(Context.Message.Author.Id)) { await Context.Message.Author.SendMessageAsync(string.Format("You must register a wallet before you can check your tip jar balance! Use {0}help if you need any help.", TrtlBotSharp.botPrefix)); } // Send reply with balance else { // Get balance decimal Balance = TrtlBotSharp.GetBalance(Context.Message.Author.Id); // Send reply await Context.Message.Author.SendMessageAsync(string.Format("You have **{0:N}** {1} in your tip jar", Balance, TrtlBotSharp.coinSymbol)); } }
public async Task MarketCapAsync([Remainder] string Remainder = "") { // Begin building a response await TrtlBotSharp.GetMarketCache(); decimal CoinPrice = (decimal)Convert.ToDecimal(TrtlBotSharp.marketCacheArray[3]); // Begin building a response string Response = string.Format("{0}'s market cap is **{1:c}** USD", TrtlBotSharp.coinName, ((decimal)CoinPrice * (decimal)decimal.Parse(TrtlBotSharp.marketCacheArray[11])) * TrtlBotSharp.GetSupply()); // Send reply if (Context.Guild != null && TrtlBotSharp.marketDisallowedServers.Contains(Context.Guild.Id)) { try { await Context.Message.DeleteAsync(); } catch { } await Context.Message.Author.SendMessageAsync(Response); } else { await ReplyAsync(Response); } }
public async Task UpdateWalletAsync(string Address, [Remainder] string Remainder = "") { // Delete original message try { await Context.Message.DeleteAsync(); } catch { } // Check that user has registered an address, register it if not. if (!TrtlBotSharp.CheckUserExists(Context.Message.Author.Id)) { await RegisterWalletAsync(Address, Remainder); return; } // Check address validity else if (!TrtlBotSharp.VerifyAddress(Address)) { await Context.Message.Author.SendMessageAsync(string.Format("Address is not a valid {0} address!", TrtlBotSharp.coinName)); } // Check that address isn't in use by another user else if (TrtlBotSharp.CheckAddressExists(Address)) { await Context.Message.Author.SendMessageAsync("Address is in use by another user"); } // Passed checks else { // Update address in database TrtlBotSharp.UpdateWallet(Context.Message.Author.Id, Address); // Reply with success await Context.Message.Author.SendMessageAsync("Successfully updated your wallet"); } }
// Sends a JSON POST request to a host wallet public static JObject RPC(string Host, int Port, string Method, JObject Params = null, string Password = null) { JObject Result = new JObject(); try { // Create a POST request HttpWebRequest HttpWebRequest = (HttpWebRequest)WebRequest.Create("http://" + Host + ":" + Port + "/json_rpc"); HttpWebRequest.ContentType = "application/json-rpc"; HttpWebRequest.Method = "POST"; // Create a JSON request JObject JRequest = new JObject(); if (Params != null) { JRequest["params"] = Params; } JRequest.Add(new JProperty("jsonrpc", "2.0")); JRequest.Add(new JProperty("id", "0")); JRequest.Add(new JProperty("method", Method)); if (Password != null) { JRequest.Add(new JProperty("password", Password)); } string Request = JRequest.ToString(); if (Method != "getStatus" && TrtlBotSharp.logLevel >= 3) { Console.WriteLine(Request); } // Send bytes to server byte[] ByteArray = Encoding.UTF8.GetBytes(Request); HttpWebRequest.ContentLength = ByteArray.Length; Stream Stream = HttpWebRequest.GetRequestStream(); Stream.Write(ByteArray, 0, ByteArray.Length); Stream.Close(); // Receive reply from server WebResponse WebResponse = HttpWebRequest.GetResponse(); StreamReader reader = new StreamReader(WebResponse.GetResponseStream(), Encoding.UTF8); // Get response Result = JObject.Parse(reader.ReadToEnd()); if (Method != "getStatus" && TrtlBotSharp.logLevel >= 3) { Console.WriteLine(Result.ToString()); } if (Result.ContainsKey("result")) { Result = (JObject)Result["result"]; } // Dispose of pieces reader.Dispose(); WebResponse.Dispose(); } catch (Exception e) { TrtlBotSharp.Log(2, "traaittCASH Currency Service", "Failed while sending request to host {0}: {1}", Host, e.Message); } return(Result); }
public async Task MarketCapAsync([Remainder] string Remainder = "") { // Get current coin price JObject CoinPrice = Request.GET(TrtlBotSharp.marketEndpoint); if (CoinPrice.Count < 1) { await ReplyAsync("Failed to connect to " + TrtlBotSharp.marketSource); return; } // Get current BTC price JObject BTCPrice = Request.GET(TrtlBotSharp.marketBTCEndpoint); if (BTCPrice.Count < 1) { await ReplyAsync("Failed to connect to " + TrtlBotSharp.marketBTCEndpoint); return; } // Begin building a response string Response = string.Format("{0}'s market cap is **{1:c}** USD", TrtlBotSharp.coinName, (decimal)CoinPrice["price"] * (decimal)BTCPrice["last"] * TrtlBotSharp.GetSupply()); // Send reply if (Context.Guild != null && TrtlBotSharp.marketDisallowedServers.Contains(Context.Guild.Id)) { try { await Context.Message.DeleteAsync(); } catch { } await Context.Message.Author.SendMessageAsync(Response); } else { await ReplyAsync(Response); } }
public async Task HelpAsync([Remainder] string Remainder = "") { // Begin building a response EmbedBuilder Response = new EmbedBuilder(); Response.WithTitle("Help"); string Output = ""; // Requesting additional help if (Remainder.ToLower() == "faucet") { Response.Title += string.Format(" - {0}faucet", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}faucet", TrtlBotSharp.botPrefix)); Response.AddField("Description:", "Gives faucet information, including the donation address, a link to the faucet, and how much it has left"); } else if (Remainder.ToLower() == "hashrate") { Response.Title += string.Format(" - {0}hashrate", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}hashrate", TrtlBotSharp.botPrefix)); Response.AddField("Description:", "Gives the current network hashrate"); } else if (Remainder.ToLower() == "difficulty") { Response.Title += string.Format(" - {0}difficulty", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}difficulty", TrtlBotSharp.botPrefix)); Response.AddField("Description:", "Gives the current network difficulty"); } else if (Remainder.ToLower() == "height") { Response.Title += string.Format(" - {0}height", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}height", TrtlBotSharp.botPrefix)); Response.AddField("Description:", "Gives the current network height"); } else if (Remainder.ToLower() == "supply") { Response.Title += string.Format(" - {0}supply", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}supply", TrtlBotSharp.botPrefix)); Response.AddField("Description:", string.Format("Gives the total circulating supply of {0}", TrtlBotSharp.coinSymbol)); } else if (Remainder.ToLower() == "registerwallet") { Response.Title += string.Format(" - {0}registerwallet", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}registerwallet <{1} Address>", TrtlBotSharp.botPrefix, TrtlBotSharp.coinSymbol)); Response.AddField("Description:", "Registers your address with the bot so you may send and recieve tips"); } else if (Remainder.ToLower() == "updatewallet") { Response.Title += string.Format(" - {0}updatewallet", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}updatewallet <{1} Address>", TrtlBotSharp.botPrefix, TrtlBotSharp.coinSymbol)); Response.AddField("Description:", "Updates your registered wallet to a new address"); } else if (Remainder.ToLower() == "wallet") { Response.Title += string.Format(" - {0}uwallet", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}wallet\n{0}wallet <{1} Address>", TrtlBotSharp.botPrefix, TrtlBotSharp.coinSymbol)); Response.AddField("Description:", "Gets a specified user's registered wallet address, or your own if no address is specified"); } else if (Remainder.ToLower() == "deposit") { Response.Title += string.Format(" - {0}deposit", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}deposit", TrtlBotSharp.botPrefix)); Response.AddField("Description:", string.Format("DMs you with your deposit information, including the address to send to, " + "and the payment ID you **must** use when sending {0}", TrtlBotSharp.coinSymbol)); } else if (Remainder.ToLower() == "withdraw") { Response.Title += string.Format(" - {0}withdraw", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}withdraw <Amount of {1}>", TrtlBotSharp.botPrefix, TrtlBotSharp.coinSymbol)); Response.AddField("Description:", "Withdraws a specified amount from your tip jar into your registered wallet"); } else if (Remainder.ToLower() == "balance") { Response.Title += string.Format(" - {0}balance", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}balance", TrtlBotSharp.botPrefix, TrtlBotSharp.coinSymbol)); Response.AddField("Description:", "Gets your current tip jar balance"); } else if (Remainder.ToLower() == "tip") { Response.Title += string.Format(" - {0}tip", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}tip <Amount of {1}> @Users1 @User2...\n{0}tip <Amount of {1}> <{1} Address>", TrtlBotSharp.botPrefix, TrtlBotSharp.coinSymbol)); Response.AddField("Description:", string.Format("Sends a tip of a specified amount to one or more users *or* a specified {0} address", TrtlBotSharp.coinSymbol)); } else if (Remainder.ToLower() == "redirecttips") { Response.Title += string.Format(" - {0}redirecttips", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}redirecttips\n{0}redirecttips <True or False>", TrtlBotSharp.botPrefix)); Response.AddField("Description:", "Sets whether you'd like to have tips sent to you to go directly to your registered wallet " + "(default) or redirected into your tip jar balance"); } else if (Remainder.ToLower() == "price" && (Context.Guild == null || !TrtlBotSharp.marketDisallowedServers.Contains(Context.Guild.Id))) { Response.Title += string.Format(" - {0}price", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}price", TrtlBotSharp.botPrefix)); Response.AddField("Description:", string.Format("Gives the current price of {0} in USD and BTC", TrtlBotSharp.coinSymbol)); } else if (Remainder.ToLower() == "mcap" && (Context.Guild == null || !TrtlBotSharp.marketDisallowedServers.Contains(Context.Guild.Id))) { Response.Title += string.Format(" - {0}mcap", TrtlBotSharp.botPrefix); Response.AddField("Usage:", string.Format("{0}mcap", TrtlBotSharp.botPrefix)); Response.AddField("Description:", string.Format("Gives {0}'s current market capitalization", TrtlBotSharp.coinSymbol)); } // No requested command else { Output += "traaittCASH Currency Service:\n"; Output += " \n"; Output += "Informational:\n"; Output += " help\tLists all available commands\n"; // Output += " faucet\tGives faucet information\n"; Output += " \n"; Output += "Network:\n"; Output += " hashrate\tGives current network hashrate\n"; Output += " difficulty\tGives current network difficulty\n"; Output += " height\tGives current network height\n"; Output += " supply\tGives current circulating supply\n"; Output += " \n"; if (Context.Guild == null || !TrtlBotSharp.marketDisallowedServers.Contains(Context.Guild.Id)) { Output += "Market: enabled soon\n"; Output += " price\tGives current price\n"; Output += " mcap\tGives current global marketcap\n"; Output += " \n"; } Output += "Currency tipping:\n"; Output += " balance\tGives your current tip jar balance\n"; Output += " tip\tTips one or more users a specified amount\n"; Output += " \n"; Output += "Wallet filling:\n"; Output += " deposit\tGives information on how to deposit\n"; Output += " withdraw\tWithdraws a specified amount\n"; Output += " \n"; Output += "Wallet configuration:\n"; Output += " registerwallet\tRegisters your own wallet\n"; Output += " updatewallet\tUpdates your registered wallet\n"; Output += " wallet\tGives your wallet address / linked contact\n"; Output += " redirecttips\tSets where you want to receive tips \n"; Output = string.Format("```" + TrtlBotSharp.Prettify(Output) + "```**Note:** You can use *{0}help <Name of Command>* for " + "additional help with any command", TrtlBotSharp.botPrefix); Response.WithDescription(Output); Response.WithTitle("Available Commands:"); } // Send reply await ReplyAsync("", false, Response); }
public async Task TipAsync(string Amount, [Remainder] string Remainder = "") { // Check if user exists in user table if (!TrtlBotSharp.CheckUserExists(Context.Message.Author.Id)) { await Context.Message.Author.SendMessageAsync(string.Format("You must register a wallet before you can tip! Use {0}help if you need any help.", TrtlBotSharp.botPrefix)); return; } // Check that amount is over the minimum fee if (Convert.ToDecimal(Amount) < TrtlBotSharp.Minimum)//TrtlBotSharp.Fee) { await ReplyAsync(string.Format("Amount must be at least {0:N} {1}", TrtlBotSharp.Minimum /*Fee*/, TrtlBotSharp.coinSymbol)); return; } // Check if an address is specified instead of mentioned users string Address = ""; if (Remainder.StartsWith(TrtlBotSharp.coinAddressPrefix) && Remainder.Length == TrtlBotSharp.coinAddressLength) { Address = Remainder.Substring(0, 97); } if (TrtlBotSharp.logLevel >= 3) { Console.Write($"The wallet ADDRESS is = *{Address}*\n"); } // Check that there is at least one mentioned user if (Address == "" && Context.Message.MentionedUsers.Count < 1) { return; } // Remove duplicate mentions List <ulong> Users = new List <ulong>(); foreach (SocketUser MentionedUser in Context.Message.MentionedUsers) { Users.Add(MentionedUser.Id); if (TrtlBotSharp.logLevel >= 3) { Console.Write($"MentionedUserID = *{MentionedUser.Id}*\n"); } } Users = Users.Distinct().ToList(); // Create a list of users that have wallets List <ulong> TippableUsers = new List <ulong>(); foreach (ulong Id in Users) { if (TrtlBotSharp.CheckUserExists(Id) && Id != Context.Message.Author.Id) { TippableUsers.Add(Id); } if (TrtlBotSharp.logLevel >= 3) { Console.Write($"CheckUserExists ID = *{Id}*\n"); Console.Write($"TippableUsers Count = {TippableUsers.Count}\n"); Console.Write($"Tip Amount = {Amount}\n"); } } if (TrtlBotSharp.logLevel >= 3) { Console.Write($"Tip Fee = {TrtlBotSharp.tipFee}\n"); } // Check that user has enough balance for the tip if (Address == "" && TrtlBotSharp.GetBalance(Context.Message.Author.Id) < ((Convert.ToDecimal(Amount) * TippableUsers.Count) + TrtlBotSharp.tipFee)) { await Context.Message.Author.SendMessageAsync(string.Format("1-Your balance is too low! Amount + Fee = **{0:N}** {1}", ((Convert.ToDecimal(Amount) * TippableUsers.Count) + TrtlBotSharp.tipFee), TrtlBotSharp.coinSymbol)); await Context.Message.AddReactionAsync(new Emoji(TrtlBotSharp.tipLowBalanceReact)); } else if (TrtlBotSharp.GetBalance(Context.Message.Author.Id) < Convert.ToDecimal(Amount) + TrtlBotSharp.tipFee) { await Context.Message.Author.SendMessageAsync(string.Format("2-Your balance is too low! Amount + Fee = **{0:N}** {1}", Convert.ToDecimal(Amount) + TrtlBotSharp.tipFee, TrtlBotSharp.coinSymbol)); await Context.Message.AddReactionAsync(new Emoji(TrtlBotSharp.tipLowBalanceReact)); } // Tip has required arguments else { if (Address == "") { // Send a failed react if a user isn't found bool FailReactAdded = false; foreach (ulong User in Users) { if (User != Context.Message.Author.Id && !TippableUsers.Contains(User)) { if (!FailReactAdded) { await Context.Message.AddReactionAsync(new Emoji(TrtlBotSharp.tipFailedReact)); FailReactAdded = true; } try { // Begin building a response var Response = new EmbedBuilder(); Response.WithTitle(string.Format("{0} wants to tip you!", Context.Message.Author.Username)); Response.Description = string.Format("Register your wallet with with `{0}registerwallet <your {1} address>` " + "to get started!\nTo create a wallet head to https://turtlecoin.lol/wallet/\nExtra Help: http://docs.turtlecoin.lol/", TrtlBotSharp.botPrefix, TrtlBotSharp.coinSymbol); // Send reply await Context.Client.GetUser(User).SendMessageAsync("", false, Response); } catch { } } } // Check that there is at least one user with a registered wallet if (TippableUsers.Count > 0 && TrtlBotSharp.Tip(Context.Message.Author.Id, TippableUsers, Convert.ToDecimal(Amount), Context.Message)) { // Send success react await Context.Message.AddReactionAsync(new Emoji(TrtlBotSharp.tipSuccessReact)); } } else if (TrtlBotSharp.Tip(Context.Message.Author.Id, Address, Convert.ToDecimal(Amount))) { // Send success react await Context.Message.AddReactionAsync(new Emoji(TrtlBotSharp.tipSuccessReact)); } } }