mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
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:
parent
6c8b6eb71c
commit
bbb15924b9
@ -9,7 +9,7 @@ import discord
|
|||||||
from discord.ext.commands import Context as DPYContext
|
from discord.ext.commands import Context as DPYContext
|
||||||
|
|
||||||
from .requires import PermState
|
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.predicates import MessagePredicate
|
||||||
from ..utils import can_user_react_in, common_filters
|
from ..utils import can_user_react_in, common_filters
|
||||||
|
|
||||||
@ -150,7 +150,11 @@ class Context(DPYContext):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
async def send_interactive(
|
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]:
|
) -> List[discord.Message]:
|
||||||
"""Send multiple messages interactively.
|
"""Send multiple messages interactively.
|
||||||
|
|
||||||
@ -168,6 +172,9 @@ class Context(DPYContext):
|
|||||||
timeout : int
|
timeout : int
|
||||||
How long the user has to respond to the prompt before it times out.
|
How long the user has to respond to the prompt before it times out.
|
||||||
After timing out, the bot deletes its prompt message.
|
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)
|
messages = tuple(messages)
|
||||||
@ -189,13 +196,14 @@ class Context(DPYContext):
|
|||||||
is_are = "are"
|
is_are = "are"
|
||||||
query = await self.send(
|
query = await self.send(
|
||||||
"There {} still {} message{} remaining. "
|
"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)
|
"".format(is_are, n_remaining, plural)
|
||||||
)
|
)
|
||||||
|
pred = MessagePredicate.lower_contained_in(("more", "file"), self)
|
||||||
try:
|
try:
|
||||||
resp = await self.bot.wait_for(
|
resp = await self.bot.wait_for(
|
||||||
"message",
|
"message",
|
||||||
check=MessagePredicate.lower_equal_to("more", self),
|
check=pred,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
)
|
)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
@ -211,6 +219,9 @@ class Context(DPYContext):
|
|||||||
# or channel is a DM
|
# or channel is a DM
|
||||||
with contextlib.suppress(discord.HTTPException):
|
with contextlib.suppress(discord.HTTPException):
|
||||||
await query.delete()
|
await query.delete()
|
||||||
|
if pred.result == 1:
|
||||||
|
await self.send(file=text_to_file(join_character.join(messages)))
|
||||||
|
break
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
async def embed_colour(self):
|
async def embed_colour(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user