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