]> git.somenet.org - pub/jan/mattermost-bot.git/blob - modules/WSModRemovePostTextEnforcer.py
core/MMBot.py
[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 import re
7
8 from AbstractWSHandler import *
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         #post = self.bot.api.get_post(post["id"])
18
19         if "somebot_removed_post_text" in post["props"] and post["message"] != "":
20             self.bot.api.update_post(post["id"], message=None, is_pinned=post["is_pinned"], has_reactions=post["has_reactions"], props=post["props"])
21             self.bot.debug_chan("``WSModRemovePostTextEnforcer: Post edit-attempt reverted. Post-id: ``**``"+post["id"]+"``**`` Text was:``\n\n----\n\n"+post["message"])
22         else:
23             import pprint
24             pprint.pprint(data)
25             self.bot.command_stats_inc("ws::"+evtype+"::"+self.NAME, amount=-1)