From 416207aa9f28ed71f4892c8941c44528ba2bc6f0 Mon Sep 17 00:00:00 2001 From: strNophix Date: Sat, 12 Nov 2022 19:42:02 +0100 Subject: [PATCH] Replaced owner cog with jishaku --- cogs/owner.py | 212 --------------------------------------------- config.json.sample | 17 +++- poetry.lock | 114 +++++++++++++++++++++++- pyproject.toml | 1 + 4 files changed, 125 insertions(+), 219 deletions(-) delete mode 100644 cogs/owner.py diff --git a/cogs/owner.py b/cogs/owner.py deleted file mode 100644 index c2fde64..0000000 --- a/cogs/owner.py +++ /dev/null @@ -1,212 +0,0 @@ -import asyncio -import io -import textwrap -import time -import traceback -from asyncio.subprocess import PIPE -from contextlib import redirect_stdout -from io import BytesIO -from platform import python_version - -import discord -from discord.ext import commands -from discord.ext.commands.context import Context - -from bot import TuneBot -from utils.classes import BaseCog - - -class OwnerCog(BaseCog): - def __init__(self, bot: TuneBot): - super().__init__(bot) - self._last_result = None - - @staticmethod - def cleanup_code(content): - if content.startswith("```") and content.endswith("```"): - return "\n".join(content.split("\n")[1:-1]) - return content.strip("` \n") - - # Hidden means it won't show up on the default help. - @commands.command(name="load", hidden=True) - @commands.is_owner() - async def _cog_load(self, ctx: Context, *, cog: str): - """Command which Loads a Module.""" - - try: - await self.bot.load_extension(cog) - except Exception as e: - await ctx.send(f"**`ERROR:`** {type(e).__name__} - {e}") - else: - await ctx.send("**`SUCCESS`**") - - @commands.command(name="unload", hidden=True) - @commands.is_owner() - async def _cog_unload(self, ctx, *, cog: str): - """Command which Unloads a Module.""" - - try: - await self.bot.unload_extension(cog) - except Exception as e: - await ctx.send(f"**`ERROR:`** {type(e).__name__} - {e}") - else: - await ctx.send("**`SUCCESS`**") - - @commands.command(name="reload", hidden=True) - @commands.is_owner() - async def _cog_reload(self, ctx, *, cog: str): - """Command which Reloads a Module.""" - - try: - await self.bot.unload_extension(cog) - await self.bot.load_extension(cog) - except Exception as e: - await ctx.send(f"**`ERROR:`** {type(e).__name__} - {e}") - else: - await ctx.send("**`SUCCESS`**") - - @commands.command(name="shutdown", hidden=True) - @commands.is_owner() - async def shutdown(self, ctx): - """Command which shutdowns the bot.""" - await ctx.bot.logout() - - @commands.is_owner() - @commands.command( - pass_context=True, - hidden=True, - name="eval", - aliases=["evaluate"], - ) - async def _eval(self, ctx, *, body: str): - env = { - "bot": self.bot, - "ctx": ctx, - "channel": ctx.channel, - "author": ctx.author, - "guild": ctx.guild, - "message": ctx.message, - "_": self._last_result, - } - - env.update(globals()) - - body = self.cleanup_code(body) - stdout = io.StringIO() - - to_compile = f'async def func():\n{textwrap.indent(body, " ")}' - # await ctx.message.add_reaction('a:loading:452489773396000778') - - try: - exec(to_compile, env) - except Exception as e: - # await ctx.message.add_reaction('naokoerror:447495055603662849') - fooem = discord.Embed(color=0xFF0000) - fooem.add_field( - name="Code evaluation was not successful.", - value=f"```\n{e.__class__.__name__}: {e}\n```", - ) - fooem.set_footer( - text=f"Evaluated using Python {python_version()}", - icon_url="http://i.imgur.com/9EftiVK.png", - ) - await ctx.send(embed=fooem) - # await ctx.message.remove_reaction('a:loading:452489773396000778', member=ctx.me) - - func = env["func"] - try: - with redirect_stdout(stdout): - ret = await func() - except Exception as e: - value = stdout.getvalue() - # await ctx.message.add_reaction('naokoerror:447495055603662849') - fooem = discord.Embed(color=0xFF0000) - fooem.add_field( - name="Code evaluation was not successful.", - value=f"```\n{value}{traceback.format_exc()}\n```", - ) - fooem.set_footer( - text=f"Evaluated using Python {python_version()}", - icon_url="http://i.imgur.com/9EftiVK.png", - ) - await ctx.send(embed=fooem) - try: - # await ctx.message.remove_reaction('a:loading:452489773396000778', member=ctx.me) - # await ctx.message.add_reaction('naokotick:447494238872141827') - pass - except Exception: - pass - else: - value = stdout.getvalue() - try: - await ctx.message.remove_reaction( - "a:loading:452489773396000778", member=ctx.me - ) - # await ctx.message.add_reaction('naokotick:447494238872141827') - except Exception: - pass - - if ret is None: - if value: - sfooem = discord.Embed(color=0x170041) - sfooem.add_field( - name="Code evaluation was successful!", - value=f"```\n{value}\n```", - ) - sfooem.set_footer( - text=f"Evaluated using Python {python_version()}", - icon_url="http://i.imgur.com/9EftiVK.png", - ) - await ctx.send(embed=sfooem) - else: - self._last_result = ret - ssfooem = discord.Embed(color=0x170041) - ssfooem.add_field( - name="Code evaluation was successful!", - value=f"```\n{value}{ret}\n```", - ) - ssfooem.set_footer( - text=f"Evaluated using Python {python_version()}", - icon_url="http://i.imgur.com/9EftiVK.png", - ) - await ctx.send(embed=ssfooem) - - @commands.is_owner() - @commands.command(hidden=True, aliases=["exec"]) - async def execute(self, ctx, *, text: str): - """Do a shell command.""" - message = await ctx.send(f"Loading...") - proc = await asyncio.create_subprocess_shell( - text, stdin=None, stderr=PIPE, stdout=PIPE - ) - out = (await proc.stdout.read()).decode("utf-8").strip() - err = (await proc.stderr.read()).decode("utf-8").strip() - - if not out and not err: - await message.delete() - return await ctx.message.add_reaction("👌") - - content = "" - - if err: - content += f"Error:\r\n{err}\r\n{'-' * 30}\r\n" - if out: - content += out - - if len(content) > 1500: - try: - data = BytesIO(content.encode("utf-8")) - await message.delete() - await ctx.send( - content=f"The result was a bit too long..", - file=discord.File(data, filename=f"result_{int(time.time())}.txt"), - ) - except asyncio.TimeoutError as e: - await message.delete() - return await ctx.send(e) - else: - await message.edit(content=f"```fix\n{content}\n```") - - -async def setup(bot: TuneBot): - await bot.add_cog(OwnerCog(bot)) diff --git a/config.json.sample b/config.json.sample index 34f2201..e71cb55 100644 --- a/config.json.sample +++ b/config.json.sample @@ -1,8 +1,13 @@ { "token": "", - "owner_ids": [194545408960102400, 190875175460405249], + "owner_ids": [ + 194545408960102400, + 190875175460405250 + ], "manager_ids": [], - "prefixes": ["ck!"], + "prefixes": [ + "ck!" + ], "redis_url": "", "redis_prefix": "", "lavalink": { @@ -19,7 +24,13 @@ "name": "CloudKid Radio", "description": "A sample bot description" }, - "cogs": ["cogs.owner", "cogs.settings", "cogs.information", "cogs.music"], + "cogs": [ + "jishaku", + "cogs.owner", + "cogs.settings", + "cogs.information", + "cogs.music" + ], "queue_buffer_size": 5, "slash_descriptions": {} } diff --git a/poetry.lock b/poetry.lock index 3487498..15ac05f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -44,6 +44,17 @@ python-versions = ">=3.6" pytube = "*" urllib3 = "*" +[[package]] +name = "astunparse" +version = "1.6.3" +description = "An AST unparser for Python" +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +six = ">=1.6.1,<2.0" + [[package]] name = "async-timeout" version = "3.0.1" @@ -105,6 +116,14 @@ jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] python2 = ["typed-ast (>=1.4.3)"] uvloop = ["uvloop (>=0.15.2)"] +[[package]] +name = "braceexpand" +version = "0.1.7" +description = "Bash-style brace expansion for Python" +category = "main" +optional = false +python-versions = "*" + [[package]] name = "certifi" version = "2021.10.8" @@ -155,7 +174,7 @@ unicode_backport = ["unicodedata2"] name = "click" version = "8.0.3" description = "Composable command line interface toolkit" -category = "dev" +category = "main" optional = false python-versions = ">=3.6" @@ -166,7 +185,7 @@ colorama = {version = "*", markers = "platform_system == \"Windows\""} name = "colorama" version = "0.4.4" description = "Cross-platform colored terminal text." -category = "dev" +category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" @@ -238,6 +257,60 @@ category = "main" optional = false python-versions = ">=3.5" +[[package]] +name = "import-expression" +version = "1.1.4" +description = "Parses a superset of Python allowing for inline module import expressions" +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +astunparse = ">=1.6.3,<2.0.0" + +[package.extras] +test = ["pytest", "pytest-cov"] + +[[package]] +name = "importlib-metadata" +version = "5.0.0" +description = "Read metadata from Python packages" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +zipp = ">=0.5" + +[package.extras] +docs = ["sphinx (>=3.5)", "jaraco.packaging (>=9)", "rst.linker (>=1.9)", "furo", "jaraco.tidelift (>=1.4)"] +perf = ["ipython"] +testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "flake8 (<5)", "pytest-cov", "pytest-enabler (>=1.3)", "packaging", "pyfakefs", "flufl.flake8", "pytest-perf (>=0.9.2)", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)", "importlib-resources (>=1.3)"] + +[[package]] +name = "jishaku" +version = "2.5.1" +description = "A discord.py extension including useful tools for bot development and debugging." +category = "main" +optional = false +python-versions = ">=3.8.0" + +[package.dependencies] +braceexpand = ">=0.1.7" +click = ">=8.0.1" +import-expression = ">=1.0.0,<2.0.0" +importlib-metadata = {version = ">=3.7.0", markers = "python_version < \"3.10\""} +line-profiler = ">=3.5.1" +typing-extensions = {version = ">=3.10.0", markers = "python_version < \"3.10\""} + +[package.extras] +discordpy = ["discord.py (>=1.7.3)"] +docs = ["Sphinx (>=4.4.0)", "sphinxcontrib-asyncio (>=0.3.0)"] +procinfo = ["psutil (>=5.8.0)"] +publish = ["Jinja2 (>=3.0.3)"] +test = ["coverage (>=6.3.2)", "flake8 (>=4.0.1)", "isort (>=5.10.1)", "pylint (>=2.11.1)", "pytest (>=7.0.1)", "pytest-asyncio (>=0.18.1)", "pytest-cov (>=3.0.0)", "pytest-mock (>=3.7.0)"] +voice = ["yt-dlp (>=2022.3.8)"] + [[package]] name = "lavalink" version = "4.0.4" @@ -253,6 +326,20 @@ aiohttp = ">=3.7.4,<3.9.0" development = ["pylint", "flake8"] docs = ["sphinx", "pygments", "guzzle-sphinx-theme", "enum-tools", "sphinx-toolbox"] +[[package]] +name = "line-profiler" +version = "3.5.1" +description = "Line-by-line profiler." +category = "main" +optional = false +python-versions = "*" + +[package.extras] +all = ["cython", "scikit-build", "cmake", "ninja", "pytest (>=4.6.11)", "pytest-cov (>=2.10.1)", "coverage[toml] (>=5.3)", "ubelt (>=1.0.1)", "IPython (>=0.13,<7.17.0)", "IPython (>=0.13)"] +build = ["cython", "scikit-build", "cmake", "ninja"] +ipython = ["IPython (>=0.13,<7.17.0)", "IPython (>=0.13)"] +tests = ["pytest (>=4.6.11)", "pytest-cov (>=2.10.1)", "coverage[toml] (>=5.3)", "ubelt (>=1.0.1)", "IPython (>=0.13,<7.17.0)", "IPython (>=0.13)"] + [[package]] name = "multidict" version = "4.7.6" @@ -409,7 +496,7 @@ use_chardet_on_py3 = ["chardet (>=3.0.2,<5)"] name = "six" version = "1.16.0" description = "Python 2 and 3 compatibility utilities" -category = "dev" +category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" @@ -515,19 +602,33 @@ mutagen = "*" pycryptodomex = "*" websockets = "*" +[[package]] +name = "zipp" +version = "3.10.0" +description = "Backport of pathlib-compatible object wrapper for zip files" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.extras] +docs = ["sphinx (>=3.5)", "jaraco.packaging (>=9)", "rst.linker (>=1.9)", "furo", "jaraco.tidelift (>=1.4)"] +testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "flake8 (<5)", "pytest-cov", "pytest-enabler (>=1.3)", "jaraco.itertools", "func-timeout", "jaraco.functools", "more-itertools", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)"] + [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "f218f441c448507816f71099116f56996d3c49745d90ceac16cc09b8d63e2601" +content-hash = "7518d3e2ccfffad1b05bd93f5178cb700c0bbe71e177707b56f60bb2dc46c70d" [metadata.files] aiohttp = [] aioredis = [] aiotube = [] +astunparse = [] async-timeout = [] attrs = [] "backports.entry-points-selectable" = [] black = [] +braceexpand = [] certifi = [ {file = "certifi-2021.10.8-py2.py3-none-any.whl", hash = "sha256:d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569"}, {file = "certifi-2021.10.8.tar.gz", hash = "sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872"}, @@ -553,7 +654,11 @@ idna = [ {file = "idna-3.3-py3-none-any.whl", hash = "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff"}, {file = "idna-3.3.tar.gz", hash = "sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"}, ] +import-expression = [] +importlib-metadata = [] +jishaku = [] lavalink = [] +line-profiler = [] multidict = [] mutagen = [] mypy-extensions = [ @@ -642,3 +747,4 @@ virtualenv = [] websockets = [] yarl = [] yt-dlp = [] +zipp = [] diff --git a/pyproject.toml b/pyproject.toml index b2b3fb0..5781461 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ humanize = "^3.12.0" uvloop = {version = "^0.16.0", optional = true} aioredis = "^2.0.0" "discord.py" = {version = "^2.0.1", extras = ["voice"]} +jishaku = "^2.5.1" [tool.poetry.dev-dependencies] black = {version = "^21.9b0", allow-prereleases = true}