Browse Source

Добавил команду для вывода курса #EBT-17

Veloe 4 years ago
parent
commit
2f1a909e32

+ 1 - 0
EthermineBotTelegram/EthermineBotTelegram.csproj

@@ -160,6 +160,7 @@
     <Compile Include="JsonCurrentStats.cs" />
     <Compile Include="JsonDownloader.cs" />
     <Compile Include="JsonWorker.cs" />
+    <Compile Include="NetworkStats.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>

+ 23 - 0
EthermineBotTelegram/NetworkStats.cs

@@ -0,0 +1,23 @@
+namespace NetworkStatsData
+{
+    // Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse); 
+    public class Data
+    {
+        public int time { get; set; }
+        public double blockTime { get; set; }
+        public long difficulty { get; set; }
+        public long hashrate { get; set; }
+        public double usd { get; set; }
+        public double btc { get; set; }
+    }
+}
+
+
+namespace EthermineBotTelegram
+{
+    public class NetworkStats
+        {
+            public string status { get; set; }
+            public NetworkStatsData.Data data { get; set; }
+        }
+}

+ 25 - 0
EthermineBotTelegram/Program.cs

@@ -123,6 +123,11 @@ namespace EthermineBotTelegram
                             GetActualData(e);
                             break;
                         
+                        // get actual data from ethermine
+                        case "/rate":
+                            GetActualRate(e);
+                            break;
+                        
                         // send help
                         case "/help":
                             //await SendHelp();
@@ -163,6 +168,26 @@ namespace EthermineBotTelegram
                     text:   "Something got wrong! Check entered wallet or try later.");
             }
         }
+        
+        static async void GetActualRate(MessageEventArgs e)
+        {
+            try
+            {
+                var url = AppSettings.poolApiUrl + "/networkStats";
+                var networkStats = JsonDownloader._download_serialized_json_data<NetworkStats>(url);
+                await botClient.SendTextMessageAsync(
+                    chatId: e.Message.Chat,
+                    text: "ETH: " + networkStats.data.usd + "\n" 
+                          + "BTC: " + Math.Round(networkStats.data.usd / networkStats.data.btc, 2)
+                );
+            }
+            catch (Exception)
+            {
+                await botClient.SendTextMessageAsync(
+                    chatId: e.Message.Chat,
+                    text:   "Something got wrong! Check entered wallet or try later.");
+            }
+        }
 
         static async void AddUser(Chat e)
         {