Помогите, пожалуйста, переделать скрипт

Обсуждение ПО и его настройки
Ответить
seel2304
Сообщения: 48
Зарегистрирован: 18 фев 2021, 20:04

Всем снова добрый день) Не помню уже где, нашёл вполне себе рабочий скрипт, который парсит чат в телеграме и если видит там команду, выполняет скрипт с таким именем.
 

Код: Выделить всё

:delay 10
:global mtIdentity [/system identity get name];
:global botID "botxxxxxx" ;
:global myChatID "-xxxxxxxx" ;
:local chatId 0;
:local messageId 0;


:local parse do={
  :local startLoc ([:find $content $variable -1] + [:len $variable] + 2);
  :local commaLoc ([:find $content "," $startLoc] - 1 + 1);
  :local braceLoc ([:find $content "}" $startLoc] - 1 + 1);
  :local endLoc $commaLoc;
  :local startSymbol [:pick $content $startLoc]
  :if ($braceLoc != 0 and ($commaLoc = 0 or $braceLoc < $commaLoc)) do={
    :set endLoc $braceLoc;
  };
  :if ($startSymbol = "{") do={
    :set endLoc ($braceLoc + 1);
  };
  :if ($quotas = true) do={
    :set startLoc ($startLoc + 1);
    :set endLoc ($endLoc - 1);
  }
  :if ($endLoc < $startLoc) do={
    :set endLoc ($startLoc + 1);
  };
  :local message [:pick $content $startLoc $endLoc]
  #:log info $message;
  :return $message;
}


:while ( true ) do={
  :do {
    #:log info "https://api.telegram.org/$botID/getUpdates\?offset=$messageId&limit=1&allowed_updates=message&timeout=60";
    :tool fetch url=("https://api.telegram.org/$botID/getUpdates\?offset=$messageId&limit=1&allowed_updates=message&timeout=60") dst-path="getUpdates";
    :local content [/file get [/file find name=getUpdates] contents] ;
    #:log info $content;
    :if ([:len $content] > 30) do={
      :set messageId ([$parse content=$content variable="update_id"] + 1)
      :local message [$parse content=$content variable="text" quotas=true]
      :local chat [$parse content=$content variable="chat"]
      :local chatId [$parse content=$chat variable="id"]      
      
      :if ($chatId = $myChatID) and ([/system script find name=$message] != "")) do={
        :system script run $message;
      } else={
        :tool fetch url=("https://api.telegram.org/$botID/sendmessage\?chat_id=$chatId&text=$mtIdentity: Unknown command: $message") keep-result=no
      }
    }
  } on-error={}
};
Помогите, пожалуйста, его переработать таким образом, чтобы в чат можно было писать не имя скрипта, а сразу команду и она напрямую исполнялась бы в терминале, а в ответ от бота я бы получал (в идеале) вывод из терминала, или, хотя бы, сообщение "%Имя микрота, внешний айпи%: команда %сообщение% была исполнена".


seel2304
Сообщения: 48
Зарегистрирован: 18 фев 2021, 20:04

Пробовал делать это самостоятельно, менял строки
 

Код: Выделить всё

 
 :if ($chatId = $myChatID) and ([/system script find name=$message] != "")) do={
        :system script run $message;
      } else={
        :tool fetch url=("https://api.telegram.org/$botID/sendmessage\?chat_id=$chatId&text=$mtIdentity: Unknown command: $message") keep-result=no
на
 

Код: Выделить всё

      :if ($chatId = $myChatID) do={
        :$message;
        :tool fetch url=("https://api.telegram.org/$botID/sendmessage\?chat_id=$chatId&text=$mtIdentity: Command: $message was executed.")
      } else={
        :tool fetch url=("https://api.telegram.org/$botID/sendmessage\?chat_id=$chatId&text=$mtIdentity: Unknown command: $message") keep-result=no
, так почему-то после этого даже в Script-Environment переменные перестали записываться. Не могу понять, что я делаю не так


seel2304
Сообщения: 48
Зарегистрирован: 18 фев 2021, 20:04

Никто не сможет помочь?


seel2304
Сообщения: 48
Зарегистрирован: 18 фев 2021, 20:04

Если кто-то может выполнить данную задачу за вознаграждение, напишите, пожалуйста, в лс или здесь свои контакты


Ответить