[Command("wallet")] // Get own wallet public async Task WalletAsync([Remainder] string Remainder = "") { // Delete original message try { await Context.Message.DeleteAsync(); } catch { } // Try to grab address from the database string Address = ""; if (PlenteumBot.CheckUserExists(Context.Message.Author.Id)) { Address = PlenteumBot.GetAddress(Context.Message.Author.Id); } // Check if result is empty if (string.IsNullOrEmpty(Address)) { await Context.Message.Author.SendMessageAsync(string.Format("You haven't registered a wallet! Use {0}help if you need any help.", PlenteumBot.botPrefix)); } // Check if user is requesting their own wallet else { await Context.Message.Author.SendMessageAsync(string.Format("**Your wallet:**```{0}```", Address)); } }
[Command("wallet")] // Get by mention public async Task WalletAsync(SocketUser User, [Remainder] string Remainder = "") { // Delete original message try { await Context.Message.DeleteAsync(); } catch { } // Try to grab address from the database string Address = ""; if (PlenteumBot.CheckUserExists(User.Id)) { Address = PlenteumBot.GetAddress(User.Id); } // Check if result is empty if (string.IsNullOrEmpty(Address)) { await Context.Message.Author.SendMessageAsync(string.Format("{0} hasn't registered a wallet!", User.Username)); } // Check if user is requesting their own wallet else if (User == null || Context.Message.Author.Id == User.Id) { 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}```", User.Username, Address)); } }
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 (!PlenteumBot.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.", PlenteumBot.botPrefix)); } // User is registered else { // Set redirect preference PlenteumBot.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 SupplyAsync([Remainder] string Remainder = "") { // Get supply decimal Supply = PlenteumBot.GetSupply(); // Send reply await ReplyAsync(string.Format("The current circulating supply is **{0:N}** {1}", Supply, PlenteumBot.coinSymbol)); }
public async Task HashrateAsync([Remainder] string Remainder = "") { // Get last block header from daemon and calculate hashrate decimal Hashrate = 0; JObject Result = Request.RPC(PlenteumBot.daemonHost, PlenteumBot.daemonPort, "getlastblockheader"); if (Result.Count > 0 && !Result.ContainsKey("error")) { Hashrate = (decimal)Result["block_header"]["difficulty"] / 120; } // Send reply await ReplyAsync("The current global hashrate is **" + PlenteumBot.FormatHashrate(Hashrate) + "**"); }
// 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 { PlenteumBot.Log(2, "PlenteumBot", "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 (!PlenteumBot.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.", PlenteumBot.botPrefix)); } // Send reply else { await Context.Message.Author.SendMessageAsync(string.Format("**Deposit {0} to start tipping!**```Address:\n{1}\n\nPayment ID:\n{2}```", PlenteumBot.coinSymbol, PlenteumBot.tipDefaultAddress, PlenteumBot.GetPaymentId(Context.Message.Author.Id))); } }
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 (PlenteumBot.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", PlenteumBot.botPrefix)); } // Check address validity else if (!PlenteumBot.VerifyAddress(Address)) { await Context.Message.Author.SendMessageAsync(string.Format("Address is not a valid {0} address!", PlenteumBot.coinName)); } // Check that address isn't in use by another user else if (PlenteumBot.CheckAddressExists(Address)) { await Context.Message.Author.SendMessageAsync("Address is in use by another user"); } // Passed checks else { // Register wallet into database string PaymentId = PlenteumBot.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}**", PlenteumBot.coinSymbol, PlenteumBot.tipDefaultAddress, PaymentId); // Send reply await Context.Message.Author.SendMessageAsync("", false, Response.Build()); } }
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 (!PlenteumBot.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.", PlenteumBot.botPrefix)); return; } // Check that amount is over the minimum fee else if (Convert.ToDecimal(Amount) < PlenteumBot.Minimum)//PlenteumBot.Fee) { await ReplyAsync(string.Format("Amount must be at least {0:N} {1}", PlenteumBot.Minimum /*Fee*/, PlenteumBot.coinSymbol)); return; } // Check if user has enough balance else if (PlenteumBot.GetBalance(Context.Message.Author.Id) < Convert.ToDecimal(Amount) + PlenteumBot.tipFee) { await Context.Message.Author.SendMessageAsync(string.Format("Your balance is too low! Amount + Fee = **{0:N}** {1}", Convert.ToDecimal(Amount) + PlenteumBot.tipFee, PlenteumBot.coinSymbol)); await Context.Message.AddReactionAsync(new Emoji(PlenteumBot.tipLowBalanceReact)); } // Send withdrawal else if (PlenteumBot.Tip(Context.Message.Author.Id, PlenteumBot.GetAddress(Context.Message.Author.Id), Convert.ToDecimal(Amount))) { // Send success react await Context.Message.AddReactionAsync(new Emoji(PlenteumBot.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 (!PlenteumBot.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.", PlenteumBot.botPrefix)); } // Send reply with balance else { // Get balance decimal Balance = PlenteumBot.GetBalance(Context.Message.Author.Id); // Send reply await Context.Message.Author.SendMessageAsync(string.Format("You have **{0:N}** {1} in your tip jar", Balance, PlenteumBot.coinSymbol)); } }
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 (!PlenteumBot.CheckUserExists(Context.Message.Author.Id)) { await RegisterWalletAsync(Address, Remainder); return; } // Check address validity else if (!PlenteumBot.VerifyAddress(Address)) { await Context.Message.Author.SendMessageAsync(string.Format("Address is not a valid {0} address!", PlenteumBot.coinName)); } // Check that address isn't in use by another user else if (PlenteumBot.CheckAddressExists(Address)) { await Context.Message.Author.SendMessageAsync("Address is in use by another user"); } // Passed checks else { // Update address in database PlenteumBot.UpdateWallet(Context.Message.Author.Id, Address); // Reply with success await Context.Message.Author.SendMessageAsync("Successfully updated your wallet"); } }
private readonly Timer _timer; // 2) Add a field like this // This example only concerns a single timer. // If you would like to have multiple independant timers, // you could use a collection such as List<Timer>, // or even a Dictionary<string, Timer> to quickly get // a specific Timer instance by name. public TimerService(DiscordSocketClient client) { _timer = new Timer(async _ => { // 3) Any code you want to periodically run goes here, for example: var server = client.Guilds.Where(x => x.Name.StartsWith("Plenteum")).FirstOrDefault(); if (server != null) { if (!server.HasAllMembers) { PlenteumBot.Log(0, "PlenteumBot", "Downloading users"); await server.DownloadUsersAsync(); //ensure all users are downloaded PlenteumBot.Log(0, "PlenteumBot", "Users Downloaded"); } else { PlenteumBot.Log(0, "PlenteumBot", "Users already Downloaded"); } } }, null, TimeSpan.FromMinutes(1), // 4) Time that download users should fire TimeSpan.FromMinutes(30)); // 5) Time after which download should repeat (use `Timeout.Infinite` for no repeat) }
public async Task MarketCapAsync([Remainder] string Remainder = "") { // Get current coin price JObject CoinPrice = ((JObject)(Request.GET(PlenteumBot.marketEndpoint)["data"])); if (CoinPrice.Count < 1) { await ReplyAsync("Failed to connect to STEX API (" + PlenteumBot.marketSource + ")"); return; } // Get current BTC price JObject BTCPrice = Request.GET(PlenteumBot.marketBTCEndpoint); if (BTCPrice.Count < 1) { await ReplyAsync("Failed to connect to BTC API (" + PlenteumBot.marketBTCEndpoint + ")"); return; } // Begin building a response string Response = string.Format("{0}'s market cap is **{1:c}** USD", PlenteumBot.coinName, (decimal)CoinPrice["bid"] * (decimal)BTCPrice["last"] * PlenteumBot.GetSupply()); // Send reply if (Context.Channel != null && PlenteumBot.marketAllowedChannels.Contains(Context.Channel.Id)) { try { await Context.Message.DeleteAsync(); } catch { } await ReplyAsync(Response); } else { await Context.Message.Author.SendMessageAsync(Response); } }
public async Task TipAsync(string Amount, [Remainder] string Remainder = "") { // Check if user exists in user table if (!PlenteumBot.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.", PlenteumBot.botPrefix)); return; } // Check that amount is over the minimum fee if (Convert.ToDecimal(Amount) < PlenteumBot.Minimum) { await ReplyAsync(string.Format("Amount must be at least {0:N} {1}", PlenteumBot.Minimum /*Fee*/, PlenteumBot.coinSymbol)); return; } // Check if an address is specified instead of mentioned users string Address = ""; if (Remainder.StartsWith(PlenteumBot.coinAddressPrefix) && Remainder.Length == PlenteumBot.coinAddressLength) { Address = Remainder.Substring(0, 99); } // List <ulong> Users = new List <ulong>(); decimal tipAmount = 0; //check if "here" or "everyone" is mentioned bool multiUser = false; bool hasEveryone = false; bool hasHere = false; bool hasRoleMentions = false; if (Context.Message.MentionedRoles.Count > 0) { hasRoleMentions = true; } else { if (Context.Message.Tags.Count > 0) { foreach (var tag in Context.Message.Tags) { if (tag.Type == TagType.RoleMention || tag.Type == TagType.HereMention || tag.Type == TagType.EveryoneMention) { hasRoleMentions = true; } } } } if (string.IsNullOrEmpty(Address) && hasRoleMentions) { //first ensure we have all members downloaded if (!Context.Guild.HasAllMembers) { await Context.Guild.DownloadUsersAsync(); } foreach (var tag in Context.Message.Tags) { if (tag.Type == TagType.EveryoneMention) { //add each member to the tip foreach (var user in Context.Guild.Users) { if (!Users.Contains(user.Id) && !user.IsBot && !user.IsWebhook) //only add if they not already in the list of users { Users.Add(user.Id); } } hasEveryone = true; } else if (tag.Type == TagType.HereMention) { foreach (var user in Context.Guild.Users) { //only add if they not already in the list of users & are Online or Idle or AFK if (!Users.Contains(user.Id) && !user.IsBot && !user.IsWebhook && (user.Status == UserStatus.Online || user.Status == UserStatus.Idle || user.Status == UserStatus.AFK)) { Users.Add(user.Id); } } hasHere = true; } else if (tag.Type == TagType.RoleMention) { foreach (var role in Context.Message.MentionedRoles) { foreach (var user in Context.Guild.Users) { //only add if they not already in the list of users & are in one of the mentioned roles if (!Users.Contains(user.Id) && user.Roles.Contains(role) && !user.IsBot && !user.IsWebhook) { Users.Add(user.Id); } } } } } //get users in Mentioned Roles if there is no "RoleMention" tag and the Users List is empty if (Context.Message.MentionedRoles.Count > 0 && Users.Count == 0) { foreach (var role in Context.Message.MentionedRoles) { foreach (var user in Context.Guild.Users) { //only add if they not already in the list of users & are in one of the mentioned roles if (!Users.Contains(user.Id) && user.Roles.Contains(role)) { Users.Add(user.Id); } } } } //check if everyone or here is mentioned by a tipper who is not allowed to mention @everyone or @here //first ensure we have all members downloaded if (Users.Count <= 0) { if (!Context.Guild.HasAllMembers) { await Context.Guild.DownloadUsersAsync(); } if (Remainder.ToLower().IndexOf("@everyone") > -1 && !hasEveryone) { //everyone was mentioned by a tipper who does not have permission to mention everyone //so, discord will prevent notifying everyone, but the tip should still be sent foreach (var user in Context.Guild.Users) { if (!Users.Contains(user.Id) && !user.IsBot && !user.IsWebhook) //only add if they not already in the list of users { Users.Add(user.Id); } } } if (Remainder.ToLower().IndexOf("@here") > -1 && !hasHere) { //everyone was mentioned by a tipper who does not have permission to mention @here //so, discord will prevent notifying @here, but the tip should still be sent foreach (var user in Context.Guild.Users) { //only add if they not already in the list of users & are Online or Idle or AFK if (!Users.Contains(user.Id) && !user.IsBot && !user.IsWebhook && (user.Status == UserStatus.Online || user.Status == UserStatus.Idle || user.Status == UserStatus.AFK)) { Users.Add(user.Id); } } } } //check there are now users to tip if (Users.Count <= 0) { await Context.Message.Author.SendMessageAsync(string.Format("There were no users found with the mentioned role!", PlenteumBot.botPrefix)); await Context.Message.AddReactionAsync(new Emoji(PlenteumBot.tipFailedReact)); return; } else { //we're tipping users that do or don't have a wallet multiUser = true; } //divide the tip Amount by the number of users tipAmount = Convert.ToDecimal(Amount) / Users.Count; //ensure round down and limit to two decimal places... tipAmount = Math.Floor(tipAmount * 100) / 100; //check that the splitAmount is LESS than or equal to the specified amount.. if (tipAmount * Users.Count > Convert.ToDecimal(Amount)) { await Context.Message.Author.SendMessageAsync(string.Format("Something went wrong! The total tip amount is greater than the specified tip amount", PlenteumBot.botPrefix)); await Context.Message.AddReactionAsync(new Emoji(PlenteumBot.tipFailedReact)); return; } if (tipAmount < PlenteumBot.Minimum) { await Context.Message.Author.SendMessageAsync(string.Format("The amount you've specified would result in the individual tip amounts being less than the minimum tip amount!", PlenteumBot.botPrefix)); await Context.Message.AddReactionAsync(new Emoji(PlenteumBot.tipFailedReact)); return; } } // Check that there is at least one mentioned user if (Address == "" && Context.Message.MentionedUsers.Count < 1 && !multiUser) { return; } // Remove duplicate mentions foreach (SocketUser MentionedUser in Context.Message.MentionedUsers) { Users.Add(MentionedUser.Id); } Users = Users.Distinct().ToList(); // Create a list of users that have wallets - tippableUsers List <ulong> TippableUsers = new List <ulong>(); foreach (ulong Id in Users) { if (PlenteumBot.CheckUserExists(Id) && Id != Context.Message.Author.Id) { TippableUsers.Add(Id); } } // Check that user has enough balance for the tip if (Address == "" && PlenteumBot.GetBalance(Context.Message.Author.Id) < Convert.ToDecimal(Amount) * TippableUsers.Count + PlenteumBot.tipFee) { await Context.Message.Author.SendMessageAsync(string.Format("Your balance is too low! Amount + Fee = **{0:N}** {1}", Convert.ToDecimal(Amount) * TippableUsers.Count + PlenteumBot.tipFee, PlenteumBot.coinSymbol)); await Context.Message.AddReactionAsync(new Emoji(PlenteumBot.tipLowBalanceReact)); } else if (PlenteumBot.GetBalance(Context.Message.Author.Id) < Convert.ToDecimal(Amount) + PlenteumBot.tipFee) { await Context.Message.Author.SendMessageAsync(string.Format("Your balance is too low! Amount + Fee = **{0:N}** {1}", Convert.ToDecimal(Amount) + PlenteumBot.tipFee, PlenteumBot.coinSymbol)); await Context.Message.AddReactionAsync(new Emoji(PlenteumBot.tipLowBalanceReact)); } // Tip has required arguments else { if (Address == "") { //if the splitAmount is > 0, tp that amount instead of the specified amount if (tipAmount == 0) { tipAmount = Convert.ToDecimal(Amount); } // 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(PlenteumBot.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://wallet.plenteum.com/", PlenteumBot.botPrefix, PlenteumBot.coinSymbol); // Send reply await Context.Client.GetUser(User).SendMessageAsync("", false, Response.Build()); } catch { } } } // Check that there is at least one user with a registered wallet if (TippableUsers.Count > 0 && PlenteumBot.Tip(Context.Message.Author.Id, TippableUsers, tipAmount, Context.Message)) { // Send success react await Context.Message.AddReactionAsync(new Emoji(PlenteumBot.tipSuccessReact)); } } else if (PlenteumBot.Tip(Context.Message.Author.Id, Address, Convert.ToDecimal(Amount))) { // Send success react await Context.Message.AddReactionAsync(new Emoji(PlenteumBot.tipSuccessReact)); } } }
// 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" && PlenteumBot.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" && PlenteumBot.logLevel >= 3) { Console.WriteLine(Result.ToString()); } if (Result.ContainsKey("result")) { Result = (JObject)Result["result"]; } // Dispose of pieces reader.Dispose(); WebResponse.Dispose(); } catch (Exception e) { PlenteumBot.Log(2, "PlenteumBot", "Failed while sending request to host {0}: {1}", Host, e.Message); } return(Result); }