mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
Allow mocking attachment-only msg, fix docstring, small refactor (#5446)
* Use the logic from `[p]mock` in `[p]mockmsg`, fix docstring * Let people mock attachment-only messages * Use empty string, not None
This commit is contained in:
parent
90406be9ea
commit
9c05db1104
@ -340,24 +340,25 @@ class Dev(commands.Cog):
|
|||||||
|
|
||||||
@commands.command(name="mockmsg")
|
@commands.command(name="mockmsg")
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
async def mock_msg(self, ctx, user: discord.Member, *, content: str):
|
async def mock_msg(self, ctx, user: discord.Member, *, content: str = ""):
|
||||||
"""Dispatch a message event as if it were sent by a different user.
|
"""Dispatch a message event as if it were sent by a different user.
|
||||||
|
|
||||||
Only reads the raw content of the message. Attachments, embeds etc. are
|
Current message is used as a base (including attachments, embeds, etc.),
|
||||||
ignored.
|
the content and author of the message are replaced with the given arguments.
|
||||||
|
|
||||||
|
Note: If `content` isn't passed, the message needs to contain embeds, attachments,
|
||||||
|
or anything else that makes the message non-empty.
|
||||||
"""
|
"""
|
||||||
old_author = ctx.author
|
msg = ctx.message
|
||||||
old_content = ctx.message.content
|
if not content and not msg.embeds and not msg.attachments:
|
||||||
ctx.message.author = user
|
# DEP-WARN: add `msg.stickers` when adding d.py 2.0
|
||||||
ctx.message.content = content
|
await ctx.send_help()
|
||||||
|
return
|
||||||
|
msg = copy(msg)
|
||||||
|
msg.author = user
|
||||||
|
msg.content = content
|
||||||
|
|
||||||
ctx.bot.dispatch("message", ctx.message)
|
ctx.bot.dispatch("message", msg)
|
||||||
|
|
||||||
# If we change the author and content back too quickly,
|
|
||||||
# the bot won't process the mocked message in time.
|
|
||||||
await asyncio.sleep(2)
|
|
||||||
ctx.message.author = old_author
|
|
||||||
ctx.message.content = old_content
|
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user