Skip to content

Commit

Permalink
Adding feature to remove reactions (#101)
Browse files Browse the repository at this point in the history
* Adding feature to remove reactions

Per enhancment request #100 this adds a method to the Message class
called remove_reaction() which takes in the emoji_name to be removed as
a parameter.

* Adding '/users/' to reaction delete url
  • Loading branch information
attzonko authored Mar 5, 2019
1 parent 48e86ef commit f9b825f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mmpy_bot/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ def react(self, emoji_name):
self._client.react_msg(
self._body['data']['post']['id'], emoji_name)

def remove_reaction(self, emoji_name):
self._client.remove_reaction(
self._body['data']['post']['id'], emoji_name)

def docs_reply(self, docs_format=' • `{0}` {1}'):
reply = [docs_format.format(v.__name__, v.__doc__ or "")
for p, v in iteritems(self._plugins.commands['respond_to'])]
Expand Down
16 changes: 16 additions & 0 deletions mmpy_bot/mattermost.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def create_reaction(self, user_id, post_id, emoji_name):
'emoji_name': emoji_name,
})

def delete_reaction(self, user_id, post_id, emoji_name):
return self.delete(
'/users/{0}/posts/{1}/reactions/{2}'.format(
user_id, post_id, emoji_name))

def create_post(self, user_id, channel_id, message,
files=None, pid="", props=None):
return self.post(
Expand Down Expand Up @@ -167,6 +172,13 @@ def post(self, request, data):
verify=self.ssl_verify
).text)

def delete(self, request):
return json.loads(requests.delete(
self.url + request,
headers=self._get_headers(),
verify=self.ssl_verify
).text)

def put(self, request, data):
return json.loads(requests.put(
self.url + request,
Expand Down Expand Up @@ -229,6 +241,10 @@ def react_msg(self, post_id, emoji_name):
return self.api.create_reaction(self.user["id"],
post_id, emoji_name)

def remove_reaction(self, post_id, emoji_name):
return self.api.delete_reaction(self.user["id"],
post_id, emoji_name)

def channel_msg(self, channel, message, files=None, pid="", props=None):
c_id = self.channels.get(channel, {}).get("id") or channel
return self.api.create_post(self.user["id"], c_id,
Expand Down

0 comments on commit f9b825f

Please sign in to comment.