Browse Source

Небольшие правки, добавлено использование логина и пароля как аргументов запуска

Veloe 4 years ago
parent
commit
2854032501
1 changed files with 21 additions and 12 deletions
  1. 21 12
      EthermineBotTelegram/Program.cs

+ 21 - 12
EthermineBotTelegram/Program.cs

@@ -24,16 +24,26 @@ namespace EthermineBotTelegram
             botClient = new TelegramBotClient("1785154817:AAGhXD9yQVn9HPdWTcmGJUBeZ8nA50SzHbY");
             var me = botClient.GetMeAsync().Result;
             
-            
-            
             Console.WriteLine(
                 $"Hello, World! I am user {me.Id} and my name is {me.FirstName}."
             );
             
-            //here will be enstablishing connection to DB
-            string user = Console.ReadLine();
-            string pass = Console.ReadLine();
-
+            //creating connection to DB
+            string user;
+            string pass;
+            if (args[0] != null && args[1] != null)
+            {
+                user = args[0];
+                pass = args[1];
+            }
+            else
+            {
+                Console.Out.Write("User:");
+                user = Console.ReadLine();
+                Console.Out.Write("Password:");
+                pass = Console.ReadLine();
+            }
+            
             Botdb =
                 new botdb("server=" + AppSettings.dbIp +  ";port=3306;database=botdb;uid=" + user + "; pwd=" + pass);
 
@@ -54,7 +64,7 @@ namespace EthermineBotTelegram
                     .WithIdentity("job1", "group1")
                     .UsingJobData("connectionString", "server=" + AppSettings.dbIp +  ";port=3306;database=botdb;uid=" + user + "; pwd=" + pass)
                     .Build();
-                // Trigger the job to run now, and then repeat every 10 seconds
+                // Trigger the job to run now, and then repeat it
                 ITrigger trigger = TriggerBuilder.Create()
                     .WithIdentity("trigger1", "group1")
                     .StartNow()
@@ -68,7 +78,7 @@ namespace EthermineBotTelegram
                 Console.WriteLine(("Scheduler started!"));
                 
                 Thread.Sleep(5000);
-                
+                //start receive messages
                 botClient.OnMessage += BotOnMessage;
                 botClient.StartReceiving();
 
@@ -138,10 +148,9 @@ namespace EthermineBotTelegram
                                     text:   "Incorrect message");
                             break;
                     }
-
             }
         }
-
+        //send reauest to pool api and gets back json than parse it and send message with data from it
         static async void GetActualData(MessageEventArgs e)
         {
             try
@@ -169,7 +178,7 @@ namespace EthermineBotTelegram
                     text:   "An exception occurred while executing this command.");
             }
         }
-        
+        //get last data from tables miners and workers from DB and send message to user
         static async void GetActualDataFromDatabase(Chat e)
         {
             //try
@@ -399,7 +408,7 @@ namespace EthermineBotTelegram
                     text:   "An exception occurred while executing this command.");
             }
         }
-
+        //gets data from pool API in json, calculates unpaid for each worker and adds it to DB
         public static async Task UpdateData()
         {
             var walletList = Botdb.users.Where(u=>u.wallet != null).Select(u=> u.wallet).Distinct().ToList();