Compare commits

...
16 Commits
Author SHA1 Message Date
marc 360364c80d master 2022-05-21 23:54:55 +02:00
marc 7ce95509df update 2022-05-21 23:54:09 +02:00
marc 9feb5b9a3c pipenv update 2022-05-21 23:49:50 +02:00
marc 1f994a6e7f update 2022-05-21 23:49:24 +02:00
marc b0c0511126 ssh 2022-05-21 23:46:59 +02:00
marc 0698d093a6 no mute if single 2022-05-21 23:45:15 +02:00
marc e890a561ed update 2022-05-21 23:43:47 +02:00
marc 03c4de805c 13 2022-05-21 23:40:27 +02:00
marc b738111b5e update 2022-05-21 23:40:15 +02:00
marc 02e5ff1a14 pipfile.lock 3.8.13 2022-05-21 23:23:55 +02:00
marc e66e94f094 bye brew 2022-05-21 23:07:40 +02:00
marc b4d83a255f ok 2022-05-21 23:06:39 +02:00
marc c74b028d82 Merge branch 'master' into ssh 2022-04-02 17:49:18 +02:00
marc 03e3e6f692 update 2022-04-02 17:43:29 +02:00
marc f02603bc20 ssh start 2022-04-02 17:42:13 +02:00
marc b06e8dcdc0 adding pxssh 2022-04-02 17:06:10 +02:00
6 changed files with 721 additions and 621 deletions
+1 -5
View File
@@ -1,7 +1,7 @@
start:
pipenv run python .
update:
pipenv lock --pre --clear
pipenv update
pipenv lock -r > requirements.txt
dev:
docker-compose -f docker-compose.yml up -d --build --force-recreate --remove-orphans dev
@@ -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
+1 -1
View File
@@ -43,4 +43,4 @@ pylint = "*"
jedi = "*"
[requires]
python_version = "3.8.12"
python_version = "3.8.13"
Generated
+603 -580
View File
File diff suppressed because it is too large Load Diff
+81
View File
@@ -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))
+3 -3
View File
@@ -69,7 +69,7 @@ class VoiceChannel(commands.Cog):
logging.info(before)
channel: discord.VoiceChannel = before.channel
members: List[discord.Member] = channel.members
await self.mute_if_single(members)
# await self.mute_if_single(members)
await self.leave_if_alone(members, before.channel)
async def join(
@@ -83,7 +83,7 @@ class VoiceChannel(commands.Cog):
logging.info(after)
channel: discord.VoiceChannel = after.channel
members: List[discord.Member] = channel.members
await self.mute_if_single(members)
# await self.mute_if_single(members)
await self.notify_on_join(member)
await self.join_if_single(members)
@@ -102,7 +102,7 @@ class VoiceChannel(commands.Cog):
before_members: List[discord.Member] = before_channel.members
after_channel: discord.VoiceChannel = after.channel
after_members: List[discord.Member] = after_channel.members
await self.mute_if_single(before_members)
# await self.mute_if_single(before_members)
await self.join_if_single(after_members)
async def mute_if_single(self, members: List[discord.Member]):
+32 -32
View File
@@ -6,80 +6,80 @@
#
-i https://pypi.org/simple
aenum==2.2.6
aiohttp==3.7.4.post0; python_version >= '3.6'
async-generator==1.10; python_version >= '3.5'
async-timeout==3.0.1; python_full_version >= '3.5.3'
attrs==21.4.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
beautifulsoup4==4.10.0
certifi==2021.10.8
beautifulsoup4==4.11.1
certifi==2022.5.18.1; python_version >= '3.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.10; python_version >= '3'
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; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
commonmark==0.9.1
cryptography==36.0.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'
discord.py[voice]==1.7.3; python_full_version >= '3.5.3'
dnspython==2.2.0
dnspython==2.2.1
dpy-http-server==0.1.0
fake-useragent==0.1.11
fbchat==2.0.0a5
fbchat==1.9.7
future==0.18.2
gtts==2.2.3
gtts==2.2.4
h11==0.13.0; python_version >= '3.6'
html2text==2020.1.16
idna==3.3; python_version >= '3'
jaraco.context==4.1.1; python_version >= '3.6'
joblib==1.1.0; python_version >= '3.6'
libretranslatepy==2.1.1
lxml==4.7.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
more-itertools==8.12.0; python_version >= '3.5'
multidict==5.2.0; python_version >= '3.6'
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_version >= '3.7'
nightcore==1.1.0
numpy==1.22.1; python_version >= '3.8'
numpy==1.22.4; python_version >= '3.8'
outcome==1.1.0; python_version >= '3.6'
paho-mqtt==1.6.1
pexpect==4.8.0
pillow==9.0.0
pillow==9.1.1
profanity-check==1.0.3
progressbar2==4.0.0
ptyprocess==0.7.0
pycparser==2.21
pydub==0.23.1
pygithub==1.55
pygments==2.11.2; python_version >= '3.5'
pyjwt==2.3.0; python_version >= '3.6'
pymongo==4.0.1
pygments==2.12.0; python_version >= '3.6'
pyjwt==2.4.0; python_version >= '3.6'
pymongo==4.1.1
pynacl==1.4.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
pyopenssl==21.0.0
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.19.2
python-utils==3.1.0; python_version >= '3.7'
python-dotenv==0.20.0
python-utils==3.2.3; python_version >= '3.7'
pyyaml==6.0
requests-futures==1.0.0
requests==2.27.1
rich==11.0.0
scikit-learn==1.0.2; python_version >= '3.7'
scipy==1.8.0rc2; python_version < '3.11' and python_version >= '3.8'
selenium==4.1.0
rich==12.4.1
scikit-learn==1.1.1; python_version >= '3.8'
scipy==1.8.1; python_version < '3.11' and python_version >= '3.8'
selenium==4.1.5
six==1.16.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
sniffio==1.2.0; python_version >= '3.5'
sortedcontainers==2.4.0
soupsieve==2.3.1; python_version >= '3.6'
soupsieve==2.3.2.post1; python_version >= '3.6'
stem==1.8.0
threadpoolctl==3.0.0; python_version >= '3.6'
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.19.0; python_version >= '3.6'
typing-extensions==4.0.1; python_version >= '3.6'
unidecode==1.3.2
urllib3[secure]==1.26.8; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'
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'
wikipedia==1.4.0
wolframalpha==5.0.0
wrapt==1.13.3; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
wsproto==1.0.0; python_full_version >= '3.6.1'
xmltodict==0.12.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_version >= '3.7'
xmltodict==0.13.0; python_version >= '3.4'
yarl==1.7.2; python_version >= '3.6'
youtube-dl==2021.12.17