Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions bot/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
from contextlib import suppress

import arrow
import discord
from aiohttp import ClientSession
from discord import Member, NotFound
from discord.ext import commands
from discord.ext.commands import Cog, Context
from pydis_core.utils import scheduling
from pydis_core.utils.paste_service import PasteFile, PasteUploadError, send_to_paste_service

from bot.constants import Channels, DEBUG_MODE, RedirectOutput
from bot.log import get_logger
Expand Down Expand Up @@ -154,8 +157,39 @@ async def inner(self: Cog, ctx: Context, *args, **kwargs) -> None:
log.trace(f"Redirecting output of {ctx.author}'s command '{ctx.command.name}' to {redirect_channel.name}")
ctx.channel = redirect_channel

if ping_user:
await ctx.send(f"Here's the output of your command, {ctx.author.mention}")
paste_response = None
if RedirectOutput.delete_invocation:
async with ClientSession() as session:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should use ctx.bot.http_session rather than creating a whole new session.

try:
paste_response = await send_to_paste_service(
files=[PasteFile(content=ctx.message.content, lexer="markdown")],
http_session=session,
Comment thread
wookie184 marked this conversation as resolved.
)
except PasteUploadError:
log.exception(
"Failed to upload message %d in channel %d to paste service when redirecting output",
ctx.message.id, ctx.message.channel.id
)
Comment thread
wookie184 marked this conversation as resolved.

msg = "Here's the output of "
msg += f"[your command]({paste_response.link})" if paste_response else "your command"
msg += f", {ctx.author.mention}:" if ping_user else ":"

await ctx.send(msg)
Comment thread
wookie184 marked this conversation as resolved.
if paste_response:
try:
# Send a DM to the user about the redirect and paste removal
await ctx.author.send(
f"Your command output was redirected to <#{Channels.bot_commands}>."
f" [Click here](<{paste_response.removal}>) to delete the pasted"
" copy of your original command."
)
except discord.Forbidden:
log.info(
"Failed to DM %s with redirected command paste removal link, user has bot DMs disabled",
ctx.author.name
)

scheduling.create_task(func(self, ctx, *args, **kwargs))

message = await old_channel.send(
Expand Down