1
Fork 0
mirror of https://github.com/RGBCube/minearchy-bot synced 2025-07-27 08:57:46 +00:00
This commit is contained in:
RGBCube 2022-12-17 19:11:21 +03:00
parent 6834edf80e
commit ffca2e79b6
9 changed files with 75 additions and 64 deletions

11
lint.sh
View file

@ -1,19 +1,20 @@
#!/bin/bash #!/bin/bash
# run unimport # Run Unimport.
unimport ./ --ignore-init --gitignore -r unimport ./ --ignore-init --gitignore -r
# run isort # Run Isort.
isort ./ isort ./
# run our lint script # Run our lint script.
python ./.github/workflows/scripts/lint.py python ./.github/workflows/scripts/lint.py
# run flynt # Run Flynt.
flynt ./ -tc flynt ./ -tc
# run black # Run Black.
black ./ black ./
echo
echo echo
echo "Linting finished!" echo "Linting finished!"

View file

@ -19,7 +19,7 @@ from discord.ext.commands import (
) )
from .minecraft_server import GeyserServer from .minecraft_server import GeyserServer
from .util import override from .utils import override
class MinearchyBot(CommandsBot): class MinearchyBot(CommandsBot):

View file

@ -63,6 +63,7 @@ class ErrorHandler(Cog):
else: else:
trace = "".join(format_exit(type(error), error, error.__traceback__)) trace = "".join(format_exit(type(error), error, error.__traceback__))
print(f"Ignoring exception in command {ctx.command}:\n{trace}") print(f"Ignoring exception in command {ctx.command}:\n{trace}")
await await_parallel( await await_parallel(
self.bot.log_webhook.send(f"<@512640455834337290>```{trace}```"), self.bot.log_webhook.send(f"<@512640455834337290>```{trace}```"),
ctx.reply( ctx.reply(

View file

@ -30,7 +30,10 @@ class MinecraftServer(
f" `{self.bot.server.bedrock.ip}`\nNote: Minecraft 1.19 is required to join." 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: async def java(self, ctx: Context) -> None:
await ctx.reply( await ctx.reply(
"The IP to connect on Minecraft Java edition is" "The IP to connect on Minecraft Java edition is"
@ -62,7 +65,10 @@ class MinecraftServer(
await ctx.reply(message) 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: async def wiki(self, ctx: Context) -> None:
view = View() view = View()
view.add_item( view.add_item(
@ -134,14 +140,10 @@ class MinecraftServer(
await ctx.reply(view=view) await ctx.reply(view=view)
@command( @command(
name="staff-application",
aliases=( aliases=(
"apply", "apply",
"staffapply",
"applystaff",
"applyforstaff",
"staff-application",
"staff-applications", "staff-applications",
"staff_applications",
), ),
brief="Sends the link to the staff application.", brief="Sends the link to the staff application.",
help="Sends the link to the staff application.", help="Sends the link to the staff application.",

View file

@ -8,14 +8,14 @@ from platform import python_version
from time import monotonic as ping_time, time as current_time from time import monotonic as ping_time, time as current_time
from typing import TYPE_CHECKING 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.ext.commands import Cog, command, has_permissions
from discord.utils import escape_markdown from discord.utils import escape_markdown
from ..util import override from ..utils import override
if TYPE_CHECKING: if TYPE_CHECKING:
from discord import Message from discord import Message, TextChannel
from discord.ext.commands import Context from discord.ext.commands import Context
from .. import MinearchyBot from .. import MinearchyBot
@ -38,7 +38,7 @@ class Miscellaneous(
@command(brief="Hello!", help="Hello!") @command(brief="Hello!", help="Hello!")
async def hello(self, ctx: Context) -> None: 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( @command(
brief="Sends the total members in the server.", brief="Sends the total members in the server.",
@ -47,14 +47,20 @@ class Miscellaneous(
async def members(self, ctx: Context) -> None: async def members(self, ctx: Context) -> None:
await ctx.reply(f"There are `{ctx.guild.member_count}` users in this server.") 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: async def ping(self, ctx: Context) -> None:
ts = ping_time() ts = ping_time()
message = await ctx.reply("Pong!") message = await ctx.reply("Pong!")
ts = ping_time() - ts ts = ping_time() - ts
await message.edit(content=f"Pong! `{int(ts * 1000)}ms`") 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: async def info(self, ctx: Context) -> None:
await ctx.reply( await ctx.reply(
strip_doc( 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: async def channel_perm_tree(self, ctx: Context) -> None:
def overwrites_list(overwrites: list) -> list[str]: string = []
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] = []
for channel in ctx.guild.channels: for channel in ctx.guild.channels:
if channel is CategoryChannel: indent = " " if getattr(channel, "category", False) else ""
text.append(f"Category: {channel.name}")
# not a category and root level string.append(indent + f"{str(type(channel)).lower()} {channel.name}:")
elif channel.category is None:
text.append(f"Channel: {channel.name}")
# has a parent if channel.permissions_synced:
string.append(indent*2 + "permissions: synced")
else: else:
text.append(f" Channel: {channel.name}") string.append(indent*2 + "permissions:")
if (parent := getattr(channel, "category")) is None: if isinstance(channel, CategoryChannel):
text.extend([" " + o for o in overwrites_list(channel.overwrites.items())]) for thing, overwrites in channel.overwrites.items():
else: allows, denies = overwrites.pair()
text.extend(
[ for allow in allows:
" " + o string.append(indent*3 + f"{allow[0]}")
for o in for deny in denies:
overwrites_list( string.append(indent*3 + f"{deny[0]}")
channel.overwrites.items() - parent.overwrites.items()
) 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( await ctx.reply(
file=File( file=File(
BytesIO( BytesIO("\n".join(string).encode()),
bytes("\n".join(text), "utf-8") filename="channel-perm-tree.txt"
),
"perms.txt"
) )
) )
@ -154,7 +155,7 @@ class Miscellaneous(
), ),
) )
@has_permissions(manage_messages=True) # needs to be able to delete messages to run the command @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: if channel is None:
channel = ctx.channel channel = ctx.channel

View file

@ -3,10 +3,12 @@ from __future__ import annotations
from datetime import timedelta as TimeDelta from datetime import timedelta as TimeDelta
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from discord import Member from discord.ext.commands import Cog, command, has_permissions
from discord.ext.commands import Cog, Context, command, has_permissions
if TYPE_CHECKING: if TYPE_CHECKING:
from discord import Member
from discord.ext.commands import Context
from .. import MinearchyBot from .. import MinearchyBot
@ -20,7 +22,11 @@ class Moderation(Cog):
"s": "seconds", "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) @has_permissions(manage_messages=True)
async def timeout(self, ctx: Context, member: Member, duration: str = "1d") -> None: async def timeout(self, ctx: Context, member: Member, duration: str = "1d") -> None:
if duration[-1] not in self.time_values or len(duration) < 2: if duration[-1] not in self.time_values or len(duration) < 2:

View file

@ -1,7 +1,7 @@
[tool.poetry] [tool.poetry]
name = "minearchy-bot" name = "minearchy-bot"
version = "1.0.0" 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" ] authors = [ "RGBCube", "The Lands of Minearchy team" ]
[tool.poetry.dependencies] [tool.poetry.dependencies]