botgram / shell-bot

:robot: Telegram bot that executes commands and sends the live output
GNU General Public License v3.0
787 stars 493 forks source link

Multiple session #66

Open killerlearner opened 1 year ago

killerlearner commented 1 year ago

Can you make it so bot can handle multiple active cmd. At present it don't let use other cmds when one running at background

andrewlytvyn commented 1 year ago

I ask a question to the chatGPT

killerlearner commented 1 year ago

What question O⁠_⁠o

andrewlytvyn commented 1 year ago

To implement the ability for a bot to handle multiple active commands, you would need to create multiple instances of command handling or utilize a concept of "threading" or "parallel processing." This is a significant programming task that would require a solid understanding of node.js (the language this bot appears to be written in) and asynchronous programming principles.

Here's a high-level approach of how you might go about it:

  1. Task Queue: Create a queue for incoming commands. Whenever a command is issued, add it to the queue. This ensures that no commands are lost if multiple commands are issued simultaneously.

  2. Command Handler: Create a command handler that runs on a separate thread or process. This handler should be able to take a command from the queue and execute it. The handler should also be able to handle multiple commands at once. This can be achieved by creating a new thread or process for each command, or by using asynchronous programming techniques to allow the handler to work on multiple commands at the same time.

  3. Output Handling: Ensure that the output from each command is handled correctly. This could involve sending the output back to the user who issued the command, or storing it in a location where it can be accessed later.

  4. Error Handling: Make sure to handle errors properly. If a command fails to execute, the handler should be able to recover and move on to the next command.

  5. Concurrency Control: Implement concurrency control mechanisms to prevent race conditions and other concurrency-related issues. This could involve using locks or other synchronization techniques.

Note that this is a high-level description and the actual implementation would require a deeper understanding of the specific bot's code and the node.js language. If you are not familiar with these concepts, you might want to consider seeking help from a professional developer or a community of developers knowledgeable in node.js and bot development.

However, it's also important to note that running multiple commands concurrently could have security and resource implications. For instance, if the bot is running on a server with limited resources, running too many commands at once could overload the server. Similarly, if commands are not properly isolated from each other, one command could potentially interfere with the execution of another, leading to unexpected behavior or security vulnerabilities. It's crucial to consider these factors when designing and implementing this feature.

killerlearner commented 1 year ago

Yup that's what we need ;)

killerlearner commented 1 year ago

It's alright in current mirror bots we just need someone who can develop it for shell bot using mirror bot code as example ig. IMG_20230527_101940 As you can see in this img that there is a sh for every background process