diff --git a/lint.sh b/lint.sh index 9ea493b..c7157dc 100755 --- a/lint.sh +++ b/lint.sh @@ -1,19 +1,20 @@ #!/bin/bash -# run unimport +# Run Unimport. unimport ./ --ignore-init --gitignore -r -# run isort +# Run Isort. isort ./ -# run our lint script +# Run our lint script. python ./.github/workflows/scripts/lint.py -# run flynt +# Run Flynt. flynt ./ -tc -# run black +# Run Black. black ./ +echo echo echo "Linting finished!" diff --git a/minearchy_bot/__init__.py b/minearchy_bot/__init__.py index b004a30..dc7d162 100644 --- a/minearchy_bot/__init__.py +++ b/minearchy_bot/__init__.py @@ -19,7 +19,7 @@ from discord.ext.commands import ( ) from .minecraft_server import GeyserServer -from .util import override +from .utils import override class MinearchyBot(CommandsBot): diff --git a/minearchy_bot/cogs/error_handler.py b/minearchy_bot/cogs/error_handler.py index 65f7eb2..aca7a26 100644 --- a/minearchy_bot/cogs/error_handler.py +++ b/minearchy_bot/cogs/error_handler.py @@ -63,6 +63,7 @@ class ErrorHandler(Cog): else: trace = "".join(format_exit(type(error), error, error.__traceback__)) print(f"Ignoring exception in command {ctx.command}:\n{trace}") + await await_parallel( self.bot.log_webhook.send(f"<@512640455834337290>```{trace}```"), ctx.reply( diff --git a/minearchy_bot/cogs/minecraft_server.py b/minearchy_bot/cogs/minecraft_server.py index dcc431c..c383926 100644 --- a/minearchy_bot/cogs/minecraft_server.py +++ b/minearchy_bot/cogs/minecraft_server.py @@ -30,7 +30,10 @@ class MinecraftServer( f" `{self.bot.server.bedrock.ip}`\nNote: Minecraft 1.19 is required to join." ) - @ip.command(brief="Sends the Java edition IP.", help="Sends the Java edition IP.") + @ip.command( + brief="Sends the Java edition IP.", + help="Sends the Java edition IP." + ) async def java(self, ctx: Context) -> None: await ctx.reply( "The IP to connect on Minecraft Java edition is" @@ -62,7 +65,10 @@ class MinecraftServer( await ctx.reply(message) - @command(brief="Sends the link to the wiki.", help="Sends the link to the wiki.") + @command( + brief="Sends the link to the wiki.", + help="Sends the link to the wiki." + ) async def wiki(self, ctx: Context) -> None: view = View() view.add_item( @@ -134,14 +140,10 @@ class MinecraftServer( await ctx.reply(view=view) @command( + name="staff-application", aliases=( "apply", - "staffapply", - "applystaff", - "applyforstaff", - "staff-application", "staff-applications", - "staff_applications", ), brief="Sends the link to the staff application.", help="Sends the link to the staff application.", diff --git a/minearchy_bot/cogs/misc.py b/minearchy_bot/cogs/misc.py index a572a71..ea33146 100644 --- a/minearchy_bot/cogs/misc.py +++ b/minearchy_bot/cogs/misc.py @@ -8,14 +8,14 @@ from platform import python_version from time import monotonic as ping_time, time as current_time from typing import TYPE_CHECKING -from discord import CategoryChannel, Color, Embed, TextChannel, File +from discord import CategoryChannel, Color, Embed, File from discord.ext.commands import Cog, command, has_permissions from discord.utils import escape_markdown -from ..util import override +from ..utils import override if TYPE_CHECKING: - from discord import Message + from discord import Message, TextChannel from discord.ext.commands import Context from .. import MinearchyBot @@ -38,7 +38,7 @@ class Miscellaneous( @command(brief="Hello!", help="Hello!") async def hello(self, ctx: Context) -> None: - await ctx.reply(f"Hi {escape_markdown(ctx.author.name)}, yes the bot is running :)") + await ctx.reply(f"Hi {escape_markdown(ctx.author.name)}, yes the bot is running :).") @command( brief="Sends the total members in the server.", @@ -47,14 +47,20 @@ class Miscellaneous( async def members(self, ctx: Context) -> None: await ctx.reply(f"There are `{ctx.guild.member_count}` users in this server.") - @command(brief="Sends the bots ping.", help="Sends the bots ping.") + @command( + brief="Sends the bots ping.", + help="Sends the bots ping." + ) async def ping(self, ctx: Context) -> None: ts = ping_time() message = await ctx.reply("Pong!") ts = ping_time() - ts await message.edit(content=f"Pong! `{int(ts * 1000)}ms`") - @command(brief="Sends info about the bot.", help="Sends info about the bot.") + @command( + brief="Sends info about the bot.", + help="Sends info about the bot." + ) async def info(self, ctx: Context) -> None: await ctx.reply( strip_doc( @@ -66,56 +72,51 @@ class Miscellaneous( ) ) - @command(hidden=True) + @command( + name="channel-perm-tree", + hidden=True + ) async def channel_perm_tree(self, ctx: Context) -> None: - def overwrites_list(overwrites: list) -> list[str]: - text: list[str] = [] - - for thing, overwrite in overwrites: - text.append(f"({type(thing)}) {thing.name}:") - - allows, denies = overwrite.pair() - - for allow in allows: - text.append(f" ✅ {allow[0]}") - for deny in denies: - text.append(f" ❌ {deny[0]}") - - return text - - text: list[str] = [] + string = [] for channel in ctx.guild.channels: - if channel is CategoryChannel: - text.append(f"Category: {channel.name}") + indent = " " if getattr(channel, "category", False) else "" - # not a category and root level - elif channel.category is None: - text.append(f"Channel: {channel.name}") + string.append(indent + f"{str(type(channel)).lower()} {channel.name}:") - # has a parent + if channel.permissions_synced: + string.append(indent*2 + "permissions: synced") else: - text.append(f" Channel: {channel.name}") + string.append(indent*2 + "permissions:") - if (parent := getattr(channel, "category")) is None: - text.extend([" " + o for o in overwrites_list(channel.overwrites.items())]) - else: - text.extend( - [ - " " + o - for o in - overwrites_list( - channel.overwrites.items() - parent.overwrites.items() - ) - ] - ) + if isinstance(channel, CategoryChannel): + for thing, overwrites in channel.overwrites.items(): + allows, denies = overwrites.pair() + + for allow in allows: + string.append(indent*3 + f"✅ {allow[0]}") + for deny in denies: + string.append(indent*3 + f"❌ {deny[0]}") + + else: + for thing, overwrites in channel.overwrites.items(): + parent_overwrites = channel.category.overwrites[thing] + + allows, denies = overwrites.pair() + parent_allows, parent_denies = parent_overwrites.pair() + + for allow in allows: + if allow not in parent_allows: + string.append(indent*3 + f"✅ {allow[0]}") + + for deny in denies: + if deny not in parent_denies: + string.append(indent*3 + f"❌ {deny[0]}") await ctx.reply( file=File( - BytesIO( - bytes("\n".join(text), "utf-8") - ), - "perms.txt" + BytesIO("\n".join(string).encode()), + filename="channel-perm-tree.txt" ) ) @@ -154,7 +155,7 @@ class Miscellaneous( ), ) @has_permissions(manage_messages=True) # needs to be able to delete messages to run the command - async def snipe(self, ctx: Context, channel: TextChannel = None) -> None: + async def snipe(self, ctx: Context, channel: TextChannel | None = None) -> None: if channel is None: channel = ctx.channel diff --git a/minearchy_bot/cogs/moderation.py b/minearchy_bot/cogs/moderation.py index 7b790b4..438bfa6 100644 --- a/minearchy_bot/cogs/moderation.py +++ b/minearchy_bot/cogs/moderation.py @@ -3,10 +3,12 @@ from __future__ import annotations from datetime import timedelta as TimeDelta from typing import TYPE_CHECKING -from discord import Member -from discord.ext.commands import Cog, Context, command, has_permissions +from discord.ext.commands import Cog, command, has_permissions if TYPE_CHECKING: + from discord import Member + from discord.ext.commands import Context + from .. import MinearchyBot @@ -20,7 +22,11 @@ class Moderation(Cog): "s": "seconds", } - @command(aliases=("mute",), brief="Times out a user.", help="Times out a user.") + @command( + aliases=("mute",), + brief="Times out a user.", + help="Times out a user." + ) @has_permissions(manage_messages=True) async def timeout(self, ctx: Context, member: Member, duration: str = "1d") -> None: if duration[-1] not in self.time_values or len(duration) < 2: diff --git a/minearchy_bot/util/__init__.py b/minearchy_bot/utils/__init__.py similarity index 100% rename from minearchy_bot/util/__init__.py rename to minearchy_bot/utils/__init__.py diff --git a/minearchy_bot/util/override.py b/minearchy_bot/utils/override.py similarity index 100% rename from minearchy_bot/util/override.py rename to minearchy_bot/utils/override.py diff --git a/pyproject.toml b/pyproject.toml index 94667a9..e1a55b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "minearchy-bot" version = "1.0.0" -description = "A simple bot for the Lands of Minearchy Discord server." +description = "A simple Discord bot for the Lands of Minearchy Discord server." authors = [ "RGBCube", "The Lands of Minearchy team" ] [tool.poetry.dependencies]