]> git.somenet.org - pub/jan/mattermost-bot.git/blob - modules/CommandSendInfCoinTo.py
modules/CommandInskription.py
[pub/jan/mattermost-bot.git] / modules / CommandSendInfCoinTo.py
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
5 import json
6 import os
7 import requests
8
9
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>",
16              }
17     USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Helper to send Inf-Coins to somebody."
18
19
20     def __init__(self, team_id, datadir, infcoin_req_url):
21         super().__init__(team_id)
22
23         self.datadir = datadir
24         self.infcoin_req_url = infcoin_req_url
25
26
27     def on_POST(self, request, data):
28         msg_text = data['text'].strip().split(" ")
29
30         if len(msg_text) != 2:
31             request.cmd_respond_text_temp("``/send-inf-coin-to`` failed: The arguments are: <username> <amount>. :(")
32             return
33
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]+")"
38         else:
39             msg = "### ``/send-inf-coin-to`` failed: @"+msg_text[0].replace("@","").strip()+" hasnt told @bot their wallet address yet (by using ``/inf-coin``)"
40
41         request.cmd_respond_text_temp(msg)
42
43
44
45     def _wallet_load(self, path, filename, default=""):
46         path = path+filename
47         ret = default
48         if os.path.isfile(path):
49             with open(path, "r") as f:
50                 ret = f.read()
51         return ret