Giter VIP home page Giter VIP logo

bashbot's Introduction

BashBot

BashBot is a Discord bot that provides terminal access via chat.

Features

  • Interactive. Works with nano, htop etc
  • Buttons can be used as input keys
  • Open/Close/Select/Freeze terminal sessions
  • Run terminal session as different user
  • Support for macros
  • Users whitelisting
  • ... and more

Getting Started

These instructions will get you a bot installed and running quickly

Prerequisites

  • Python 3.5+
  • pyte library (installation instructions below)
  • discord.py library (installation instructions below)

Installing

You can download BashBot.zip from Releases which contains all required dependencies and continue to "Running" section.

or you can continue with manuall installation:

Type following commands to install dependencies:

pip install -r requirements.txt

Running

In order to run bot you have to obtain a bot account. It can be obtained through the applications page. Later you have to transform your app into app bot user

Create a Bot User

then enable "Message Content Intent"

2022-09-08_03-38

After these operations, copy your bot token using the Copy button

And run

python bashbot.py

or if you downloaded BashBot release

python BashBot.zip

Now BashBot should start and show later instructions

Docker

Copy config.toml.example to config.toml file. And in the same directory run following command:

docker run -v $(pwd)/config.toml:/BashBot/config.toml adikso/bashbot

You can add -d to run container in background

docker run -d -v $(pwd)/config.toml:/BashBot/config.toml adikso/bashbot

Now BashBot should start and show later instructions

Commands

Commands are now available as app commands, but you can still use the old way:

