1
0
mirror of https://gitlab.com/ddorn/tfjm-discord-bot.git synced 2024-12-24 17:02:22 +00:00

async console

This commit is contained in:
ddorn 2020-05-01 17:08:05 +02:00
parent d16aeee4c0
commit 5af3342182
6 changed files with 152 additions and 17 deletions

108
poetry.lock generated
View File

@ -24,6 +24,14 @@ version = ">=3.6.5"
[package.extras]
speedups = ["aiodns", "brotlipy", "cchardet"]
[[package]]
category = "main"
description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"."
name = "appdirs"
optional = false
python-versions = "*"
version = "1.4.3"
[[package]]
category = "main"
description = "Timeout context manager for asyncio programs"
@ -101,6 +109,21 @@ version = "1.1.0"
[package.dependencies]
idna = ">=2.0"
[[package]]
category = "main"
description = "An autocompletion tool for Python that can be used for text editors."
name = "jedi"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
version = "0.17.0"
[package.dependencies]
parso = ">=0.7.0"
[package.extras]
qa = ["flake8 (3.7.9)"]
testing = ["colorama", "docopt", "pytest (>=3.9.0,<5.0.0)"]
[[package]]
category = "main"
description = "multidict implementation"
@ -109,6 +132,28 @@ optional = false
python-versions = ">=3.5"
version = "4.7.5"
[[package]]
category = "main"
description = "A Python Parser"
name = "parso"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
version = "0.7.0"
[package.extras]
testing = ["docopt", "pytest (>=3.0.7)"]
[[package]]
category = "main"
description = "Library for building powerful interactive command lines in Python"
name = "prompt-toolkit"
optional = false
python-versions = ">=3.6"
version = "3.0.3"
[package.dependencies]
wcwidth = "*"
[[package]]
category = "main"
description = "Cross-platform lib for process and system monitoring in Python."
@ -120,6 +165,31 @@ version = "5.7.0"
[package.extras]
enum = ["enum34"]
[[package]]
category = "main"
description = "Python REPL build on top of prompt_toolkit"
name = "ptpython"
optional = false
python-versions = ">=3.6"
version = "3.0.2"
[package.dependencies]
appdirs = "*"
jedi = ">=0.9.0"
prompt-toolkit = ">=3.0.0,<3.1.0"
pygments = "*"
[package.extras]
ptipython = ["ipython"]
[[package]]
category = "main"
description = "Pygments is a syntax highlighting package written in Python."
name = "pygments"
optional = false
python-versions = ">=3.5"
version = "2.6.1"
[[package]]
category = "main"
description = "YAML parser and emitter for Python"
@ -137,6 +207,14 @@ optional = false
python-versions = "*"
version = "3.7.4.2"
[[package]]
category = "main"
description = "Measures number of Terminal column cells of wide-character codes"
name = "wcwidth"
optional = false
python-versions = "*"
version = "0.1.9"
[[package]]
category = "main"
description = "An implementation of the WebSocket Protocol (RFC 6455 & 7692)"
@ -158,7 +236,7 @@ idna = ">=2.0"
multidict = ">=4.0"
[metadata]
content-hash = "efedf2c9dc8d78ca138823f3be2425eded9010c7edecc695e3ddc6ede8df5c94"
content-hash = "9c9fe13eda9abe2a52c99a38f8bd1183b208d8f8ac72f478061376066c4a105e"
python-versions = "^3.6"
[metadata.files]
@ -176,6 +254,10 @@ aiohttp = [
{file = "aiohttp-3.6.2-py3-none-any.whl", hash = "sha256:460bd4237d2dbecc3b5ed57e122992f60188afe46e7319116da5eb8a9dfedba4"},
{file = "aiohttp-3.6.2.tar.gz", hash = "sha256:259ab809ff0727d0e834ac5e8a283dc5e3e0ecc30c4d80b3cd17a4139ce1f326"},
]
appdirs = [
{file = "appdirs-1.4.3-py2.py3-none-any.whl", hash = "sha256:d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e"},
{file = "appdirs-1.4.3.tar.gz", hash = "sha256:9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92"},
]
async-timeout = [
{file = "async-timeout-3.0.1.tar.gz", hash = "sha256:0c3c816a028d47f659d6ff5c745cb2acf1f966da1fe5c19c77a70282b25f4c5f"},
{file = "async_timeout-3.0.1-py3-none-any.whl", hash = "sha256:4291ca197d287d274d0b6cb5d6f8f8f82d434ed288f962539ff18cc9012f9ea3"},
@ -203,6 +285,10 @@ idna = [
idna-ssl = [
{file = "idna-ssl-1.1.0.tar.gz", hash = "sha256:a933e3bb13da54383f9e8f35dc4f9cb9eb9b3b78c6b36f311254d6d0d92c6c7c"},
]
jedi = [
{file = "jedi-0.17.0-py2.py3-none-any.whl", hash = "sha256:cd60c93b71944d628ccac47df9a60fec53150de53d42dc10a7fc4b5ba6aae798"},
{file = "jedi-0.17.0.tar.gz", hash = "sha256:df40c97641cb943661d2db4c33c2e1ff75d491189423249e989bcea4464f3030"},
]
multidict = [
{file = "multidict-4.7.5-cp35-cp35m-macosx_10_13_x86_64.whl", hash = "sha256:fc3b4adc2ee8474cb3cd2a155305d5f8eda0a9c91320f83e55748e1fcb68f8e3"},
{file = "multidict-4.7.5-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:42f56542166040b4474c0c608ed051732033cd821126493cf25b6c276df7dd35"},
@ -222,6 +308,14 @@ multidict = [
{file = "multidict-4.7.5-cp38-cp38-win_amd64.whl", hash = "sha256:544fae9261232a97102e27a926019100a9db75bec7b37feedd74b3aa82f29969"},
{file = "multidict-4.7.5.tar.gz", hash = "sha256:aee283c49601fa4c13adc64c09c978838a7e812f85377ae130a24d7198c0331e"},
]
parso = [
{file = "parso-0.7.0-py2.py3-none-any.whl", hash = "sha256:158c140fc04112dc45bca311633ae5033c2c2a7b732fa33d0955bad8152a8dd0"},
{file = "parso-0.7.0.tar.gz", hash = "sha256:908e9fae2144a076d72ae4e25539143d40b8e3eafbaeae03c1bfe226f4cdf12c"},
]
prompt-toolkit = [
{file = "prompt_toolkit-3.0.3-py3-none-any.whl", hash = "sha256:c93e53af97f630f12f5f62a3274e79527936ed466f038953dfa379d4941f651a"},
{file = "prompt_toolkit-3.0.3.tar.gz", hash = "sha256:a402e9bf468b63314e37460b68ba68243d55b2f8c4d0192f85a019af3945050e"},
]
psutil = [
{file = "psutil-5.7.0-cp27-none-win32.whl", hash = "sha256:298af2f14b635c3c7118fd9183843f4e73e681bb6f01e12284d4d70d48a60953"},
{file = "psutil-5.7.0-cp27-none-win_amd64.whl", hash = "sha256:75e22717d4dbc7ca529ec5063000b2b294fc9a367f9c9ede1f65846c7955fd38"},
@ -235,6 +329,14 @@ psutil = [
{file = "psutil-5.7.0-cp38-cp38-win_amd64.whl", hash = "sha256:d84029b190c8a66a946e28b4d3934d2ca1528ec94764b180f7d6ea57b0e75e26"},
{file = "psutil-5.7.0.tar.gz", hash = "sha256:685ec16ca14d079455892f25bd124df26ff9137664af445563c1bd36629b5e0e"},
]
ptpython = [
{file = "ptpython-3.0.2-py2.py3-none-any.whl", hash = "sha256:126a9e2126816066e6ad57661a15715649a5a4d4b3ca9387d7825dc7d9040c38"},
{file = "ptpython-3.0.2.tar.gz", hash = "sha256:556e5367d4d58231b575dc619493dc0d8ef4c2d15ee85c727a88beb60fa5c52b"},
]
pygments = [
{file = "Pygments-2.6.1-py3-none-any.whl", hash = "sha256:ff7a40b4860b727ab48fad6360eb351cc1b33cbf9b15a0f689ca5353e9463324"},
{file = "Pygments-2.6.1.tar.gz", hash = "sha256:647344a061c249a3b74e230c739f434d7ea4d8b1d5f3721bc0f3558049b38f44"},
]
pyyaml = [
{file = "PyYAML-5.3.1-cp27-cp27m-win32.whl", hash = "sha256:74809a57b329d6cc0fdccee6318f44b9b8649961fa73144a98735b0aaf029f1f"},
{file = "PyYAML-5.3.1-cp27-cp27m-win_amd64.whl", hash = "sha256:240097ff019d7c70a4922b6869d8a86407758333f02203e0fc6ff79c5dcede76"},
@ -253,6 +355,10 @@ typing-extensions = [
{file = "typing_extensions-3.7.4.2-py3-none-any.whl", hash = "sha256:6e95524d8a547a91e08f404ae485bbb71962de46967e1b71a0cb89af24e761c5"},
{file = "typing_extensions-3.7.4.2.tar.gz", hash = "sha256:79ee589a3caca649a9bfd2a8de4709837400dfa00b6cc81962a1e6a1815969ae"},
]
wcwidth = [
{file = "wcwidth-0.1.9-py2.py3-none-any.whl", hash = "sha256:cafe2186b3c009a04067022ce1dcd79cb38d8d65ee4f4791b8888d6599d1bbe1"},
{file = "wcwidth-0.1.9.tar.gz", hash = "sha256:ee73862862a156bf77ff92b09034fc4825dd3af9cf81bc5b360668d425f3c5f1"},
]
websockets = [
{file = "websockets-8.0.2-cp36-cp36m-macosx_10_6_intel.whl", hash = "sha256:e906128532a14b9d264a43eb48f9b3080d53a9bda819ab45bf56b8039dc606ac"},
{file = "websockets-8.0.2-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:83e63aa73331b9ca21af61df8f115fb5fbcba3f281bee650a4ad16a40cd1ef15"},

View File

@ -9,6 +9,7 @@ python = "^3.6"
discord = "^1.0.1"
pyyaml = "^5.0.0"
psutil = "^5.7.0"
ptpython = "^3.0.2"
[tool.poetry.dev-dependencies]

View File

@ -1,3 +1,4 @@
import asyncio
import code
from pprint import pprint
@ -5,6 +6,7 @@ import discord
from discord import TextChannel, PermissionOverwrite
from discord.ext.commands import command, has_role, Bot, Cog
from discord.utils import get
from ptpython.repl import embed
from src.constants import *
from src.core import CustomBot
@ -18,6 +20,8 @@ COGS_SHORTCUTS = {
"v": "dev",
}
KeyboardInterrupt
class DevCog(Cog, name="Dev tools"):
def __init__(self, bot: CustomBot):
@ -42,18 +46,17 @@ class DevCog(Cog, name="Dev tools"):
# Utility functions
local = {
**globals(),
**locals(),
"pprint": pprint,
"_show": lambda o: print(*dir(o), sep="\n"),
"__name__": "__console__",
"__doc__": None,
}
def send(msg, channel=None):
channel = channel or ctx.channel
asyncio.create_task(channel.send(msg))
try:
await embed(
globals(), locals(), vi_mode=True, return_asyncio_coroutine=True
)
except EOFError:
pass
code.interact(
banner="Ne SURTOUT PAS FAIRE Ctrl+C !\n(TFJM² debugger)", local=local
)
await ctx.send("Tout va mieux !")
def full_cog_name(self, name):
@ -121,17 +124,24 @@ class DevCog(Cog, name="Dev tools"):
"""
return
guild: discord.Guild = ctx.guild
nothing = PermissionOverwrite(read_messages=False)
see = PermissionOverwrite(read_messages=True)
# orga = get(guild.roles, name=f"Orga {t}")
for t in TOURNOIS[3:]:
jury = get(guild.roles, name=f"Jury {t}")
for p in "AB":
await guild.create_voice_channel(
f"blabla-jury-poule-{p}",
overwrites={guild.default_role: nothing, jury: see},
category=get(guild.categories, name=t),
)
return
aide: TextChannel = get(guild.text_channels, name="aide")
for t in TOURNOIS:
orga = get(guild.roles, name=f"Orga {t}")
jury = get(guild.roles, name=f"Jury {t}")
await aide.set_permissions(orga, overwrite=see)
await aide.set_permissions(jury, overwrite=see)
@ -173,5 +183,5 @@ class DevCog(Cog, name="Dev tools"):
await ctx.send(" ".join(msg))
def setup(bot: Bot):
def setup(bot: CustomBot):
bot.add_cog(DevCog(bot))

View File

@ -1,9 +1,11 @@
import datetime
import io
import itertools
import random
from operator import attrgetter
from time import time
import aiohttp
import discord
from discord import Guild
from discord.ext import commands
@ -85,6 +87,18 @@ class MiscCog(Cog, name="Divers"):
await ctx.send(embed=embed)
@command(hidden=True)
async def fractal(self, ctx: Context):
await ctx.message.add_reaction(Emoji.CHECK)
seed = random.randint(0, 1_000_000_000)
async with aiohttp.ClientSession() as session:
async with session.get(FRACTAL_URL.format(seed=seed)) as resp:
if resp.status != 200:
return await ctx.send("Could not download file...")
data = io.BytesIO(await resp.read())
await ctx.send(file=discord.File(data, "cool_image.png"))
# ----------------- Help ---------------- #
@command(name="help", aliases=["h"])

View File

@ -12,6 +12,7 @@ __all__ = [
"DIEGO",
"TOURNOIS",
"EMBED_COLOR",
"FRACTAL_URL",
"File",
"Emoji",
]
@ -32,6 +33,8 @@ GUILD = "690934836696973404"
DIEGO = "Diego" # Mon display name
TEAMS_CHANNEL_CATEGORY = "Channels d'équipes"
EMBED_COLOR = 0xFFA500
FRACTAL_URL = "https://thefractal.space/img/{seed}.png?size=1500"
ROUND_NAMES = ["premier tour", "deuxième tour"]
TOURNOIS = [
"Lille",
@ -61,6 +64,7 @@ class Emoji:
SOB = "😭"
BIN = "🗑️"
DICE = "🎲"
CHECK = ""
class File:

View File

@ -27,7 +27,7 @@ def send_and_bin(f):
return wrapped
def start_time(self):
def start_time():
return psutil.Process().create_time()