Compare commits
| 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 }}
|
||||
|
||||
@@ -8,4 +8,3 @@ venv/
|
||||
.env
|
||||
.env.dev
|
||||
./config/marc_store.yml
|
||||
.python-version
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
start:
|
||||
poetry run python .
|
||||
pipenv run python .
|
||||
update:
|
||||
poetry update
|
||||
poetry export --output requirements.txt
|
||||
pipenv update
|
||||
pipenv lock -r > requirements.txt
|
||||
dev:
|
||||
docker-compose -f docker-compose.yml up -d --build --force-recreate --remove-orphans dev
|
||||
prod:
|
||||
@@ -14,8 +14,8 @@ push: build
|
||||
deploy: push
|
||||
DOCKER_HOST=ssh://vps docker service update vps_esclave
|
||||
setup:
|
||||
poetry install
|
||||
poetry shell
|
||||
pip install pipenv
|
||||
pipenv shell
|
||||
pipenv install
|
||||
recreate:
|
||||
docker-compose -f docker-compose.yml up --force-recreate dev
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ unidecode = '*'
|
||||
future = '*'
|
||||
selenium = "*"
|
||||
fake-useragent = "*"
|
||||
colorama = "*"
|
||||
|
||||
[dev-packages]
|
||||
black = "*"
|
||||
|
||||
Generated
+872
-1094
File diff suppressed because it is too large
Load Diff
+3
-8
@@ -17,7 +17,7 @@ from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
from config.config import prefix, masters, access
|
||||
from config.config import prefix, masters, delete_after_time, status, access
|
||||
from config.credentials import token, client_id
|
||||
from discord.ext import commands, tasks
|
||||
|
||||
@@ -39,11 +39,7 @@ from discord.ext import commands, tasks
|
||||
# # If we are in a guild, we allow for the user to mention us or use any of the prefixes in our list.
|
||||
# return commands.when_mentioned_or(*prefixes)(bot, message)
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
|
||||
# client = commands.Bot(command_prefix=prefix, case_insensitive=True)
|
||||
client = commands.Bot(command_prefix=prefix, intents=intents)
|
||||
client = commands.Bot(command_prefix=prefix, case_insensitive=True)
|
||||
client.id = client_id
|
||||
|
||||
|
||||
@@ -60,7 +56,7 @@ class Main(commands.Cog):
|
||||
self.load_cogs()
|
||||
self.load_status()
|
||||
self.load_icloud()
|
||||
# self.api: PycloudService = None
|
||||
self.api: PycloudService = None
|
||||
|
||||
def load_icloud(self):
|
||||
"""Charge l'api d'icloud."""
|
||||
@@ -83,7 +79,6 @@ class Main(commands.Cog):
|
||||
@commands.command()
|
||||
async def environment(self, ctx: commands.Context):
|
||||
"""Affiche l'environnement dans lequel le bot tourne."""
|
||||
print("environment")
|
||||
host = os.environ.get("HOST")
|
||||
await ctx.send(f"> Environment: **{host}**")
|
||||
|
||||
|
||||
+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))
|
||||
+1
-1
@@ -15,7 +15,7 @@ link = "https://discordapp.com/oauth2/authorize?&client_id=703347349623144549&sc
|
||||
prefix = os.environ.get("DISCORD_PREFIX") or "."
|
||||
masters = [478552571510915072] # , 219949869220102147]
|
||||
wolfram = wolframalpha.Client(wolfram_alpha_id)
|
||||
ialab_bot_url = os.environ.get("IALAB_URL") or "https://ialab.marcpartensky.com"
|
||||
ialab_bot_url = "https://ialab.marcpartensky.com"
|
||||
|
||||
roles = ["@Maître", "@Admin"]
|
||||
|
||||
|
||||
+12
-19
@@ -1,4 +1,5 @@
|
||||
# from mongocollection import MongoCollection
|
||||
import discord
|
||||
from pymongo import MongoClient
|
||||
from pymongo.database import Database
|
||||
from pymongo.collection import Collection, ObjectId
|
||||
@@ -101,7 +102,7 @@ class MongoCluster(MongoClient):
|
||||
def __getitem__(self, item):
|
||||
"""Return a mongo database given its key."""
|
||||
item = super().__getitem__(item)
|
||||
if isinstance(item, Database):
|
||||
if isinstance(item, pymongo.database.Database):
|
||||
return MongoDatabase.from_database(item)
|
||||
else:
|
||||
return item
|
||||
@@ -119,7 +120,7 @@ class MongoDatabase(Database):
|
||||
def __getitem__(self, item):
|
||||
"""Return a mongo collection given a key."""
|
||||
item = super().__getitem__(item)
|
||||
if isinstance(item, Collection):
|
||||
if isinstance(item, pymongo.collection.Collection):
|
||||
return MongoCollection.from_collection(item)
|
||||
else:
|
||||
return item
|
||||
@@ -200,10 +201,10 @@ class MongoCollection(Collection):
|
||||
else:
|
||||
self.insert_one(arg, **kwargs)
|
||||
|
||||
def insert_many(self, posts):
|
||||
def insert_many(self, posts, **kwargs):
|
||||
"""Insert many posts."""
|
||||
posts = [self.treat(post) for post in posts]
|
||||
super().insert_many(posts)
|
||||
super().insert_many(post)
|
||||
|
||||
def __contains__(self, id):
|
||||
return self.seek_one(_id=id) != None
|
||||
@@ -240,9 +241,10 @@ class MongoCollection(Collection):
|
||||
|
||||
def __delitem__(self, id):
|
||||
"""Delete a post."""
|
||||
# print(self.find_one(dict(_id=id)))
|
||||
print(id)
|
||||
print(self.find_one(dict(_id=id)))
|
||||
self.delete_one(dict(_id=id))
|
||||
# print(self.find_one(dict(_id=id)))
|
||||
print(self.find_one(dict(_id=id)))
|
||||
|
||||
def post(self, post):
|
||||
"""Replace or insert a post."""
|
||||
@@ -262,14 +264,12 @@ class MongoCollection(Collection):
|
||||
"""Set a default post."""
|
||||
if id in self:
|
||||
post.update(self[id]._dict)
|
||||
# print(1, post)
|
||||
print(1, post)
|
||||
self[id] = post
|
||||
# print(2, self[id])
|
||||
print(2, self[id])
|
||||
|
||||
def __setattr__(self, att, value):
|
||||
"""Set attribute to a collection."""
|
||||
# print(att, value)
|
||||
if att in type(self).keys or att in dir(self) or att.startswith("_"):
|
||||
if att in type(self).keys or att in dir(self):
|
||||
super().__setattr__(att, value)
|
||||
else:
|
||||
self.__setitem__(att, value)
|
||||
@@ -497,14 +497,7 @@ class User(DictObject):
|
||||
# command = db.commands.find(machin=34, bidule=324)
|
||||
|
||||
if __name__ == "__main__":
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
cluster = os.environ["DISCORD_MONGO_CLUSTER"]
|
||||
username = os.environ["DISCORD_MONGO_USERNAME"]
|
||||
password = os.environ["DISCORD_MONGO_PASSWORD"]
|
||||
mongo_url = f"mongodb+srv://{username}:{password}@{cluster}"
|
||||
mongo_url = "mongodb+srv://esclave:esclave@discord-cluster-5ckni.mongodb.net/test"
|
||||
cl = MongoCluster(mongo_url)
|
||||
# print('cluster over')
|
||||
esclave = cl.esclave
|
||||
|
||||
Generated
-2069
File diff suppressed because it is too large
Load Diff
@@ -1,50 +0,0 @@
|
||||
[tool.poetry]
|
||||
name = "discord-bot"
|
||||
version = "0.1.0"
|
||||
description = "A discord bot multi purpose."
|
||||
authors = ["Marc Partensky <marc.partensky@gmail.com>"]
|
||||
license = "GPL2"
|
||||
readme = "README.md"
|
||||
packages = [{include = "discord_bot"}]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "3.8.13"
|
||||
beautifulsoup4 = "*"
|
||||
# "discord.py[voice]" = "*"
|
||||
fbchat = "*"
|
||||
# fbchat = {git = "git://github.com/carpedm20/fbchat.git"}
|
||||
nightcore = "*"
|
||||
profanity-check = "*"
|
||||
progressbar2 = "*"
|
||||
# pyicloud = "*"
|
||||
pymongo = "*"
|
||||
requests = "*"
|
||||
rich = "*"
|
||||
translate = "*"
|
||||
wikipedia = "*"
|
||||
wolframalpha = "*"
|
||||
html2text = "*"
|
||||
gTTS = "2.2.1"
|
||||
Pillow = "*"
|
||||
PyGithub = "*"
|
||||
PyYAML = "*"
|
||||
youtube_dl = "*"
|
||||
python-dotenv = "*"
|
||||
dpy-http-server = "*"
|
||||
pexpect = "*"
|
||||
# libs/sherlock
|
||||
dnspython = "*"
|
||||
requests-futures = "*"
|
||||
torrequest = "*"
|
||||
# libs/google
|
||||
unidecode = '*'
|
||||
future = '*'
|
||||
selenium = "*"
|
||||
fake-useragent = "*"
|
||||
colorama = "*"
|
||||
py-cord = "^2.4.1"
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
+64
-59
@@ -1,80 +1,85 @@
|
||||
#
|
||||
# These requirements were autogenerated by pipenv
|
||||
# To regenerate from the project's Pipfile, run:
|
||||
#
|
||||
# pipenv lock --requirements
|
||||
#
|
||||
|
||||
-i https://pypi.org/simple
|
||||
aenum==2.2.6
|
||||
aiohttp==3.8.3
|
||||
aiosignal==1.3.1
|
||||
async-generator==1.10
|
||||
async-timeout==4.0.2
|
||||
attrs==22.2.0
|
||||
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.11.1
|
||||
certifi==2022.12.7
|
||||
cffi==1.15.1
|
||||
charset-normalizer==2.1.1
|
||||
click==7.1.2
|
||||
colorama==0.4.6
|
||||
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.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'
|
||||
commonmark==0.9.1
|
||||
Deprecated==1.2.13
|
||||
discord.py==2.1.0
|
||||
dnspython==2.3.0
|
||||
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.1
|
||||
dpy-http-server==0.1.0
|
||||
exceptiongroup==1.1.0
|
||||
fake-useragent==1.1.1
|
||||
fake-useragent==0.1.11
|
||||
fbchat==1.9.7
|
||||
frozenlist==1.3.3
|
||||
future==0.18.3
|
||||
gTTS==2.2.4
|
||||
h11==0.14.0
|
||||
future==0.18.2
|
||||
gtts==2.2.4
|
||||
h11==0.13.0; python_version >= '3.6'
|
||||
html2text==2020.1.16
|
||||
idna==3.4
|
||||
importlib-resources==5.10.2
|
||||
jaraco.context==4.2.0
|
||||
joblib==1.2.0
|
||||
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.9.2
|
||||
more-itertools==9.0.0
|
||||
multidict==6.0.4
|
||||
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.24.1
|
||||
outcome==1.2.0
|
||||
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.4.0
|
||||
pillow==9.1.1
|
||||
profanity-check==1.0.3
|
||||
progressbar2==4.2.0
|
||||
progressbar2==4.0.0
|
||||
ptyprocess==0.7.0
|
||||
pycparser==2.21
|
||||
pydub==0.23.1
|
||||
PyGithub==1.57
|
||||
Pygments==2.14.0
|
||||
PyJWT==2.6.0
|
||||
pymongo==4.3.3
|
||||
PyNaCl==1.5.0
|
||||
PySocks==1.7.1
|
||||
python-dotenv==0.21.0
|
||||
python-utils==3.4.5
|
||||
PyYAML==6.0
|
||||
requests==2.28.2
|
||||
pygithub==1.55
|
||||
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==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_version >= '3.7'
|
||||
pyyaml==6.0
|
||||
requests-futures==1.0.0
|
||||
rich==13.1.0
|
||||
scikit-learn==1.2.0
|
||||
scipy==1.10.0
|
||||
selenium==4.7.2
|
||||
six==1.16.0
|
||||
sniffio==1.3.0
|
||||
requests==2.27.1
|
||||
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.2.post1
|
||||
stem==1.8.1
|
||||
threadpoolctl==3.1.0
|
||||
soupsieve==2.3.2.post1; python_version >= '3.6'
|
||||
stem==1.8.0
|
||||
threadpoolctl==3.1.0; python_version >= '3.6'
|
||||
torrequest==0.1.0
|
||||
translate==3.6.1
|
||||
trio==0.22.0
|
||||
trio-websocket==0.9.2
|
||||
typing_extensions==4.4.0
|
||||
Unidecode==1.3.6
|
||||
urllib3==1.26.14
|
||||
trio-websocket==0.9.2; python_version >= '3.5'
|
||||
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.14.1
|
||||
wsproto==1.2.0
|
||||
xmltodict==0.13.0
|
||||
yarl==1.8.2
|
||||
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
|
||||
zipp==3.11.0
|
||||
|
||||
Reference in New Issue
Block a user