1 # Mattermost Bot module.
2 # Copyright (c) 2016-2021 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 from AbstractCommand import AbstractCommand
10 class CommandRoom(AbstractCommand):
12 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
13 "auto_complete_hint": "['--chan'] <room name>",
15 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Use TOSS to get room information."
18 def __init__(self, team_id, toss_url_api_search):
19 super().__init__(team_id)
20 self.toss_url_api_search = toss_url_api_search
23 def on_POST(self, request, data):
27 if search.startswith("--chan "):
28 search = search.replace("--chan ", "", 1)
31 if not search or search == "--chan":
32 request.cmd_respond_text_temp("You did not provide a room name.\n``/"+self.TRIGGER+" "+data["text"]+"``")
35 r = requests.get(self.toss_url_api_search+"?q="+requests.utils.quote(search))
36 if r.status_code != 200:
37 request.cmd_respond_text_temp(":stop_sign: TOSS-query failed. :(\n"+str(repr(r))+"\n``/"+self.TRIGGER+" "+data["text"]+"``")
40 msg = "#### ** [:toss: ``Results``](https://toss.fsinf.at/?q="+requests.utils.quote(search)+") ``(max 5)``**"
42 for entry in r.json():
43 if entry["type"] == "room":
48 msg += "\n#### "+entry["name"]+" ("+entry["code"]+")\n"
50 msg += ":world_map:[``"+entry["address"]+"``](https://www.google.com/maps/search/"+requests.utils.quote(entry["address"].split(";")[0])+")"
51 if entry["description"]:
52 msg += "\n"+entry["description"]
56 request.cmd_respond_text_temp("#### **``No`` :toss: ``Results``** :(\n``/"+self.TRIGGER+" "+data["text"]+"``")
57 elif not send_to_chan:
58 request.cmd_respond_text_temp(msg+"\n``/"+self.TRIGGER+" "+data["text"]+"``")
60 request.cmd_respond_text_chan(msg+"\n``/"+self.TRIGGER+" "+data["text"]+"``")