Esempio n. 1
0
        public async Task Process(SocketUserMessage msg)
        {
            var em = new EmbedBuilder()
                     .WithAuthor("Seed Node Information", Globals.Client.CurrentUser.GetAvatarUrl())
                     .WithDescription("The latest seed node status")
                     .WithColor(Color.DarkMagenta)
                     .WithThumbnailUrl(Globals.Client.CurrentUser.GetAvatarUrl());

            int x = 0;

            foreach (var s in AtomBotConfig.SeedNodes)
            {
                ++x;

                try
                {
                    NodeInfo    ni = null;
                    RequestData rd = await Request.Http($"{s}/api/daemon/get_info/");

                    if (!rd.IsError)
                    {
                        ni = JsonConvert.DeserializeObject <JsonResult <NodeInfo> >(rd.ResultString).Result;
                    }

                    em.AddField($"Seed {x}", GetSeedInfoString(ni), true);
                }
                catch
                {
                    em.AddField($"Seed {x}", "Not Available", true);
                    continue;
                }
            }

            await DiscordResponse.Reply(msg, embed : em.Build());
        }
Esempio n. 2
0
        public async Task Process(SocketUserMessage msg)
        {
            RequestData rd = await Request.Http("https://getnerva.org/getbinaries.php");

            if (!rd.IsError)
            {
                var json = JsonConvert.DeserializeObject <LinkData>(rd.ResultString);

                var em = new EmbedBuilder()
                         .WithAuthor("Download Links", Globals.Client.CurrentUser.GetAvatarUrl())
                         .WithDescription($"Current CLI: {json.CliVersion}\nCurrent GUI: {json.GuiVersion}")
                         .WithColor(Color.DarkPurple)
                         .WithThumbnailUrl("https://getnerva.org/content/images/dropbox-logo.png");

                StringBuilder sb = new StringBuilder();

                sb.AppendLine($"Windows: [CLI]({json.BinaryUrl}binaries/{json.WindowsLink}) | [GUI]({json.BinaryUrl}binaries/{json.WindowsGuiLink})");
                sb.AppendLine($"Linux: [CLI]({json.BinaryUrl}binaries/{json.LinuxLink}) | [GUI]({json.BinaryUrl}binaries/{json.LinuxGuiLink})");
                sb.AppendLine($"MacOS: [CLI]({json.BinaryUrl}binaries/{json.MacLink}) | [GUI]({json.BinaryUrl}binaries/{json.MacGuiLink})");

                em.AddField($"Nerva Tools", sb.ToString());

                sb = new StringBuilder();
                sb.AppendLine($"[Bootstrap]({json.BinaryUrl}bootstrap/mainnet.raw) | [QuickSync]({json.BinaryUrl}bootstrap/quicksync.raw)");

                em.AddField($"Chain Data", sb.ToString());

                await DiscordResponse.Reply(msg, embed : em.Build());
            }
        }
Esempio n. 3
0
        public async Task Process(SocketUserMessage msg)
        {
            RequestData rd = await Request.Api(AtomBotConfig.SeedNodes, "daemon/get_generated_coins", msg.Channel);

            if (!rd.IsError)
            {
                ulong coins = JsonConvert.DeserializeObject <JsonResult <GetGeneratedCoins> >(rd.ResultString).Result.Coins;
                await DiscordResponse.Reply(msg, text : $"Current Supply: {coins.FromAtomicUnits()}");
            }
        }
Esempio n. 4
0
        public async Task Process(SocketUserMessage msg)
        {
            RequestData rd = await Request.Api(AtomBotConfig.SeedNodes, "daemon/get_block_count", msg.Channel);

            if (!rd.IsError)
            {
                ulong count = JsonConvert.DeserializeObject <JsonResult <GetBlockCount> >(rd.ResultString).Result.Count;
                await DiscordResponse.Reply(msg, text : $"Current height: {count}");
            }
        }
