The bot monitors and controls the computer via telegrams

What bot are you talking about?


This is a bot that I myself wrote using Python.

If you write the bot “s”, the bot will take a screenshot and send it back to you.

If the bot writes “question xxxxxxxxxxxxxxxx?”, Where xxxxxxxxxxxxxxxx is your question, then a window will open on the entire computer screen in which your question is written and the answer form, after which the person will have the opportunity to write the answer to your question and click “Submit” , after which the bot will return to you what the person answered.

You can also write anything to the bot, and on the computer a dialog box opens with a “ok” button and the contents that you wrote.

How i used this bot


I launched it before I left the store, then I just went into the telegram to the bot and took screenshots. So my younger brother sat at the computer, and began to do his work there.
Then I wrote the following message to the bot: “the question, why did you sit down at the computer?”, And it looked like this:

image

Well, we corresponded with him there and upon arrival home we agreed that he wouldn’t do this anymore :)

How did I write it?


I have known Python for a long time, and I know it well, so it was not difficult to write such a bot.
For more or less programmers.

I used libraries: telebot, PyQt5, sys, tkinter, pyautogui, and that's all, that was enough for me.

Here is the source code for the program:

import telebot as TL#          
from PyQt5.QtWidgets import QMessageBox#    messagebox     
import PyQt5#     
import sys#     
from tkinter import *#     ,          
from pyautogui import screenshot#    pyautogui   

token = input("  : ")

def vopros(mess,msg):#     
    def ok_btn(entr,msg,root):#     ,       ""
        msg = msg
        root = root
        msg(": "+entr.get())
        root.destroy()
    root = Tk()#   tkinter  
    root.geometry("200x200")#   
    root.attributes("-fullscreen",True)# ,         
    root.lift()#   lift,     
    lab = Label(root,text=mess)# ,          
    entr = Entry(root)#  
    btn_ok = Button(text="",command=lambda: ok_btn(entr,msg,root))#  "",     "ok_btn",     :  ,   ,  
    lab.pack()# 
    entr.pack()#  
    btn_ok.pack()##  ""
    root.mainloop()#  


def msg_mean(mess):#      
    newApp = PyQt5.QtWidgets.QApplication(sys.argv)#    PyQt5
    msg = QMessageBox()#   
    msg.setWindowTitle("")#     
    msg.setText(mess)#   ,    
    msg.setIcon(QMessageBox.Critical)#    
    x = msg.exec_()# 

bot = TL.TeleBot(token)#  "bot",     
@bot.message_handler(commands=['start'])#   bot  
def start_message(message):#        
                           #      ,    start 
                           #   
    bot.send_message(message.chat.id, ',  :)')#    " "

@bot.message_handler(content_types=['text'])#   bot  
def send_text(message):#    ()      
    def msg(message_text):#     
        bot.send_message(message.chat.id, str(message_text))#  id    ,          
    def snd_doc(name_doc):#     "msg",      (      )
        bot.send_document(message.chat.id, open(name_doc,"rb"))
    if message.text[:6] == "":#         "",      
        vopros(message.text,msg)#        
    else:#  
        if message.text == "s":#    "s"
            screen = screenshot('s.jpg')#   
            snd_doc("s.jpg")#      "snd_doc" 
        else:#      "s"    "",     
            msg_mean(message.text)#        


while True:#      
    try:
        bot.polling()#  
    except(BaseException):
        pass#   
    #         
    #      


As you can see, the bot is not complicated, but there are bugs:

  • it can be easily disabled through the task manager,
  • if you send a lot of messages, then it just flies.

And some person can connect to your bot (if he knows what your bot’s name is) and observe the computer.

Fortunately, I know how to fix it, and maybe fix it if you like such a bot.

What happens in the bot?


First, I initialize all the libraries that the bot will use.

import telebot as TL#          
from PyQt5.QtWidgets import QMessageBox#    messagebox     
import PyQt5#     
import sys#     
from tkinter import *#     ,          
from pyautogui import screenshot#    pyautogui   

Next, I create a question function:

def vopros(mess,msg):#     
    def ok_btn(entr,msg,root):#     ,       ""
        msg = msg
        root = root
        msg(": "+entr.get())
        root.destroy()
    root = Tk()#   tkinter  
    root.geometry("200x200")#   
    root.attributes("-fullscreen",True)# ,         
    root.lift()#   lift,     
    lab = Label(root,text=mess)# ,          
    entr = Entry(root)#  
    btn_ok = Button(text="",command=lambda: ok_btn(entr,msg,root))#  "",     "ok_btn",     :  ,   ,  
    lab.pack()# 
    entr.pack()#  
    btn_ok.pack()##  ""
    root.mainloop()#  

Next, I create a function that will display a message to the user on the PC:

def msg_mean(mess):#      
    newApp = PyQt5.QtWidgets.QApplication(sys.argv)#    PyQt5
    msg = QMessageBox()#   
    msg.setWindowTitle("")#     
    msg.setText(mess)#   ,    
    msg.setIcon(QMessageBox.Critical)#    
    x = msg.exec_()# 

Then you can do the telegram and the bot itself, create a bot:

bot = TL.TeleBot(token)#  "bot",     

And I create the first function that will respond to the "/ start" command in the telegram:

def start_message(message):#        
                           #      ,    start 
                           #   
    bot.send_message(message.chat.id, ',  :)')#    " "

Then we also work with telegrams, and now we create a function that will receive a message from the user:

@bot.message_handler(content_types=['text'])#   bot  
def send_text(message):#    ()      

And in it we create two functions, these are msg and snd_doc.

    def msg(message_text):#     
        bot.send_message(message.chat.id, str(message_text))#  id    ,          
    def snd_doc(name_doc):#     "msg",      (      )
        bot.send_document(message.chat.id, open(name_doc,"rb"))

Then we receive a message from the bot user, and check what he wanted:

    if message.text[:6] == "":#         "",      
        vopros(message.text,msg)#        
    else:#  
        if message.text == "s":#    "s"
            screen = screenshot('s.jpg')#   
            snd_doc("s.jpg")#      "snd_doc" 
        else:#      "s"    "",     
            msg_mean(message.text)#        

It remains only to launch the bot:

while True:#      
    try:
        bot.polling()#  
    except(BaseException):
        pass#   
    #         
    #      

That's all, that's how it works.

How to use such a bot?


It may seem complicated, but if you do everything according to the instructions, then nothing complicated.

instruction


Find in the telegram of the bot called @BotFather,
it looks like this: image
Next, write him a command to create a new bot, the command looks like this: / newbot

image
Next, call your bot as you want, but you need to name it individually, i.e. so that there is no such bot in the world, for example: BotStepana3215.



Next, you will need to come up with the name of your bot, and be sure to prefix “bot”, for example, I’ll call my one like this: BotStepana3215_bot:



And @BotFather will give you the token of your bot, it looks like this:



This token cannot be given to anyone else, because it can change the bot.

And it remains to copy the token, save it somewhere in a text file (it is more convenient to copy from there), run the program and enter the token there.

And now you can write to your bot that you just created (it can be found in the search for telegrams by last name, in my case @ BotStepana3215_bot), and everything that I listed from its functionality will work for you.

Where to get such a bot?


Here I have .exe and .py on github

But .exe is only for windows 10.

Enjoy the program and write reviews.

Good luck

All Articles