Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding feature to remove reactions #101

Merged
merged 3 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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