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
10 # pylint: disable=wrong-import-position
11 from AbstractCommand import AbstractCommand
12 class CommandSendInfCoinTo(AbstractCommand):
13 TRIGGER = "send-inf-coin-to"
14 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
15 "auto_complete_hint": "<username> <amount>",
17 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Helper to send Inf-Coins to somebody."
20 def __init__(self, team_id, datadir, infcoin_req_url):
21 super().__init__(team_id)
23 self.datadir = datadir
24 self.infcoin_req_url = infcoin_req_url
27 def on_POST(self, request, data):
28 msg_text = data['text'].strip().split(" ")
30 if len(msg_text) != 2:
31 request.cmd_respond_text_temp("``/send-inf-coin-to`` failed: The arguments are: <username> <amount>. :(")
34 user = self.bot.api.get_user_by_username(msg_text[0].replace("@","").strip(), exc=False)
35 infcoin_wallet = json.loads(self._wallet_load(self.datadir+"wallet-"+user["id"], ".json", '{"wallet":""}'))
36 if infcoin_wallet["wallet"] != "":
37 msg = "### [Complete the transaction with neoline via webbrowser]("+self.infcoin_req_url+"?addr="+infcoin_wallet["wallet"]+"&amount="+msg_text[1]+")"
39 msg = "### ``/send-inf-coin-to`` failed: @"+msg_text[0].replace("@","").strip()+" hasnt told @bot their wallet address yet (by using ``/inf-coin``)"
41 request.cmd_respond_text_temp(msg)
45 def _wallet_load(self, path, filename, default=""):
48 if os.path.isfile(path):
49 with open(path, "r") as f: