fix(bot): 🐛 Fix reply argument conversion.
This commit is contained in:
@@ -337,6 +337,9 @@ class Payphone(commands.AutoShardedBot):
|
|||||||
f"❌ You're going too fast! Wait `{int(exception.retry_after)}` seconds before trying again."
|
f"❌ You're going too fast! Wait `{int(exception.retry_after)}` seconds before trying again."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
elif isinstance(exception, errors.NotOwner):
|
||||||
|
await context.send("❌ You're not the owner of this bot.")
|
||||||
|
|
||||||
elif isinstance(exception, errors.CommandNotFound):
|
elif isinstance(exception, errors.CommandNotFound):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class Mods(base.Cog):
|
|||||||
async def ban(
|
async def ban(
|
||||||
self,
|
self,
|
||||||
ctx: commands.Context,
|
ctx: commands.Context,
|
||||||
user: discord.User | discord.Member | converters.DiscordUser,
|
user: converters.DiscordUserID,
|
||||||
time: converters.Timedelta | None = None,
|
time: converters.Timedelta | None = None,
|
||||||
*,
|
*,
|
||||||
reason: str | None = "",
|
reason: str | None = "",
|
||||||
@@ -42,13 +42,7 @@ class Mods(base.Cog):
|
|||||||
- `[<reason>]`: The reason of their ban.
|
- `[<reason>]`: The reason of their ban.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
user_id = None
|
user_id = user
|
||||||
|
|
||||||
if isinstance(user, (discord.User, discord.Member)):
|
|
||||||
user_id = user.id
|
|
||||||
|
|
||||||
else:
|
|
||||||
user_id = user
|
|
||||||
|
|
||||||
profile = await models.Profile.filter(user_id=user_id).limit(1).first()
|
profile = await models.Profile.filter(user_id=user_id).limit(1).first()
|
||||||
|
|
||||||
@@ -88,7 +82,7 @@ class Mods(base.Cog):
|
|||||||
async def unban(
|
async def unban(
|
||||||
self,
|
self,
|
||||||
ctx: commands.Context,
|
ctx: commands.Context,
|
||||||
user: discord.User | discord.Member | converters.DiscordUser,
|
user: converters.DiscordUserID,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Unbans a user by their ID, pinging them, or replying to their message. The user will be
|
Unbans a user by their ID, pinging them, or replying to their message. The user will be
|
||||||
@@ -98,7 +92,7 @@ class Mods(base.Cog):
|
|||||||
- `<user>`: The user to unban or their ID.
|
- `<user>`: The user to unban or their ID.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
user_id = user if isinstance(user, int) else user.id
|
user_id = user
|
||||||
|
|
||||||
await self.bot.unban(user_id)
|
await self.bot.unban(user_id)
|
||||||
|
|
||||||
@@ -121,7 +115,7 @@ class Mods(base.Cog):
|
|||||||
async def warn(
|
async def warn(
|
||||||
self,
|
self,
|
||||||
ctx: commands.Context,
|
ctx: commands.Context,
|
||||||
user: discord.User | discord.Member | converters.DiscordUser,
|
user: converters.DiscordUserID,
|
||||||
*,
|
*,
|
||||||
reason: str,
|
reason: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
@@ -133,7 +127,7 @@ class Mods(base.Cog):
|
|||||||
- `<reason>`: The reason of the warn.
|
- `<reason>`: The reason of the warn.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
user_id = user if isinstance(user, int) else user.id
|
user_id = user
|
||||||
|
|
||||||
user = None
|
user = None
|
||||||
|
|
||||||
@@ -316,7 +310,7 @@ class Mods(base.Cog):
|
|||||||
f"Profiles: {await models.Profile.all().count()}",
|
f"Profiles: {await models.Profile.all().count()}",
|
||||||
f"Servers: {await models.Server.all().count()}",
|
f"Servers: {await models.Server.all().count()}",
|
||||||
f"Shards: {self.bot.shard_count}",
|
f"Shards: {self.bot.shard_count}",
|
||||||
f"Current Shard: {ctx.guild.shard_id + 1}"
|
f"Current Shard: {ctx.guild.shard_id + 1}",
|
||||||
]
|
]
|
||||||
|
|
||||||
await ctx.send(f"```\n{"\n".join(stats)}\n```")
|
await ctx.send(f"```\n{"\n".join(stats)}\n```")
|
||||||
|
|||||||
+20
-17
@@ -3,6 +3,8 @@ from datetime import timedelta
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.ext.commands import converter
|
from discord.ext.commands import converter
|
||||||
|
|
||||||
|
from tortoise import expressions
|
||||||
|
|
||||||
from payphone.db import models
|
from payphone.db import models
|
||||||
from payphone.core import exceptions
|
from payphone.core import exceptions
|
||||||
|
|
||||||
@@ -38,10 +40,13 @@ class Timedelta(converter.Converter):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DiscordUser(converter.Converter):
|
class DiscordUserID(converter.Converter):
|
||||||
"""Converts a URL, ID, or reply into a Discord User ID."""
|
"""Converts a URL, ID, or reply into a Discord User ID."""
|
||||||
|
|
||||||
async def converter(self, ctx: commands.Context, argument: str) -> int:
|
async def convert(self, ctx: commands.Context, argument: str) -> int:
|
||||||
|
if len(argument) > 17 and argument[:2] == "<@" and argument[-1] == ">":
|
||||||
|
return int(argument[2:-1])
|
||||||
|
|
||||||
if argument.isdecimal() and len(argument) in range(17, 19):
|
if argument.isdecimal() and len(argument) in range(17, 19):
|
||||||
return int(argument)
|
return int(argument)
|
||||||
|
|
||||||
@@ -50,27 +55,25 @@ class DiscordUser(converter.Converter):
|
|||||||
):
|
):
|
||||||
return int(argument.split("?", 1)[0].rsplit("/", 1)[1])
|
return int(argument.split("?", 1)[0].rsplit("/", 1)[1])
|
||||||
|
|
||||||
if ctx.message.reference is not None:
|
if argument.lower() in ["reply", "."]:
|
||||||
ref = ctx.message.reference
|
if ctx.message.reference is not None:
|
||||||
|
ref = ctx.message.reference
|
||||||
|
|
||||||
if ref.cached_message is not None:
|
msg = ref.cached_message or await ctx.channel().fetch_message(
|
||||||
msg = ref.cached_message
|
ref.message_id
|
||||||
|
)
|
||||||
|
|
||||||
if msg.author.bot:
|
if msg.author.bot:
|
||||||
row = await models.Message.get_or_none(id=msg.id)
|
row = await models.Message.get_or_none(
|
||||||
|
expressions.Q(id=msg.id, propagation_id=msg.id, join_type="OR")
|
||||||
|
)
|
||||||
|
|
||||||
if row is not None:
|
if row is not None:
|
||||||
return row.user_id
|
return row.user_id
|
||||||
|
|
||||||
raise ValueError()
|
raise converter.BadArgument()
|
||||||
|
|
||||||
return msg.author.id
|
else:
|
||||||
|
return msg.author.id
|
||||||
|
|
||||||
row = await models.Message.get_or_none(id=ref.message_id)
|
raise converter.BadArgument()
|
||||||
|
|
||||||
if row is not None:
|
|
||||||
return row.user_id
|
|
||||||
|
|
||||||
raise ValueError()
|
|
||||||
|
|
||||||
raise ValueError()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user