/newbot and hereinafter. We will need the token of the new bot and your id (you can get it, for example, from @userinfobot ).telebot library ( pip install pytelegrambotapi ). With the help of the subprocess library we will execute commands on the server.nano bot.py from subprocess import check_output import telebot import time bot = telebot.TeleBot("XXXXXXXXX:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")# user_id = 0 #id @bot.message_handler(content_types=["text"]) def main(message): if (user_id == message.chat.id): #, comand = message.text # try: # - check_output exception bot.send_message(message.chat.id, check_output(comand, shell = True)) except: bot.send_message(message.chat.id, "Invalid input") # if __name__ == '__main__': while True: try:# try bot.polling(none_stop=True)# except: time.sleep(10)# check_output() function executes the passed command and returns the result.screen ( sudo apt-get install screen ): screen -dmS ServerBot python3 bot.py (where "ServerBot" is a process identifier)
from subprocess import check_output import telebot from telebot import types # import time bot = telebot.TeleBot("XXXXXXXXX:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")# user_id = 0 #id @bot.message_handler(content_types=["text"]) def main(message): if (user_id == message.chat.id): #, comand = message.text # markup = types.InlineKeyboardMarkup() # button = types.InlineKeyboardButton(text="", callback_data=comand) # markup.add(button) # try: # - check_output exception bot.send_message(user_id, check_output(comand, shell = True, reply_markup = markup)) # except: bot.send_message(user_id, "Invalid input") # @bot.callback_query_handler(func=lambda call: True) def callback(call): comand = call.data # data try:# - check_output exception markup = types.InlineKeyboardMarkup() # button = types.InlineKeyboardButton(text="", callback_data=comand) # data markup.add(button) # bot.send_message(user_id, check_output(comand, shell = True), reply_markup = markup) # except: bot.send_message(user_id, "Invalid input") # if __name__ == '__main__': while True: try:# try bot.polling(none_stop=True)# except: time.sleep(10)# killall python3 screen -dmS ServerBot python3 bot.py 
Source: https://habr.com/ru/post/443846/
All Articles