|
@@ -121,7 +121,10 @@ namespace EthermineBotTelegram
|
|
|
|
|
|
// get actual data from ethermine
|
|
|
case "/actual":
|
|
|
- GetActualData(e);
|
|
|
+ if (message.Text.Length > 7)
|
|
|
+ GetActualData(e);
|
|
|
+ else
|
|
|
+ GetActualDataFromDatabase(e.Message.Chat);
|
|
|
break;
|
|
|
|
|
|
// get actual data from ethermine
|
|
@@ -133,7 +136,7 @@ namespace EthermineBotTelegram
|
|
|
case "/help":
|
|
|
//await SendHelp();
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
default:
|
|
|
//await Usage(message);
|
|
|
await botClient.SendTextMessageAsync(
|
|
@@ -170,6 +173,83 @@ namespace EthermineBotTelegram
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ static async void GetActualDataFromDatabase(Chat e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var wallet = Botdb.users.Where(u => u.chat_id == e.Id).Select(u => u.wallet).FirstOrDefault();
|
|
|
+ if (wallet != null)
|
|
|
+ {
|
|
|
+ var lastMinerRecord = Botdb.miners.Where(w => w.wallet == wallet)
|
|
|
+ .OrderByDescending(w => w.time)
|
|
|
+ .FirstOrDefault();
|
|
|
+
|
|
|
+ if (lastMinerRecord != null)
|
|
|
+ {
|
|
|
+ //var lastWorkerRecord = new workers();
|
|
|
+ var lastTime = Botdb.workers.Where(w => w.wallet == wallet)
|
|
|
+ .Max(w => w.time);
|
|
|
+
|
|
|
+ if (lastTime != null)
|
|
|
+ {
|
|
|
+ var lastWorkerRecord = Botdb.workers.Where(w => w.wallet == wallet && w.time == lastTime)
|
|
|
+ .OrderByDescending(w => w.time).ToList();
|
|
|
+ await botClient.SendTextMessageAsync(
|
|
|
+ chatId: e,
|
|
|
+ text: $"Miner {lastMinerRecord.wallet} stats\n" +
|
|
|
+ "Updated: " + DateTimeOffset.FromUnixTimeSeconds(lastMinerRecord.time)
|
|
|
+ .LocalDateTime
|
|
|
+ .ToString("f") + "\n"
|
|
|
+ + "Reported Hashrate: " +
|
|
|
+ Math.Round(lastMinerRecord.reported_hashrate / 1000000D, 3) + " MH/s\n"
|
|
|
+ + "Current Hashrate: " +
|
|
|
+ Math.Round(lastMinerRecord.current_hashrate / 1000000D, 3) + " MH/s\n"
|
|
|
+ + "Valid Shares: " + lastMinerRecord.valid_shares + "\n"
|
|
|
+ + "Stale Shares: " + lastMinerRecord.stale_shares + "\n"
|
|
|
+ + "Unpaid Balance: " + Math.Round(lastMinerRecord.unpaid / Math.Pow(10, 18), 5) +
|
|
|
+ " ETH\n");
|
|
|
+ for (int i = 0; i < lastWorkerRecord.Count; i++)
|
|
|
+ {
|
|
|
+ await botClient.SendTextMessageAsync(
|
|
|
+ chatId: e,
|
|
|
+ text: $"Worker {lastWorkerRecord[i].worker} stats\n" +
|
|
|
+ "Updated: " + DateTimeOffset.FromUnixTimeSeconds(lastWorkerRecord[i].time)
|
|
|
+ .LocalDateTime
|
|
|
+ .ToString("f") + "\n"
|
|
|
+ + "Reported Hashrate: " +
|
|
|
+ Math.Round(lastWorkerRecord[i].reported_hashrate / 1000000D, 3) + " MH/s\n"
|
|
|
+ + "Current Hashrate: " +
|
|
|
+ Math.Round(lastWorkerRecord[i].current_hashrate / 1000000D, 3) + " MH/s\n"
|
|
|
+ + "Valid Shares: " + lastWorkerRecord[i].valid_shares + "\n"
|
|
|
+ + "Stale Shares: " + lastWorkerRecord[i].stale_shares + "\n"
|
|
|
+ + "Unpaid Balance: " +
|
|
|
+ Math.Round(lastWorkerRecord[i].worker_unpaid / Math.Pow(10, 18), 5) +
|
|
|
+ " ETH\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //no worker rows
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //no miner rows
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //no wallet exeption
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ await botClient.SendTextMessageAsync(
|
|
|
+ chatId: e,
|
|
|
+ text: "Something got wrong! Check entered wallet or try later.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
static async void GetActualRate(MessageEventArgs e)
|
|
|
{
|
|
|
try
|