Compare commits
8
Commits
voicechannel
..
ssh
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
360364c80d | ||
|
|
b0c0511126 | ||
|
|
02e5ff1a14 | ||
|
|
e66e94f094 | ||
|
|
b4d83a255f | ||
|
|
c74b028d82 | ||
|
|
f02603bc20 | ||
|
|
b06e8dcdc0 |
@@ -1,7 +1 @@
|
||||
liberapay: marcpartensky
|
||||
patreon: marcpartensky
|
||||
github: marcpartensky
|
||||
custom:
|
||||
# - monero:43J2XmRtjDPRLD35UsYGH2AZamFBQz7dt4VdvZXVm3SuadTrvcoXUXBRUNHqukFte23Q5TWXqhbwaLJJgoVQzzbe2AJDANQ
|
||||
- https://paypal.me/marcpartensky
|
||||
- https://buymeacoffee.com/marcpartensky
|
||||
|
||||
@@ -38,12 +38,6 @@ jobs:
|
||||
with:
|
||||
push: true
|
||||
tags: marcpartensky/discord-bot:v${{ github.run_number }}.${{ steps.tag.outputs.tag }}
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
push: true
|
||||
tags: marcpartensky/discord-bot:latest
|
||||
|
||||
test-python-versions:
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
@@ -19,7 +19,3 @@ setup:
|
||||
pipenv install
|
||||
recreate:
|
||||
docker-compose -f docker-compose.yml up --force-recreate dev
|
||||
fixwithbrew:
|
||||
brew install python@3.8
|
||||
sudo ln -sf /home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.12_1/bin/python3.8 /usr/bin/python3.8
|
||||
|
||||
|
||||
@@ -36,8 +36,6 @@ unidecode = '*'
|
||||
future = '*'
|
||||
selenium = "*"
|
||||
fake-useragent = "*"
|
||||
colorama = "*"
|
||||
discord-ext-audiorec = "*"
|
||||
|
||||
[dev-packages]
|
||||
black = "*"
|
||||
|
||||
Generated
+1443
File diff suppressed because it is too large
Load Diff
+81
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env python
|
||||
"""Control ssh sessions."""
|
||||
|
||||
import typing
|
||||
import discord
|
||||
from pexpect import pxssh
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands.core import has_role
|
||||
|
||||
import pexpect
|
||||
|
||||
SSH_ROLE = "Ssh"
|
||||
|
||||
|
||||
class Ssh(commands.Cog):
|
||||
"""Control ssh sessions."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
"""Initialize the cog with the bot."""
|
||||
self.bot = bot
|
||||
self.color: discord.Color = discord.Color.purple()
|
||||
self.thumbnail: str = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/da/GNOME_Terminal_icon_2019.svg/1200px-GNOME_Terminal_icon_2019.svg.png"
|
||||
self.timeout = 3600
|
||||
self.shells: typing.Dict[int, pexpect.pty_spawn.spawn] = {}
|
||||
|
||||
@has_role(SSH_ROLE)
|
||||
@commands.command()
|
||||
async def ssh(self, ctx: commands.Context, hostname: str, port: int=0):
|
||||
"""Run a command in a ssh session"""
|
||||
username=""
|
||||
await create_role_if_missing(ctx, SSH_ROLE, self.color)
|
||||
embed = discord.Embed(color=self.color)
|
||||
embed.set_thumbnail(url=self.thumbnail)
|
||||
embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar)
|
||||
embed.description = self.shell_path
|
||||
shell = pxssh.pxssh()
|
||||
shell.login(hostname, username, password)
|
||||
self.shells[ctx.author.id] = shell
|
||||
shell.sendline("echo $HOSTNAME")
|
||||
hostname = shell.before.decode("utf-8")
|
||||
embed.title = f"Connected to {hostname}"
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@commands.command(name="shells")
|
||||
async def list_shells(self, ctx: commands.Context):
|
||||
"""List ."""
|
||||
if len(self.shells) == 0:
|
||||
return await ctx.send("> No active ssh connexion.")
|
||||
embed = discord.Embed(title="Active ssh connexions:", color=self.color)
|
||||
embed.set_thumbnail(url=self.thumbnail)
|
||||
|
||||
shell_users = []
|
||||
for shell_user in map(self.bot.fetch_user, self.shells.keys()):
|
||||
shell_users.append(f"- {await shell_user}")
|
||||
embed.description = "\n".join(shell_users)
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@commands.Cog.listener(name="on_message")
|
||||
async def on_message(self, msg: discord.Message):
|
||||
"""Read all messages"""
|
||||
if msg.author == self.bot.user:
|
||||
return
|
||||
if msg.content.startswith(self.bot.command_prefix):
|
||||
return
|
||||
if msg.author.id in self.shells:
|
||||
shell = self.shells[msg.author.id]
|
||||
shell.sendline(msg.content)
|
||||
shell.prompt()
|
||||
output = shell.before.decode("utf-8")
|
||||
print(output)
|
||||
await msg.channel.send(output)
|
||||
|
||||
# async def cog_common_error(self, ctx, error):
|
||||
# """Close all shell sessions."""
|
||||
# for shell in self.shells.values():
|
||||
# shell.close()
|
||||
|
||||
|
||||
def setup(bot):
|
||||
"""Setup the Shell cog."""
|
||||
bot.add_cog(Ssh(bot))
|
||||
@@ -6,7 +6,6 @@ from typing import List
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from discord.ext.audiorec import NativeVoiceClient
|
||||
|
||||
from config.config import masters
|
||||
|
||||
|
||||
+5
-6
@@ -17,7 +17,6 @@ cffi==1.15.0
|
||||
chardet==4.0.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
|
||||
charset-normalizer==2.0.12; python_version >= '3'
|
||||
click==7.1.2; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
|
||||
colorama==0.4.4
|
||||
commonmark==0.9.1
|
||||
cryptography==37.0.2
|
||||
deprecated==1.2.13; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
||||
@@ -36,7 +35,7 @@ joblib==1.1.0; python_version >= '3.6'
|
||||
libretranslatepy==2.1.1
|
||||
lxml==4.8.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
|
||||
more-itertools==8.13.0; python_version >= '3.5'
|
||||
multidict==6.0.2; python_full_version >= '3.7.0'
|
||||
multidict==6.0.2; python_version >= '3.7'
|
||||
nightcore==1.1.0
|
||||
numpy==1.22.4; python_version >= '3.8'
|
||||
outcome==1.1.0; python_version >= '3.6'
|
||||
@@ -56,7 +55,7 @@ pynacl==1.4.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2,
|
||||
pyopenssl==22.0.0
|
||||
pysocks==1.7.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
||||
python-dotenv==0.20.0
|
||||
python-utils==3.2.3; python_full_version >= '3.7.0'
|
||||
python-utils==3.2.3; python_version >= '3.7'
|
||||
pyyaml==6.0
|
||||
requests-futures==1.0.0
|
||||
requests==2.27.1
|
||||
@@ -73,14 +72,14 @@ threadpoolctl==3.1.0; python_version >= '3.6'
|
||||
torrequest==0.1.0
|
||||
translate==3.6.1
|
||||
trio-websocket==0.9.2; python_version >= '3.5'
|
||||
trio==0.20.0; python_full_version >= '3.7.0'
|
||||
trio==0.20.0; python_version >= '3.7'
|
||||
typing-extensions==4.2.0; python_version < '3.9'
|
||||
unidecode==1.3.4
|
||||
urllib3[secure,socks]==1.26.9; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4.0'
|
||||
urllib3[secure,socks]==1.26.9; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'
|
||||
wikipedia==1.4.0
|
||||
wolframalpha==5.0.0
|
||||
wrapt==1.14.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
|
||||
wsproto==1.1.0; python_full_version >= '3.7.0'
|
||||
wsproto==1.1.0; python_version >= '3.7'
|
||||
xmltodict==0.13.0; python_version >= '3.4'
|
||||
yarl==1.7.2; python_version >= '3.6'
|
||||
youtube-dl==2021.12.17
|
||||
|
||||
Reference in New Issue
Block a user