mirror of
https://github.com/RGBCube/minearchy-bot
synced 2025-07-27 17:07:45 +00:00
Cleanup
This commit is contained in:
parent
5b7fb2deba
commit
5ab80712d0
6 changed files with 45 additions and 36 deletions
|
@ -1,8 +1,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from asyncio import gather as await_parallel
|
||||
import asyncio
|
||||
from contextlib import suppress as suppress_error
|
||||
from traceback import format_exception as format_exit
|
||||
from traceback import format_exception
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from discord import HTTPException
|
||||
|
@ -61,10 +61,10 @@ class ErrorHandler(Cog):
|
|||
await ctx.reply("Invalid channel.")
|
||||
|
||||
else:
|
||||
trace = "".join(format_exit(type(error), error, error.__traceback__))
|
||||
trace = "".join(format_exception(type(error), error, error.__traceback__))
|
||||
print(f"Ignoring exception in command {ctx.command}:\n{trace}")
|
||||
|
||||
await await_parallel(
|
||||
await asyncio.gather(
|
||||
self.bot.log_webhook.send(f"<@512640455834337290>```{trace}```"),
|
||||
ctx.reply(
|
||||
"An error occurred while executing the command. The error has been reported."
|
||||
|
|
|
@ -2,7 +2,8 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from discord.ext.commands import Cog, command, group
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Cog, command
|
||||
from discord.ui import Button, View
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -19,7 +20,7 @@ class MinecraftServer(
|
|||
def __init__(self, bot: MinearchyBot) -> None:
|
||||
self.bot = bot
|
||||
|
||||
@group(
|
||||
@commands.group(
|
||||
invoke_without_command=True,
|
||||
brief="Sends the server IP.",
|
||||
help="Sends the server IP.",
|
||||
|
|
|
@ -2,14 +2,15 @@ from __future__ import annotations
|
|||
|
||||
from collections import defaultdict as DefaultDict, deque as Deque
|
||||
from datetime import timedelta as TimeDelta
|
||||
from inspect import cleandoc as strip_doc
|
||||
from inspect import cleandoc as strip
|
||||
from io import BytesIO
|
||||
from platform import python_version
|
||||
from time import monotonic as ping_time, time as current_time
|
||||
from time import monotonic as get_monotonic, time as get_time
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from discord import CategoryChannel, Color, Embed, File, TextChannel
|
||||
from discord.ext.commands import Cog, command, has_permissions
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Cog, command
|
||||
from discord.utils import escape_markdown
|
||||
|
||||
from ..utils import override
|
||||
|
@ -52,9 +53,9 @@ class Miscellaneous(
|
|||
help="Sends the bots ping."
|
||||
)
|
||||
async def ping(self, ctx: Context) -> None:
|
||||
ts = ping_time()
|
||||
ts = get_monotonic()
|
||||
message = await ctx.reply("Pong!")
|
||||
ts = ping_time() - ts
|
||||
ts = get_monotonic() - ts
|
||||
await message.edit(content=f"Pong! `{int(ts * 1000)}ms`")
|
||||
|
||||
@command(
|
||||
|
@ -63,11 +64,11 @@ class Miscellaneous(
|
|||
)
|
||||
async def info(self, ctx: Context) -> None:
|
||||
await ctx.reply(
|
||||
strip_doc(
|
||||
strip(
|
||||
f"""
|
||||
__**Bot Info**__
|
||||
**Python Version:** v{python_version()}
|
||||
**Uptime:** `{TimeDelta(seconds=int(current_time() - self.bot.ready_timestamp))}`
|
||||
**Uptime:** `{TimeDelta(seconds=int(get_time() - self.bot.ready_timestamp))}`
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
@ -155,7 +156,7 @@ class Miscellaneous(
|
|||
" isn't specified, it uses the current channel."
|
||||
),
|
||||
)
|
||||
@has_permissions(manage_messages=True) # needs to be able to delete messages to run the command
|
||||
@commands.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) -> None:
|
||||
if channel is None:
|
||||
channel = ctx.channel
|
||||
|
@ -185,7 +186,7 @@ class Miscellaneous(
|
|||
|
||||
embed.add_field(
|
||||
name=str(i) + ("" if i else " (latest)"),
|
||||
value=strip_doc(
|
||||
value=strip(
|
||||
f"""
|
||||
Author: {message.author.mention} (ID: {message.author.id}, Plain: {escape_markdown(str(message.author))})
|
||||
Deleted at: <t:{ts}:F> (Relative: <t:{ts}:R>)
|
||||
|
@ -205,7 +206,7 @@ class Miscellaneous(
|
|||
if not message.guild:
|
||||
return
|
||||
|
||||
self.sniped[message.channel.id].appendleft((message, int(current_time())))
|
||||
self.sniped[message.channel.id].appendleft((message, int(get_time())))
|
||||
|
||||
while len(self.sniped[message.channel.id]) > 5:
|
||||
self.sniped[message.channel.id].pop()
|
||||
|
|
|
@ -3,7 +3,8 @@ from __future__ import annotations
|
|||
from datetime import timedelta as TimeDelta
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from discord.ext.commands import Cog, command, has_permissions
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Cog, command
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from discord import Member
|
||||
|
@ -27,7 +28,7 @@ class Moderation(Cog):
|
|||
brief="Times out a user.",
|
||||
help="Times out a user."
|
||||
)
|
||||
@has_permissions(manage_messages=True)
|
||||
@commands.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:
|
||||
await ctx.reply("Invalid duration. Valid durations are: d, h, m, s.")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue