Allow send_interactive to upload a file containing all content (#5902)

Co-authored-by: Flame442 <34169552+Flame442@users.noreply.github.com>
This commit is contained in:
TrustyJAID 2022-11-24 14:05:07 -07:00 committed by GitHub
parent 6c8b6eb71c
commit bbb15924b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,7 +9,7 @@ import discord
from discord.ext.commands import Context as DPYContext
from .requires import PermState
from ..utils.chat_formatting import box
from ..utils.chat_formatting import box, text_to_file
from ..utils.predicates import MessagePredicate
from ..utils import can_user_react_in, common_filters
@ -150,7 +150,11 @@ class Context(DPYContext):
return True
async def send_interactive(
self, messages: Iterable[str], box_lang: str = None, timeout: int = 15
self,
messages: Iterable[str],
box_lang: str = None,
timeout: int = 15,
join_character: str = "",
) -> List[discord.Message]:
"""Send multiple messages interactively.
@ -168,6 +172,9 @@ class Context(DPYContext):
timeout : int
How long the user has to respond to the prompt before it times out.
After timing out, the bot deletes its prompt message.
join_character : str
The character used to join all the messages when the file output
is selected.
"""
messages = tuple(messages)
@ -189,13 +196,14 @@ class Context(DPYContext):
is_are = "are"
query = await self.send(
"There {} still {} message{} remaining. "
"Type `more` to continue."
"Type `more` to continue or `file` to upload all contents as a file."
"".format(is_are, n_remaining, plural)
)
pred = MessagePredicate.lower_contained_in(("more", "file"), self)
try:
resp = await self.bot.wait_for(
"message",
check=MessagePredicate.lower_equal_to("more", self),
check=pred,
timeout=timeout,
)
except asyncio.TimeoutError:
@ -211,6 +219,9 @@ class Context(DPYContext):
# or channel is a DM
with contextlib.suppress(discord.HTTPException):
await query.delete()
if pred.result == 1:
await self.send(file=text_to_file(join_character.join(messages)))
break
return ret
async def embed_colour(self):