]> git.somenet.org - pub/jan/mattermost-bot.git/blob - modules/WSModRemovePostTextEnforcer.py
config.py.example
[pub/jan/mattermost-bot.git] / modules / WSModRemovePostTextEnforcer.py
1 # Mattermost Bot module.
2 #  Copyright (c) 2016-2022 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 #  published under MIT-License
4
5 import json
6
7 # pylint: disable=wrong-import-position
8 from AbstractWSHandler import AbstractWSHandler
9 class WSModRemovePostTextEnforcer(AbstractWSHandler):
10     NAME = "mod-remove-post-text-enforcer"
11
12
13     def on_WS_EVENT(self, data):
14         post = json.loads(data["data"]["post"])
15         if "has_reactions" not in post:
16             post["has_reactions"] = False
17
18         if "somebot_removed_post_text" in post["props"] and post["message"] != "":
19             self.bot.api.update_post(post["id"], message=None, is_pinned=post["is_pinned"], has_reactions=post["has_reactions"], props=post["props"])
20             self.bot.debug_chan("``WSModRemovePostTextEnforcer: Post edit-attempt reverted. Post-id: ``**``"+post["id"]+"``**`` Text was:``\n\n----\n\n"+post["message"])
21             return True