Add delete_after parameter to MessageChannel.send
This commit is contained in:
parent
20ddc9f14f
commit
4e175d36d3
@ -145,7 +145,7 @@ class MessageChannel(metaclass=abc.ABCMeta):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def send(self, content=None, *, tts=False, embed=None, file=None, filename=None):
|
def send(self, content=None, *, tts=False, embed=None, file=None, filename=None, delete_after=None):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
Sends a message to the channel with the content given.
|
Sends a message to the channel with the content given.
|
||||||
@ -185,6 +185,10 @@ class MessageChannel(metaclass=abc.ABCMeta):
|
|||||||
The filename of the file. Defaults to ``file.name`` if it's available.
|
The filename of the file. Defaults to ``file.name`` if it's available.
|
||||||
If this is provided, you must also provide the ``file`` parameter or it
|
If this is provided, you must also provide the ``file`` parameter or it
|
||||||
is silently ignored.
|
is silently ignored.
|
||||||
|
delete_after: float
|
||||||
|
If provided, the number of seconds to wait in the background
|
||||||
|
before deleting the message we just sent. If the deletion fails,
|
||||||
|
then it is silently ignored.
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
--------
|
--------
|
||||||
@ -219,7 +223,17 @@ class MessageChannel(metaclass=abc.ABCMeta):
|
|||||||
else:
|
else:
|
||||||
data = yield from state.http.send_message(channel_id, content, guild_id=guild_id, tts=tts, embed=embed)
|
data = yield from state.http.send_message(channel_id, content, guild_id=guild_id, tts=tts, embed=embed)
|
||||||
|
|
||||||
return Message(channel=self, state=state, data=data)
|
ret = Message(channel=self, state=state, data=data)
|
||||||
|
if delete_after is not None:
|
||||||
|
@asyncio.coroutine
|
||||||
|
def delete():
|
||||||
|
yield from asyncio.sleep(delete_after, loop=state.loop)
|
||||||
|
try:
|
||||||
|
yield from ret.delete()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
discord.compat.create_task(delete(), loop=state.loop)
|
||||||
|
return ret
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def send_typing(self):
|
def send_typing(self):
|
||||||
|
@ -53,7 +53,7 @@ log = logging.getLogger(__name__)
|
|||||||
ReadyState = namedtuple('ReadyState', ('launch', 'guilds'))
|
ReadyState = namedtuple('ReadyState', ('launch', 'guilds'))
|
||||||
|
|
||||||
class StateContext:
|
class StateContext:
|
||||||
__slots__ = ('store_user', 'http', 'self_id', 'store_emoji', 'reaction_emoji')
|
__slots__ = ('store_user', 'http', 'self_id', 'store_emoji', 'reaction_emoji', 'loop')
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
for attr, value in kwargs.items():
|
for attr, value in kwargs.items():
|
||||||
@ -71,7 +71,7 @@ class ConnectionState:
|
|||||||
self.ctx = StateContext(store_user=self.store_user,
|
self.ctx = StateContext(store_user=self.store_user,
|
||||||
store_emoji=self.store_emoji,
|
store_emoji=self.store_emoji,
|
||||||
reaction_emoji=self._get_reaction_emoji,
|
reaction_emoji=self._get_reaction_emoji,
|
||||||
http=http, self_id=None)
|
http=http, self_id=None, loop=loop)
|
||||||
self.clear()
|
self.clear()
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user