2 # Copyright (c) 2016-2020 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 # published under MIT-License
8 REX_linesplit = re.compile(r"\xa0|\t|\s{4}")
11 from AbstractCommand import *
12 class CommandTissJoin(AbstractCommand):
14 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
15 "auto_complete_hint": "<as-is-copy/paste of one TISS-LVA-Cockpit table>",
17 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Parses input and tries to join every LVA-channel. There is no undo."
20 def on_POST(self, request, data):
22 lines = data["text"].splitlines()
24 lva_line = REX_linesplit.split(line)
28 lvaname = lva_line[1].strip().replace("&"," ").replace("-"," ").replace("|"," ").strip()
32 if lvaname.startswith("Titel Std") or lvaname.startswith("Summe "):
35 result += "\n+ ``"+lvaname+"``"
38 channel_results = self.bot.api.search_channel(self.TEAM_ID, lvaname[:60]) # max 60 char length
40 if len(channel_results) == 0:
41 result += "\n + :stop_sign: could not find suitable channel"
43 elif len(channel_results) == 1:
44 channel = channel_results[0]
45 result += "\n + :white_check_mark: found channel: ~"+channel["name"]+"\n + trying to join..."
47 self.bot.api.add_user_to_channel(channel["id"], data["user_id"])
50 result += "\n + :warning: multiple channels found. Join the correct channel(s) by clicking on their name. If they are not clickable, click on ``More...`` to download the full channel-list. Close the window once it opens."
51 for channel in channel_results:
52 result += "\n + ~"+channel["name"]+"\n"
56 request.cmd_respond_text_temp("### ``TISS-Join results``\nFailed to detect any courses. :(")
58 request.cmd_respond_text_temp("### ``TISS-Join results``"+result)