Esempio n. 5
0
        public async Task Process(SocketUserMessage msg)
        {
            var matches = Regex.Matches(msg.Content.ToLower(), @"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}");

            if (matches.Count == 0)
            {
                await DiscordResponse.Reply(msg, text : "Need an IP to unban!");

                return;
            }

            foreach (var m in matches)
            {
                bool   partialFail = false;
                bool   allFail     = true;
                string ip          = m.ToString();

                foreach (var s in AtomBotConfig.SeedNodes)
                {
                    RequestData rd = await Request.Http($"{s}/api/daemon/set_bans/?ip={ip}&ban=false&time=0");

                    if (!rd.IsError)
                    {
                        allFail = false;
                    }
                    else
                    {
                        partialFail = true;
                    }
                }

                string result = null;

                if (allFail)
                {
                    result = $"An error occurred attempting to unban IP {ip}";
                }
                else if (partialFail)
                {
                    result = $"IP {ip} could not be unbanned from all seed nodes";
                }
                else
                {
                    result = $"IP {ip} unbanned successfully";
                }

                await DiscordResponse.Reply(msg, text : result);
            }
        }
Esempio n. 6
0
        public async Task Process(SocketUserMessage msg)
        {
            var em = new EmbedBuilder()
                     .WithAuthor("Help", Globals.Client.CurrentUser.GetAvatarUrl())
                     .WithDescription("How can I can help you today?")
                     .WithColor(Color.DarkBlue)
                     .WithThumbnailUrl(Globals.Client.CurrentUser.GetAvatarUrl());

            foreach (var h in Globals.BotHelp)
            {
                em.AddField(h.Key, h.Value);
            }

            await DiscordResponse.Reply(msg, embed : em.Build());
        }
Esempio n. 7
0
        public async Task Process(SocketUserMessage msg)
        {
            var em = new EmbedBuilder()
                     .WithAuthor("Web Links", Globals.Client.CurrentUser.GetAvatarUrl())
                     .WithDescription("Need more NERVA information?")
                     .WithColor(Color.DarkGrey)
                     .WithThumbnailUrl(Globals.Client.CurrentUser.GetAvatarUrl());

            em.AddField("Website", "[getnerva.org](https://getnerva.org/)", true);
            em.AddField("Twitter", "[@NervaCurrency](https://twitter.com/NervaCurrency)", true);
            em.AddField("Reddit", "[r/Nerva](https://www.reddit.com/r/Nerva)", true);
            em.AddField("Source Code", "[BitBucket](https://bitbucket.org/nerva-project)", true);
            em.AddField("NERVA Stats", "[FreeBoard](https://freeboard.io/board/EV5-se)", true);
            em.AddField("Block Explorer", "[explorer.getnerva.org](https://explorer.getnerva.org/)", true);
            em.AddField("CPU Benchmarks", "[Forkmaps.com](https://forkmaps.com/#/benchmarks)", true);
            em.AddField("Public Node hosted by Hooftly", "[pubnodes.com](https://www.pubnodes.com/) | [Explorer](https://xnvex.pubnodes.com)");

            await DiscordResponse.Reply(msg, embed : em.Build());
        }
Esempio n. 8
0
        private void WebsocketAuthenticate(string token)
        {
            var authData = new DiscordResponse
            {
                Operation = 2,
                Data      = new DiscordResponseData
                {
                    Token          = token,
                    Properties     = new Dictionary <string, string>(),
                    Compress       = false,
                    LargeThreshold = 250
                }
            };

            var authDataString = JsonConvert.SerializeObject(authData);

            //Log.Write($"Sending auth data string: {authDataString}");

            _websocketClient.Send(authDataString);
        }
