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
8 REX_linesplit = re.compile(r"\xa0|\t|\s{4}")
11 # pylint: disable=wrong-import-position
12 from AbstractCommand import AbstractCommand
13 class CommandTissJoin(AbstractCommand):
15 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
16 "auto_complete_hint": "<as-is-copy/paste of one TISS-LVA-Cockpit table>",
18 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = AbstractCommand.ICON_PRIVATE+"Parses input and tries to join every LVA-channel. There is no undo."
21 def on_POST(self, request, data):
23 lines = data["text"].splitlines()
25 lva_line = REX_linesplit.split(line)
29 lvaname = lva_line[0].strip().replace("&", " ").replace("-", " ").replace("|", " ").replace(",", " ").strip()
30 lvaname = re.sub(r"\d\d\d\.\d\d\d\s*\w\w\s*$", " ", lvaname).strip()
34 if lvaname.startswith("Titel Std") or lvaname.startswith("Summe "):
37 result += "\n+ ``"+lvaname+"``"
40 channel_results = self.bot.api.search_channel(self.TEAM_ID, lvaname[:60]) # max 60 char length
42 if not channel_results:
43 result += "\n + :stop_sign: could not find suitable channel"
45 elif len(channel_results) == 1:
46 channel = channel_results[0]
47 result += "\n + :white_check_mark: found channel: ~"+channel["name"]+"\n + trying to join..."
49 self.bot.api.add_user_to_channel(channel["id"], data["user_id"])
52 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."
53 for channel in channel_results:
54 result += "\n + [~"+channel["name"]+"](https://mattermost.fsinf.at/w-inf-tuwien/channels/"+channel["name"]+")\n"
58 request.respond_cmd_err("``/"+self.TRIGGER+"`` failed to detect any courses.")
60 request.respond_cmd_temp("## :white_check_mark: Success! :)\n#### Results..."+result)