From 0543eb81eb4b8bed7d1764799a45f27f18bdbb82 Mon Sep 17 00:00:00 2001 From: Someone Date: Wed, 8 Dec 2021 19:38:38 +0100 Subject: [PATCH] [somebot] WS:ModRemovePostTextEnforcer --- modules/WSModRemovePostTextEnforcer.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 modules/WSModRemovePostTextEnforcer.py diff --git a/modules/WSModRemovePostTextEnforcer.py b/modules/WSModRemovePostTextEnforcer.py new file mode 100644 index 0000000..a3ba617 --- /dev/null +++ b/modules/WSModRemovePostTextEnforcer.py @@ -0,0 +1,25 @@ +# Mattermost Bot module. +# Copyright (c) 2016-2021 by Someone (aka. Jan Vales ) +# published under MIT-License + +import json +import re + +from AbstractWSHandler import * +class WSModRemovePostTextEnforcer(AbstractWSHandler): + NAME = "mod-remove-post-text-enforcer" + + + def on_WS_EVENT(self, data): + post = json.loads(data["data"]["post"]) + if "has_reactions" not in post: + post["has_reactions"] = False + #post = self.bot.api.get_post(post["id"]) + + if "somebot_removed_post_text" in post["props"] and post["message"] != "": + self.bot.api.update_post(post["id"], message=None, is_pinned=post["is_pinned"], has_reactions=post["has_reactions"], props=post["props"]) + self.bot.debug_chan("``WSModRemovePostTextEnforcer: Post edit-attempt reverted. Post-id: ``**``"+post["id"]+"``**`` Text was:``\n\n----\n\n"+post["message"]) + else: + import pprint + pprint.pprint(data) + self.bot.command_stats_inc("ws::"+evtype+"::"+self.NAME, amount=-1) -- 2.43.0