From 9a1215e13bf3eb5e2d8dca797dc563a1f722c02e Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 27 Feb 2017 23:03:46 -0500 Subject: [PATCH] Add support for message acking. --- discord/guild.py | 22 +++++++++++++++++++++- discord/http.py | 11 +++++++++++ discord/message.py | 22 +++++++++++++++++++++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index 878ceb031..760632bce 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -36,7 +36,7 @@ from .emoji import Emoji from .game import Game from .permissions import PermissionOverwrite from .colour import Colour -from .errors import InvalidArgument +from .errors import InvalidArgument, ClientException from .channel import * from .enums import GuildRegion, Status, ChannelType, try_enum, VerificationLevel from .mixins import Hashable @@ -979,3 +979,23 @@ class Guild(Hashable): Unbanning failed. """ 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) diff --git a/discord/http.py b/discord/http.py index baa9a7490..29f4fdfc2 100644 --- a/discord/http.py +++ b/discord/http.py @@ -227,6 +227,7 @@ class HTTPClient: def _token(self, token, *, bot=True): self.token = token self.bot_token = bot + self._ack_token = None # login management @@ -321,6 +322,16 @@ class HTTPClient: 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): r = Route('DELETE', '/channels/{channel_id}/messages/{message_id}', channel_id=channel_id, message_id=message_id) diff --git a/discord/message.py b/discord/message.py index 7c809d9f6..cec7647eb 100644 --- a/discord/message.py +++ b/discord/message.py @@ -36,7 +36,7 @@ from .emoji import Emoji from .object import Object from .calls import CallMessage from .enums import MessageType, try_enum -from .errors import InvalidArgument +from .errors import InvalidArgument, ClientException from .embeds import Embed class Message: @@ -576,3 +576,23 @@ class Message: You do not have the proper permissions to remove all the reactions. """ 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)