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 # previous implementation written 2019 by Ju <daju@fsinf.at> was completely replaced by a modified previous CommandToss implementation by Someone <someone@somenet.org> in 2020.
9 # pylint: disable=wrong-import-position
10 from AbstractCommand import AbstractCommand
11 class CommandRoom(AbstractCommand):
13 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
14 "auto_complete_hint": "['--chan'] <room name>",
16 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Use TOSS to get room information."
19 def __init__(self, team_id, toss_url_api_search):
20 super().__init__(team_id)
21 self.toss_url_api_search = toss_url_api_search
24 def on_POST(self, request, data):
28 if search.startswith("--chan "):
29 search = search.replace("--chan ", "", 1)
32 if not search or search == "--chan":
33 request.respond_cmd_err("``/"+self.TRIGGER+"`` you did not provide a room name. :(")
36 r = requests.get(self.toss_url_api_search+"?q="+requests.utils.quote(search))
37 if r.status_code != 200:
38 request.respond_cmd_err("``/"+self.TRIGGER+"`` TOSS-query failed. :(\n"+str(repr(r))+"\n``/"+self.TRIGGER+" "+data["text"]+"``")
41 msg = "#### ** [:toss: ``Results``](https://toss.fsinf.at/?q="+requests.utils.quote(search)+") ``(max 5)``**"
43 for entry in r.json():
44 if entry["type"] == "room":
49 msg += "\n#### "+entry["name"]+" ("+entry["code"]+")\n"
50 if "address" in entry:
51 msg += ":world_map:[``"+entry["address"]+"``](https://www.google.com/maps/search/"+requests.utils.quote(entry["address"].split(";")[0])+")"
52 if "description" in entry:
53 msg += "\n"+entry["description"]
57 request.respond_cmd_err("#### **``No`` :toss: ``Results``** :(\n``/"+self.TRIGGER+" "+data["text"]+"``")
58 elif not send_to_chan:
59 request.respond_cmd_temp(msg+"\n``/"+self.TRIGGER+" "+data["text"]+"``")
61 request.respond_cmd_chan(msg+"\n``/"+self.TRIGGER+" "+data["text"]+"``")