Exemple #1
0
        public void GetMessage()
        {
            if (Users == null)
            {
                Users = new TelegramMembers();
            }

            var json      = tAPI.sendAPIRequest("getUpdates", $"offset={lastUpdateId}");
            var apiResult = JsonConvert.DeserializeObject <APIResult>(json);

            if ((apiResult == null) || (apiResult.Result == null))
            {
                return;
            }

            foreach (var update in apiResult.Result)
            {
                if (!BotHelpers.CheckUpdate(update))
                {
                    continue;
                }

                User newUser = new User();
                newUser.ID        = update.message.chat.id;
                newUser.FirstName = update.message.chat.first_name;
                newUser.LastName  = update.message.chat.last_name;

                // log

                Logger.Log($"Получен апдейт от {update.message.chat.first_name} {update.message.chat.last_name} id {update.message.chat.id} текст: {update.message.text}");
                lastUpdateId = update.update_id + 1;

                // Commands

                if (CheckCommandsForBot(newUser, update.message.text))
                {
                    return;
                }

                // Check user

                if (Users.CheckUser(newUser))
                {
                    SendMessageAll($"{newUser.FirstName} {newUser.LastName} : {update.message.text}", newUser.ID);
                }
                else
                {
                    SendMessage("Введите пароль:", newUser.ID);
                }
            }
        }
Exemple #2
0
        private bool PingCommand(User _newUser, string _text)
        {
            Host tmpHost = new Host(BotHelpers.GetHostNamefromText(_text));

            if (tmpHost.IP != string.Empty)
            {
                if (Pinger.PingHost(tmpHost))
                {
                    SendMessage($"Ping host <{tmpHost.IP}> - OK! Time: {tmpHost.pingTime} ms.", _newUser.ID);
                }
                else
                {
                    SendMessage($"Ping host <{tmpHost.IP}> - FAIL!", _newUser.ID);
                }
            }
            else
            {
                SendMessage($"Неверный формат команды PING.", _newUser.ID);
            }
            return(true);
        }
Exemple #3
0
 public void SendMessageAll(string _text, int authorID)
 {
     for (int i = 0; i < Users.GetCount(); i++)
     {
         if (Users.GetUserID(i) != authorID)
         {
             tAPI.sendAPIRequest("sendMessage", $"chat_id={Users.GetUserID(i)}&text={BotHelpers.CheckText(_text)}");
         }
     }
 }
Exemple #4
0
 public void SendMessageAll(List <string> _mails)
 {
     foreach (string text in _mails)
     {
         for (int i = 0; i < Users.GetCount(); i++)
         {
             tAPI.sendAPIRequest("sendMessage", $"chat_id={Users.GetUserID(i)}&text={BotHelpers.CheckText(text)}");
         }
     }
 }
Exemple #5
0
 public void SendMessage(string _text, int _idChat)
 {
     tAPI.sendAPIRequest("sendMessage", $"chat_id={_idChat}&text={BotHelpers.CheckText(_text)}");
 }