Esempio n. 9
0
        public async Task Process(SocketUserMessage msg)
        {
            var em = new EmbedBuilder()
                     .WithAuthor("Make A Donation", Globals.Client.CurrentUser.GetAvatarUrl())
                     .WithDescription("Would you like to make a donation?\n" +
                                      "If you would like to remain anonymous, please omit the payment id")
                     .WithColor(Color.Gold)
                     .WithThumbnailUrl(Globals.Client.CurrentUser.GetAvatarUrl());

            foreach (var j in ((FusionBotConfig)(Globals.Bot.Config)).AccountJson.Accounts)
            {
                if (j.Display)
                {
                    em.AddField($"__{j.Name}__", $"{j.Address}\n\u200b");
                }
            }

            em.AddField("Payment ID", $"{IdEncrypter.Encrypt(msg.Author.Id, 0)}\n\u200b");

            await DiscordResponse.Reply(msg, privateOnly : true, embed : em.Build());
        }
Esempio n. 10
0
        public async Task Process(SocketUserMessage msg)
        {
            RequestData rd = await Request.Http("https://tradeogre.com/api/v1/ticker/btc-xnv");

            if (!rd.IsError)
            {
                var json = JsonConvert.DeserializeObject <MarketInfo>(rd.ResultString);

                var em = new EmbedBuilder()
                         .WithAuthor("TradeOgre Details", Globals.Client.CurrentUser.GetAvatarUrl())
                         .WithDescription("The latest pricing from TradeOgre")
                         .WithColor(Color.DarkGreen)
                         .WithThumbnailUrl("https://getnerva.org/content/images/tradeogre-logo.png");

                em.AddField("Volume", Math.Round(json.Volume, 5));
                em.AddField("Buy", json.Ask * 100000000.0d, true);
                em.AddField("Sell", json.Bid * 100000000.0d, true);
                em.AddField("High", json.High * 100000000.0d, true);
                em.AddField("Low", json.Low * 100000000.0d, true);

                await DiscordResponse.Reply(msg, embed : em.Build());
            }
        }
Esempio n. 11
0
        public async Task Process(SocketUserMessage msg)
        {
            RequestData rd = await Request.Api(AtomBotConfig.SeedNodes, "daemon/get_info", msg.Channel);

            if (!rd.IsError)
            {
                float  hr        = JsonConvert.DeserializeObject <JsonResult <NodeInfo> >(rd.ResultString).Result.Difficulty / 120.0f;
                string formatted = $"{hr} h/s";

                float kh = (float)Math.Round(hr / 1000.0f, 2);
                float mh = (float)Math.Round(hr / 1000000.0f, 2);
                if (mh > 1)
                {
                    formatted = $"{mh} mh/s";
                }
                else
                {
                    formatted = $"{kh} kh/s";
                }

                await DiscordResponse.Reply(msg, text : $"Current nethash: {formatted}");
            }
        }
Esempio n. 12
0
        public async Task Process(SocketUserMessage msg)
        {
            //Use a HashSet here as the adding items is slower, but lookups to check for dups are
            //orders of magnitude faster.
            HashSet <string> banList = new HashSet <string>();

            foreach (var sn in AtomBotConfig.SeedNodes)
            {
                RequestData rd = await Request.Http($"{sn}/api/daemon/get_bans/");

                if (!string.IsNullOrEmpty(rd.ResultString))
                {
                    List <BanListItem> bl = JsonConvert.DeserializeObject <JsonResult <BanList> >(rd.ResultString).Result.Bans;

                    foreach (var b in bl)
                    {
                        if (!banList.Contains(b.Host))
                        {
                            banList.Add(b.Host);
                        }
                    }
                }
            }

            //Discord has a 2000 character message limit. It may be possible to exceed this if the ban list is large
            //So a mod to this code to split the ban list into smaller chunks may be appropriate, however the risk of
            //exceeding the character limit is small, making this a job for another day
            StringBuilder sb = new StringBuilder();

            foreach (string s in banList)
            {
                sb.AppendLine(s);
            }

            await DiscordResponse.Reply(msg, text : sb.ToString());
        }
