mirror of
https://github.com/RGBCube/minearchy-bot
synced 2025-07-27 08:57:46 +00:00
Handle a few more errors & format
This commit is contained in:
parent
c619bf5e63
commit
99cb747dea
5 changed files with 50 additions and 28 deletions
10
bot.py
10
bot.py
|
@ -43,7 +43,10 @@ class MinearchyBot(commands.Bot):
|
||||||
strip_after_prefix=True,
|
strip_after_prefix=True,
|
||||||
help_attrs=dict(
|
help_attrs=dict(
|
||||||
brief="Sends help.",
|
brief="Sends help.",
|
||||||
help="Sends all the commands of the bot, or help of a specific command and module.",
|
help=(
|
||||||
|
"Sends all the commands of the bot, or help of a specific command"
|
||||||
|
" and module."
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -89,9 +92,6 @@ with open("./config.json") as f:
|
||||||
for key in ["BOT_TOKEN", "WEBHOOK_URL"]:
|
for key in ["BOT_TOKEN", "WEBHOOK_URL"]:
|
||||||
config.setdefault(key, os.getenv(key))
|
config.setdefault(key, os.getenv(key))
|
||||||
|
|
||||||
bot = MinearchyBot(
|
bot = MinearchyBot(token=config["BOT_TOKEN"], webhook_url=config["WEBHOOK_URL"])
|
||||||
token=config["BOT_TOKEN"],
|
|
||||||
webhook_url=config["WEBHOOK_URL"]
|
|
||||||
)
|
|
||||||
|
|
||||||
bot.run()
|
bot.run()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import traceback
|
import traceback
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
@ -32,24 +33,27 @@ class ErrorHandler(commands.Cog):
|
||||||
return
|
return
|
||||||
|
|
||||||
elif isinstance(error, commands.NoPrivateMessage):
|
elif isinstance(error, commands.NoPrivateMessage):
|
||||||
try:
|
with contextlib.suppress(discord.HTTPException):
|
||||||
await ctx.author.send(
|
await ctx.author.send(
|
||||||
f"The commmand `{ctx.command}` cannot be used in DMs."
|
f"The command `{ctx.command.qualified_name}` cannot be used in DMs."
|
||||||
)
|
)
|
||||||
except discord.HTTPException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
elif isinstance(error, commands.MissingPermissions):
|
elif isinstance(error, (commands.MissingPermissions, commands.NotOwner)):
|
||||||
await ctx.reply("You can't use this command!")
|
await ctx.reply("You can't use this command!")
|
||||||
|
|
||||||
elif isinstance(error, commands.MissingRequiredArgument):
|
elif isinstance(error, commands.MissingRequiredArgument):
|
||||||
await ctx.reply(f"Missing a required argument: `{error.param.name}`")
|
await ctx.reply(f"Missing a required argument: `{error.param.name}`.")
|
||||||
|
|
||||||
|
elif isinstance(error, commands.TooManyArguments):
|
||||||
|
await ctx.reply("Too many arguments.")
|
||||||
|
|
||||||
elif isinstance(error, commands.ChannelNotFound):
|
elif isinstance(error, commands.ChannelNotFound):
|
||||||
await ctx.reply("Invalid channel.")
|
await ctx.reply("Invalid channel.")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
trace = "".join(traceback.format_exception(type(error), error, error.__traceback__))
|
trace = "".join(
|
||||||
|
traceback.format_exception(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 self.bot.log_webhook.send(f"<@512640455834337290>```{trace}```")
|
await self.bot.log_webhook.send(f"<@512640455834337290>```{trace}```")
|
||||||
|
|
||||||
|
|
|
@ -24,13 +24,16 @@ class MinecraftServer(
|
||||||
)
|
)
|
||||||
async def ip(self, ctx: commands.Context) -> None:
|
async def ip(self, ctx: commands.Context) -> None:
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
f"Java edition IP: `{self.bot.mc_server.ip}`\nBedrock edition IP: `{self.bot.mc_server.bedrock_ip}` (Port: 19132)\nNote: Minecraft 1.18+ is required to join."
|
f"Java edition IP: `{self.bot.mc_server.ip}`\nBedrock edition IP:"
|
||||||
|
f" `{self.bot.mc_server.bedrock_ip}` (Port: 19132)\nNote: Minecraft 1.18+"
|
||||||
|
" 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: commands.Context) -> None:
|
async def java(self, ctx: commands.Context) -> None:
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
f"The IP to connect on Minecraft Java edition is `{self.bot.mc_server.ip}`\nNote: Minecraft 1.18+ is required to join."
|
"The IP to connect on Minecraft Java edition is"
|
||||||
|
f" `{self.bot.mc_server.ip}`\nNote: Minecraft 1.18+ is required to join."
|
||||||
)
|
)
|
||||||
|
|
||||||
@ip.command(
|
@ip.command(
|
||||||
|
@ -39,12 +42,17 @@ class MinecraftServer(
|
||||||
)
|
)
|
||||||
async def bedrock(self, ctx: commands.Context) -> None:
|
async def bedrock(self, ctx: commands.Context) -> None:
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
f"The IP to connect on Minecraft Bedrock edition is `{self.bot.mc_server.bedrock_ip}` (Port: 19132)\nNote: Minecraft 1.18+ is required to join."
|
"The IP to connect on Minecraft Bedrock edition is"
|
||||||
|
f" `{self.bot.mc_server.bedrock_ip}` (Port: 19132)\nNote: Minecraft 1.18+"
|
||||||
|
" is required to join."
|
||||||
)
|
)
|
||||||
|
|
||||||
@commands.command(
|
@commands.command(
|
||||||
brief="Shows information about the Minecraft server.",
|
brief="Shows information about the Minecraft server.",
|
||||||
help="Shows the total player count, the Minecraft server IP and the server latency.",
|
help=(
|
||||||
|
"Shows the total player count, the Minecraft server IP and the server"
|
||||||
|
" latency."
|
||||||
|
),
|
||||||
)
|
)
|
||||||
async def status(self, ctx: commands.Context) -> None:
|
async def status(self, ctx: commands.Context) -> None:
|
||||||
server = self.bot.mc_server
|
server = self.bot.mc_server
|
||||||
|
|
21
cogs/misc.py
21
cogs/misc.py
|
@ -46,7 +46,9 @@ class Miscellanious(
|
||||||
)
|
)
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="Uptime",
|
name="Uptime",
|
||||||
value=f"```{datetime.timedelta(seconds=int(time.time() - self.bot.up_ts))}```",
|
value=(
|
||||||
|
f"```{datetime.timedelta(seconds=int(time.time() - self.bot.up_ts))}```"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
await ctx.reply(embed=embed)
|
await ctx.reply(embed=embed)
|
||||||
|
|
||||||
|
@ -76,7 +78,10 @@ class Miscellanious(
|
||||||
|
|
||||||
@commands.command(
|
@commands.command(
|
||||||
brief="Sends the latest deleted messages.",
|
brief="Sends the latest deleted messages.",
|
||||||
help="Sends the last 5 deleted messages in a specified channel.\nIf the channel isn't specified, it uses the current channel.",
|
help=(
|
||||||
|
"Sends the last 5 deleted messages in a specified channel.\nIf the channel"
|
||||||
|
" isn't specified, it uses the current channel."
|
||||||
|
),
|
||||||
)
|
)
|
||||||
@commands.has_permissions(
|
@commands.has_permissions(
|
||||||
manage_messages=True
|
manage_messages=True
|
||||||
|
@ -91,12 +96,16 @@ class Miscellanious(
|
||||||
|
|
||||||
if not logs:
|
if not logs:
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
f"There are no messages to be sniped in {'this channel.' if channel.id == ctx.channel.id else channel.mention}"
|
"There are no messages to be sniped in"
|
||||||
|
f" {'this channel.' if channel.id == ctx.channel.id else channel.mention}"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title=f"Showing last 5 deleted messages for {'the current channel' if ctx.channel.id == channel.id else channel}",
|
title=(
|
||||||
|
"Showing last 5 deleted messages for"
|
||||||
|
f" {'the current channel' if ctx.channel.id == channel.id else channel}"
|
||||||
|
),
|
||||||
description="The lower the number is, the more recent it got deleted.",
|
description="The lower the number is, the more recent it got deleted.",
|
||||||
color=self.bot.embed_color,
|
color=self.bot.embed_color,
|
||||||
)
|
)
|
||||||
|
@ -104,7 +113,7 @@ class Miscellanious(
|
||||||
for i, log in reversed(list(enumerate(logs))):
|
for i, log in reversed(list(enumerate(logs))):
|
||||||
message, ts = log
|
message, ts = log
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name=str(i) + (" (latest)" if not i else ""),
|
name=str(i) + ("" if i else " (latest)"),
|
||||||
value=inspect.cleandoc(
|
value=inspect.cleandoc(
|
||||||
f"""Author: {message.author.mention} (ID: {message.author.id}, Plain: {discord.utils.escape_markdown(str(message.author))})
|
f"""Author: {message.author.mention} (ID: {message.author.id}, Plain: {discord.utils.escape_markdown(str(message.author))})
|
||||||
Deleted at: <t:{ts}:F> (Relative: <t:{ts}:R>)
|
Deleted at: <t:{ts}:F> (Relative: <t:{ts}:R>)
|
||||||
|
@ -112,7 +121,7 @@ class Miscellanious(
|
||||||
```
|
```
|
||||||
{message.content.replace('`', f'{zwsp}`{zwsp}')}
|
{message.content.replace('`', f'{zwsp}`{zwsp}')}
|
||||||
```"""
|
```"""
|
||||||
), # zero-width spaces, or it will break.
|
),
|
||||||
inline=False,
|
inline=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,8 @@ class Suggestions(commands.Cog):
|
||||||
await message.add_reaction("❌")
|
await message.add_reaction("❌")
|
||||||
|
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
f"Suggestion submitted!\nYou can view it at {self.bot.suggestions_channel.mention}"
|
"Suggestion submitted!\nYou can view it at"
|
||||||
|
f" {self.bot.suggestions_channel.mention}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue