2 # Copyright (c) 2016-2020 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 # published under MIT-License
8 from AbstractCommand import *
9 class TACommandWipeChannel(AbstractCommand):
10 TRIGGER = "ta-wipe-channel"
11 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
12 "auto_complete_hint": "'--really-all'|<username>",
14 CONFIG["auto_complete_desc"] = CONFIG["description"] = "Delete all not-pinned posts in channel (optionally: only by <username>). There is no undo. [TEAM_ADMIN]"
17 def on_POST(self, request, data):
18 self._require_team_admin(data) # will throw an exception if not. (Dont try-except: Its handled up the stack.)
20 u = self.bot.api.get_user_by_username(data["text"].strip())
21 if data["text"].strip() != "--really-all" and len(u) == 0:
22 request.cmd_respond_text_temp("### parameter must be '--really-all' or a valid username. :(")
25 # needs indirection. see iterators.
26 posts = [p for p in self.bot.api.get_posts_for_channel(data["channel_id"])]
31 if (data["text"].strip() == "--really-all") or (data["text"].strip() != "" and u[0]["id"] == p["user_id"]) or (data["text"].strip() == ""):
32 self.bot.api.delete_post(p["id"])
34 request.cmd_respond_text_temp("### ``Done.`` :)")
35 self.bot.debug_chan("``/ta-wipe-channel "+data["text"].strip()+"`` used by ``@"+data["user_name"]+"`` in ``"+data["team_domain"]+"::"+data["channel_name"]+"``")