Esempio n. 13
0
        public async Task Process(SocketUserMessage msg)
        {
            RequestData rd = await Request.Http("https://api.coingecko.com/api/v3/coins/nerva?localization=false");

            if (!rd.IsError)
            {
                var json = JsonConvert.DeserializeObject <CoinGeckoInfo>(rd.ResultString);

                var em = new EmbedBuilder()
                         .WithAuthor("CoinGecko Details", Globals.Client.CurrentUser.GetAvatarUrl())
                         .WithDescription("The latest scores and rankings from CoinGecko")
                         .WithColor(Color.DarkTeal)
                         .WithThumbnailUrl("https://getnerva.org/content/images/coingecko-logo.png");

                em.AddField("CoinGecko Rank", json.CoinGeckoRank, true);
                em.AddField("CoinGecko Score", json.CoinGeckoScore, true);
                em.AddField("Market Cap Rank", json.MarketCapRank, true);
                em.AddField("Community Score", json.CommunityScore, true);
                em.AddField("Developer Score", json.DeveloperScore, true);
                em.AddField("Public Interest Score", json.PublicInterestScore, true);

                await DiscordResponse.Reply(msg, embed : em.Build());
            }
        }
Esempio n. 14
0
        public async Task Process(SocketUserMessage msg)
        {
            FusionBotConfig                 cfg       = ((FusionBotConfig)Globals.Bot.Config);
            GetAccountsResponseData         balances  = null;
            List <GetTransfersResponseData> transfers = new List <GetTransfersResponseData>();

            await new GetAccounts(null, (GetAccountsResponseData result) =>
            {
                balances = result;
            }, null, cfg.WalletHost, cfg.DonationWalletPort).RunAsync();

            if (balances == null)
            {
                await DiscordResponse.Reply(msg, text : "Sorry. Couldn't retrieve the donation account balances...");

                return;
            }

            foreach (var a in cfg.AccountJson.Accounts)
            {
                if (!a.Display)
                {
                    transfers.Add(null);
                    continue;
                }

                await new GetTransfers(new GetTransfersRequestData
                {
                    AccountIndex = (uint)a.Index
                }, (GetTransfersResponseData result) =>
                {
                    transfers.Add(result);
                }, null, cfg.WalletHost, cfg.DonationWalletPort).RunAsync();
            }

            if (cfg.AccountJson.Accounts.Length != transfers.Count)
            {
                await DiscordResponse.Reply(msg, text : "Sorry. Couldn't retrieve the donation account balances...");

                return;
            }

            EmbedBuilder eb = new EmbedBuilder()
                              .WithAuthor("Donation Account Balances", Globals.Client.CurrentUser.GetAvatarUrl())
                              .WithDescription("These are the balances of all the donation accounts")
                              .WithColor(Color.Red)
                              .WithThumbnailUrl(Globals.Client.CurrentUser.GetAvatarUrl());

            for (int i = 0; i < cfg.AccountJson.Accounts.Length; i++)
            {
                var a = cfg.AccountJson[i];

                if (!a.Display)
                {
                    continue;
                }

                var bb = balances.Accounts[i].UnlockedBalance;
                var tt = transfers[i];

                StringBuilder sb = new StringBuilder();

                foreach (var t in tt.Incoming.OrderByDescending(x => x.Height).Take(5))
                {
                    ulong s, r;
                    IdEncrypter.Decrypt(t.PaymentId, out s, out r);
                    sb.AppendLine($"{s.ToMention()}: {t.Amount.FromAtomicUnits()}");
                }

                sb.AppendLine("\u200b");

                ulong outTotal = 0;
                foreach (var o in tt.Outgoing)
                {
                    outTotal += o.Amount;
                }

                eb.AddField($"{a.Name}: {bb.FromAtomicUnits()} XNV ({outTotal.FromAtomicUnits()} out)", sb.ToString());
            }

            await DiscordResponse.Reply(msg, embed : eb.Build());
        }
Esempio n. 15
0
 public async Task Process(SocketUserMessage msg)
 {
     await DiscordResponse.Reply(msg, text : "Pong!");
 }
Esempio n. 16
0
 public static extern void Respond(string userId, DiscordResponse reply);