From 40105f37ed07c6729d68a3f655ec88306adfe456 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Sat, 29 Sep 2018 11:13:11 -0500 Subject: [PATCH] Added support for deleting dm's with the new Twitter API methods --- doc/changelog.md | 1 + src/controller/buffers/twitterBuffers.py | 1 - src/twython/api.py | 8 ++++++-- src/twython/endpoints.py | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/changelog.md b/doc/changelog.md index 41a0682f..950b403d 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -2,6 +2,7 @@ ## changes in this version +* Added support for deleting direct messages by using the new Twitter API methods. * When quoting a retweet, the quote will be made to the original tweet instead of the retweet. * If the sent direct messages buffer is hidden, TWBlue should keep loading everything as expected. ([#246](https://github.com/manuelcortez/TWBlue/issues/246)) * There is a new soundpack, called FreakyBlue (Thanks to [Andre Louis](https://twitter.com/FreakyFwoof)) as a new option in TWBlue. This pack can be the default in the next stable, so users can take a look and share their opinion in snapshot versions. ([#247](https://github.com/manuelcortez/TWBlue/issues/247)) diff --git a/src/controller/buffers/twitterBuffers.py b/src/controller/buffers/twitterBuffers.py index 225de733..1ed2a34a 100644 --- a/src/controller/buffers/twitterBuffers.py +++ b/src/controller/buffers/twitterBuffers.py @@ -557,7 +557,6 @@ class baseBufferController(baseBuffers.buffer): self.session.twitter.destroy_status(id=self.get_right_tweet()["id"]) self.session.db[self.name].pop(index) self.buffer.list.remove_item(index) -# if index > 0: except TwythonError: self.session.sound.play("error.ogg") diff --git a/src/twython/api.py b/src/twython/api.py index 10c4963c..96d1ae72 100644 --- a/src/twython/api.py +++ b/src/twython/api.py @@ -153,7 +153,7 @@ class Twython(EndpointsMixin, object): if k in ('timeout', 'allow_redirects', 'stream', 'verify'): requests_args[k] = v - if method == 'get': + if method == 'get' or method == 'delete': requests_args['params'] = params else: # Check for json_encoded so we will sent params as "data" or "json" @@ -242,7 +242,7 @@ class Twython(EndpointsMixin, object): (e.g. search/tweets) :type endpoint: string :param method: (optional) Method of accessing data, either - GET or POST. (default GET) + GET, POST or DELETE. (default GET) :type method: string :param params: (optional) Dict of parameters (if any) accepted the by Twitter API endpoint you are trying to @@ -281,6 +281,10 @@ class Twython(EndpointsMixin, object): """Shortcut for POST requests via :class:`request`""" return self.request(endpoint, 'POST', params=params, version=version, json_encoded=json_encoded) + def delete(self, endpoint, params=None, version='1.1', json_encoded=False): + """Shortcut for delete requests via :class:`request`""" + return self.request(endpoint, 'DELETE', params=params, version=version, json_encoded=json_encoded) + def get_lastfunction_header(self, header, default_return_value=None): """Returns a specific header from the last API call This will return None if the header is not present diff --git a/src/twython/endpoints.py b/src/twython/endpoints.py index f7e0a5a6..9adf800f 100644 --- a/src/twython/endpoints.py +++ b/src/twython/endpoints.py @@ -329,10 +329,10 @@ class EndpointsMixin(object): """Destroys the direct message specified in the required ``id`` parameter Docs: - https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/delete-message + https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/delete-message-event """ - return self.post('direct_messages/destroy', params=params) + return self.delete('direct_messages/events/destroy', params=params) def send_direct_message(self, **params): """Sends a new direct message to the specified user from the