Browse Source

Add support for message acking.

pull/476/merge
Rapptz 8 years ago
parent
commit
9a1215e13b
  1. 22
      discord/guild.py
  2. 11
      discord/http.py
  3. 22
      discord/message.py

22
discord/guild.py

@ -36,7 +36,7 @@ from .emoji import Emoji
from .game import Game from .game import Game
from .permissions import PermissionOverwrite from .permissions import PermissionOverwrite
from .colour import Colour from .colour import Colour
from .errors import InvalidArgument from .errors import InvalidArgument, ClientException
from .channel import * from .channel import *
from .enums import GuildRegion, Status, ChannelType, try_enum, VerificationLevel from .enums import GuildRegion, Status, ChannelType, try_enum, VerificationLevel
from .mixins import Hashable from .mixins import Hashable
@ -979,3 +979,23 @@ class Guild(Hashable):
Unbanning failed. Unbanning failed.
""" """
yield from self._state.http.unban(user.id, self.id) yield from self._state.http.unban(user.id, self.id)
def ack(self):
"""|coro|
Marks every message in this guild as read.
The user must not be a bot user.
Raises
-------
HTTPException
Acking failed.
ClientException
You must not be a bot user.
"""
state = self._state
if state.is_bot:
raise ClientException('Must not be a bot account to ack messages.')
return state.http.ack_guild(self.id)

11
discord/http.py

@ -227,6 +227,7 @@ class HTTPClient:
def _token(self, token, *, bot=True): def _token(self, token, *, bot=True):
self.token = token self.token = token
self.bot_token = bot self.bot_token = bot
self._ack_token = None
# login management # login management
@ -321,6 +322,16 @@ class HTTPClient:
return self.request(r, data=form) return self.request(r, data=form)
@asyncio.coroutine
def ack_message(self, channel_id, message_id):
r = Route('POST', '/channels/{channel_id}/messages/{message_id}/ack', channel_id=channel_id,
message_id=message_id)
data = yield from self.request(r, json={'token': self._ack_token})
self._ack_token = data['token']
def ack_guild(self, guild_id):
return self.request(Route('POST', '/guilds/{guild_id}/ack', guild_id=guild_id))
def delete_message(self, channel_id, message_id): def delete_message(self, channel_id, message_id):
r = Route('DELETE', '/channels/{channel_id}/messages/{message_id}', channel_id=channel_id, r = Route('DELETE', '/channels/{channel_id}/messages/{message_id}', channel_id=channel_id,
message_id=message_id) message_id=message_id)

22
discord/message.py

@ -36,7 +36,7 @@ from .emoji import Emoji
from .object import Object from .object import Object
from .calls import CallMessage from .calls import CallMessage
from .enums import MessageType, try_enum from .enums import MessageType, try_enum
from .errors import InvalidArgument from .errors import InvalidArgument, ClientException
from .embeds import Embed from .embeds import Embed
class Message: class Message:
@ -576,3 +576,23 @@ class Message:
You do not have the proper permissions to remove all the reactions. You do not have the proper permissions to remove all the reactions.
""" """
yield from self._state.http.clear_reactions(self.id, self.channel.id) yield from self._state.http.clear_reactions(self.id, self.channel.id)
def ack(self):
"""|coro|
Marks this message as read.
The user must not be a bot user.
Raises
-------
HTTPException
Acking failed.
ClientException
You must not be a bot user.
"""
state = self._state
if state.is_bot:
raise ClientException('Must not be a bot account to ack messages.')
return state.http.ack_message(self.channel.id, self.id)

Loading…
Cancel
Save