(Every command have to start with prefix. By default it's "$". You can change it in settings. More information about commands after typing "$.help")

Command Alias Usage Description
.about - .about Shows information about project
.open .o .open [name] Opens new terminal session
.close .c .close Closes current terminal session
.freeze .f .freeze Freezes current terminal session
.here .h .here Moves selected terminal below the user message
.select .s .select [name] Sets terminal as selected
.controls - .controls add/remove [emoji] [content..] Manages terminal controls
.repeat .r .repeat <string..> Repeats string n times and sends to the current terminal session
.rename - .rename <new_name> Changes session name
.submit - .submit Toggles auto submit mode
.macro .m .macro <macro_name> Executes macro from "macros" directory
.interactive .i .interactive Enables interactive mode where all messages are sent to terminal
.exec .e .exec <command...> Execute single command
.whitelist - .whitelist add/remove <user_tag> Add/Remove user to/from whitelist. Bot owner can execute all commands without being on the whitelist

Shortcuts

Shortcut Description
[UP] Arrow up
[DOWN] Arrow down
[LEFT] Arrow left
[RIGHT] Arrow right
[ESC] Escape
[TAB] or [T] Horizontal tab
[F1]...[F12]
[<] Clears entire input line
\a Bell (BEL)
\b Backspace (BS)
\f Formfeed (FF)
\n Linefeed(Newline) (LF)
\r Carriage Return (CR)
\t Horizontal Tab (TAB)
\v Vertical Tab (VT)
^(key) CTRL + (key)

Built With

  • Discord.py - Discord API wrapper for Python
  • Pyte - VTXXX-compatible terminal emulator

Contributing

Feel free to contribute

Authors

  • Adam Zambrzycki (Adikso)

See also the list of contributors who participated in this project.

License

This project is licensed under the GNU License - see the LICENSE file for details

Acknowledgments

  • Bopke, tomangelo, RhAnjiE for testing

bashbot's People

Contributors

adikso avatar thewilloftheshadow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

bashbot's Issues

No Longer Working

Even after editing the code to fix intent errors, the bot never responds!

Suggestion: CTRL-C shortcut

I'd like to see some support for the CTRL-C shortcut, to be able to quit running apps in the terminal session. In the meantime, I suppose one can use a macro that sends the ETX character.

Does this work on Windows?

Hi there!
Whenever I try this on Windows 10 2004, I keep getting in discord "Waiting for tty.." and it never moves. Nothing shows up in logs.
Please Help!

Send a single command

I want to send a single command. How do I do that without opening a terminal?

Something like "source .bashrc" -
for just this command, I have to do

  1. $.o
  2. $source .bashrc

anything to make it one liner? I know I can use a macro. but possible to just run the command? with a prefix maybe or something?

Bot not reacting to messages

Hey there,

this is my first time using this bot, so please bare with me.

I've installed it on a Ubuntu 20.04 server, exactly according to your documentation (besides replacing pip/python-commands with pip3/python3 for obvious reasons).

It runs fine, but just doesn't do anything.

It was invited to my server, is in a channel where it has nearly all permissions but just doesn't respond to "$help", "$.help" or ".bash help". The log doesn't give any information besides that it's been started, its ID and how to invite it. Discord shows it as online.

Is there any thing I could've missed? If you need further details, please let me know what exactly and I'll happily provide it.

Bash bot permissions file not working

Hello,
I am trying to setup the permissions for the bot but i can't make it right and python always make me an error at startup here is the permissions i am "trying" to apply for now.

{
    "default": {
        "chat.write": true,
        "info.about": false,
        "info.help": true,
        "input.controls.manage": false,
        "input.repeat": false,
        "internal.settings": false,
        "permissions.manage": false,
        "permissions.manage.edit": false,
        "permissions.manage.view": false,
        "session.close": false,
        "session.freeze": false,
        "session.kill": false,
        "session.killall": false,
        "session.list": true,
        "session.move": false,
        "session.open": false,
        "session.rename": false,
        "session.select": false
    }

       "admin": {
        "chat.write": true,
        "info.about": false,
        "info.help": true,
        "input.controls.manage": false,
        "input.repeat": false,
        "internal.settings": false,
        "permissions.manage": false,
        "permissions.manage.edit": false,
        "permissions.manage.view": false,
        "session.close": false,
        "session.freeze": false,
        "session.kill": false,
        "session.killall": false,
        "session.list": true,
        "session.move": false,
        "session.open": false,
        "session.rename": false,
        "session.select": false
    }

}

When i try to run it it does this error :

Loaded `/root/.bashbot/settings.json`
Traceback (most recent call last):
  File "/usr/local/bin/bashbot", line 11, in <module>
    load_entry_point('bashbot==1.0', 'console_scripts', 'bashbot')()
  File "/usr/local/lib/python3.6/dist-packages/bashbot-1.0-py3.6.egg/bashbot/main.py", line 7, in main
  File "/usr/local/lib/python3.6/dist-packages/bashbot-1.0-py3.6.egg/bashbot/settings.py", line 65, in copy_default
  File "/usr/local/lib/python3.6/dist-packages/bashbot-1.0-py3.6.egg/bashbot/settings.py", line 27, in load
  File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.6/json/decoder.py", line 355, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 23 column 8 (char 632)
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f8f8d889a90>


Listen to Discord Server channel

Hi, I would appreciate any help. I set the bot working to dm, macros with live terminal, etc. but I cannot make bot listen and interact into a discord server channel even when I configured roles for the bot.

Thank you.

Terminal not starting

I am trying to open a terminal and the bot responds with "waiting for tty" and a terminal never opens.

Unable to install using setup.py or installing the dependacies on RaspberryPi

When running the command sudo python setup.py I get an error about encoding
error text:

Processing dependencies for bashbot==1.0
Searching for websockets>=3.1,<4.0
Reading https://pypi.python.org/simple/websockets/
Best match: websockets 3.4
Downloading https://pypi.python.org/packages/4a/e8/acf36f117deeb18c0b6679624fa11                                                                                        b57b0876044f0ce3f34024c3a7b2d95/websockets-3.4.tar.gz#md5=3586aa49a9e6da35759da0                                                                                        92d5c79c18
Processing websockets-3.4.tar.gz
Writing /tmp/easy_install-peGAAr/websockets-3.4/setup.cfg
Running websockets-3.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-peGAAr                                                                                        /websockets-3.4/egg-dist-tmp-tgvu6J
Traceback (most recent call last):
  File "setup.py", line 17, in <module>
    "bashbot = bashbot.main:main",
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/install.py", line 67                                                                                        , in run
    self.do_egg_install()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/install.py", line 11                                                                                        7, in do_egg_install
    cmd.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", li                                                                                        ne 393, in run
    self.easy_install(spec, not self.no_deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", li                                                                                        ne 617, in easy_install
    return self.install_item(None, spec, tmpdir, deps, True)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", li                                                                                        ne 668, in install_item
    self.process_distribution(spec, dist, deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", li                                                                                        ne 716, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 631, in resolve
    dist = best[req.key] = env.best_match(req, ws, installer)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 874, in best_ma                                                                                        tch
    return self.obtain(req, installer)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 886, in obtain
    return installer(requirement)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", li                                                                                        ne 636, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", li                                                                                        ne 666, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", li                                                                                        ne 856, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", li                                                                                        ne 1078, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", li                                                                                        ne 1063, in run_setup
    run_setup(setup_script, args)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 68, in run                                                                                        _setup
    DirectorySandbox(setup_dir).run(runner)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 114, in ru                                                                                        n
    return func()
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 67, in run                                                                                        ner
    _execfile(setup_script, ns)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 43, in _ex                                                                                        ecfile
    exec(code, globals, locals)
  File "/tmp/easy_install-peGAAr/websockets-3.4/setup.py", line 11, in <module>
    license="MIT",
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 243, in _o                                                                                        pen
    return _open(path,mode,*args,**kw)
TypeError: 'encoding' is an invalid keyword argument for this function

When not using setup.py I get a different error relating to encoding after installing the dependencies and running python bashbot.py

error text

File "bashbot.py", line 12
SyntaxError: Non-ASCII character '\xe2' in file bashbot.py on line 12, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Add ability to scroll or Make tty Height totally flexible ( Feature Request )

I am running a bash script through BashBot and the script has quite many options to be displayed . BashBot generated tty in discord only lets me see the bottom half of the script ( it first shows the top half and then immediately shows the bottom half )

So is it possible to add a scrollbar to the terminal .If not , you can make the tty screen height unlimited ( ie. When a user opens tty and starts any process , it can display everything from start to end without replacing older text and tty height can be as long as it needs to be ). I don't know if you might have a better solution to this problem but it would really great have this issue addressed

Thank you

Error starting a terminal.

When i type"$.open name", it returns a message saying it is starting, but in the console, it has a python error on line 58 in sessions.py execute_async(message.edit, content=content). It says that "Nonetype has no attribute 'edit'". I presume that "Nonetype" is the message. I've tried a lot of things, but it always returns the same message. First time using this bot, and help would be appreciated. Thanks!

Sir, Error! HELP ME

I got this output when i start the bot via python bashbot.py (rewrite repo)

[2019-11-24 02:20:52] WARNING:discord.client: PyNaCl is not installed, voice will NOT be supported
[2019-11-24 02:20:52] INFO:discord.client: logging in using static token
[2019-11-24 02:20:52] INFO:discord.client: Cleaning up tasks.
[2019-11-24 02:20:52] INFO:discord.client: Closing the event loop.
[2019-11-24 02:20:52] ERROR:Launcher: Improper token has been passed.

I have tried your both repo, master and rewrite, both have the same error. I give the correct token. (Bot token)

.sh files

so in my friend's server i wanted to run a bash bot for the whitelist program (for a minecraft server) made of shell script as it is made of shell script others can't run it so i decided to use this bot but it didn't work so i tried sh script.sh -asd (the code)

Ignoring exception in on_message Traceback (most recent call last): File "/home/clerickx/.local/lib/python3.9/site-packages/discord/client.py", line 312, in _run_event await coro(*args, **kwargs) File "/home/clerickx/BashBot/bashbot/bot.py", line 136, in on_message await message.delete() File "/home/clerickx/.local/lib/python3.9/site-packages/discord/message.py", line 759, in delete await self._state.http.delete_message(self.channel.id, self.id) File "/home/clerickx/.local/lib/python3.9/site-packages/discord/http.py", line 241, in request raise Forbidden(r, data) discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
and then it gave me this message

Commands aren't working

When trying to type a command, it would show the output of me doing the cmd in terminal, but nothing would happen in Discord. I tried changing permissions.json and settings,json, but no luck.

Help!!!

I am trying to deploy this bot in heroku but i got this output when i ran python bashbot.py

Traceback (most recent call last):
File "bot.py", line 3, in
from bashbot.commands import CommandsManager
File "/app/bashbot.py", line 5, in
import bashbot.main
ModuleNotFoundError: No module named 'bashbot.main'; 'bashbot' is not a package
Help me

Suggestion: Make persistant controls or bulk controls add a thing

Hi, I tend to use controls quite alot, I have even set up a particular set of commands for when I want to use them so I just have to copy paste, and as you can see, it's quite long...

Arrows :

That's already 4 characters.

  • $.controls add ⬆️ [UP]
  • $.controls add ⬇️ [DOWN]
  • $.controls add ⬅️ [LEFT]
  • $.controls add ➡️ [RIGHT]

Important Keys :

3 more.

  • $.controls add ❌ [ESC]
  • $.controls add 🆑 [<]
  • $.controls add ⏭️ [TAB]

Function Keys :

And append another 12...

  • $.controls add 1️⃣ [F1]
  • $.controls add 2️⃣ [F2]
  • $.controls add 3️⃣ [F3]
  • $.controls add 4️⃣ [F4]
  • $.controls add 5️⃣ [F5]
  • $.controls add 6️⃣ [F6]
  • $.controls add 7️⃣ [F7]
  • $.controls add 8️⃣ [F8]
  • $.controls add 9️⃣ [F9]
  • $.controls add 🔟 [F10]
  • $.controls add 🅰️ [F11]
  • $.controls add 🅱️ [F12]

The rest of the escaped characters :

Add another final 7.

  • $.controls add 🔔 \a
  • $.controls add 🔙 \b
  • $.controls add ↪️ \f
  • $.controls add ↩️ \n
  • $.controls add ⤵️ \r
  • $.controls add ↔️ \t
  • $.controls add ↕️ \v

So in total, that makes us 4 + 3 + 12 + 7 = 26 keys to set, so with character count for all commands, removing whitespaces in between sections that makes us a whopping 765 characters to type.
Honestly that's almost half of discord's allowed per message character limit. That's way too much. Please either make a configuration file; a save command; a startup preset or bulk insertion. That's way too much.

Message repeatedly from whitelist add

Hello, good afternoon, I have a question
every time someone sends a message in some channel, the bot reply to that message saying that the user needs to be on the whitelist add
it will not be possible to do this command, but did everything make the user do a bot command with the prefix?

it becomes annoying anybody to send a message in the chat and the bot spam

"$.permission list" isn't working

When running "$.permission list", the following error spits out

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/discord/client.py", line 307, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "/home/adminrat/Downloads/BashBot/bashbot/bot.py", line 64, in on_message
    success = await commands_manager.execute(client, message)
  File "/home/adminrat/Downloads/BashBot/bashbot/commands/__init__.py", line 88, in execute
    await command.execute(client, message, alias, args)
  File "/home/adminrat/Downloads/BashBot/bashbot/commands/__init__.py", line 59, in execute
    await getattr(self, action)(client, message, parameters)
AttributeError: 'PermissionCommand' object has no attribute 'list_all'

Can't invoke command

Here is the traceback :

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/discord.py-1.2.3-py3.7.egg/discord/client.py", line 270, in _run_event
    await coro(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/bashbot-1.0-py3.7.egg/bashbot/bot.py", line 49, in on_message
    if is_command(message):
  File "/usr/local/lib/python3.7/dist-packages/bashbot-1.0-py3.7.egg/bashbot/bot.py", line 120, in is_command
    if message.channel.is_private:
AttributeError: 'DMChannel' object has no attribute 'is_private'

I tried in a channel, and in private message

I don't think I miss something in the installation process...
Cordially

If you want to talk to me directly from Discord : Dezyox#3310

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.