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
5 from inspect import cleandoc
11 from AbstractCommand import *
12 class DialogManagedInfCoin(AbstractCommand):
14 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
15 # "auto_complete_hint": "Manage your Inf-Coins",
17 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Will make @bot send you a Inf-Coin managing post."
20 def __init__(self, team_id, datadir, infcoin_req_url, infcoin_req_user, infcoin_req_pw, infcoin_req_amount=100):
21 super().__init__(team_id)
23 self.datadir = datadir
24 self.infcoin_req_url = infcoin_req_url
25 self.infcoin_req_user = infcoin_req_user
26 self.infcoin_req_pw = infcoin_req_pw
27 self.infcoin_req_amount = infcoin_req_amount
30 def on_POST(self, request, data):
31 # self._require_bot_admin(data) # will throw an exception if not. (Dont try-except: Its handled up the stack.)
35 ## ``(FS)Inf``:coin: ``Management`` :rocket:
36 **Inf-Coins, previously FSInf-Coins are tokens of gratitude and appreciation without any inherent value.**
37 For more details about Inf-Coin, [visit its professional website!](https://infcoin.jvales.net)
39 You will be rewarded 1 Inf-Coin for setting your wallet address for the first time. :rocket:
41 To send Inf-Coins to somebody, use the command ``/send-inf-coin @<ACCOUNTNAME>``
44 + Get yourself a NEO wallet which supports NEO2-Testnet. At least these should do:
45 + https://testnet.neotracker.io/wallet (Web)
46 + https://neoline.io/en/ (Extension)
48 + Once setup, start tracking the [$Inf (f26c60f640091e2fa8cd15b30bb5f51cd4d2048b) asset on NEO2-testnet](https://testnet.neotube.io/nep5/f26c60f640091e2fa8cd15b30bb5f51cd4d2048b/page/1) in your wallet.
49 + As soon as you get Inf-Coins your wallet should display them to you and you should be able to transfer them.
51 :information_source: *Coin minting cannot be done automatically is a secure manner so it might take a while for you to receive your Inf-Coins.*
52 :warning:**If you need to update your addess, because you gave a wrong one, contact @someone so your coins dont get send on the old address. Once sent, there is no undo.**
56 "text": "Self-Management",
58 {"name": ":pencil: Set your Inf-Coin wallet address", "integration": {"url": self.URL+"/interactive"}},
59 #{"name": ":rocket: Claim newly received Inf-Coins", "integration": {"url": self.URL+"/interactive"}}
63 #"actions": [{"name": ":package: Send unclaimed coins to somebody", "integration": {"url": self.URL+"/interactive"}}]
66 c = self.bot.api.create_dm_channel_with(data['user_id'])
67 p = self.bot.api.create_post(c['id'], msg, props={"from_webhook":"true", "attachments":att})
68 request.cmd_respond_text_temp("@bot has written you a direct message.\n:arrow_right: https://mattermost.fsinf.at/"+data["team_domain"]+"/pl/"+p["id"])
71 def on_POST_interactive(self, request, data):
73 #print("on_POST_interactive")
76 callback_id = "wallet-"+data["user_id"]
77 infcoin_wallet = json.loads(self._wallet_load(self.datadir+callback_id, ".json", '{"wallet":""}'))
80 "callback_id": callback_id,
81 "title": "Set your Inf-Coin/NEO2-Testnet wallet address",
82 "submit_label":"Submit",
84 "display_name": "Your Inf-Coin/NEO2-Testnet wallet address",
85 "placeholder": "Paste here.",
86 "name": "infcoin_wallet",
88 "help_text": "The wallet address is alphanumeric and 34 characters long.",
90 "default": infcoin_wallet['wallet']
94 self.bot.api.open_dialog(data["trigger_id"], self.URL+"/dialog", dialog)
95 request.respond(200, {})
99 def on_POST_dialog(self, request, data):
101 #print("on_POST_dialog")
105 if data["submission"]["infcoin_wallet"] == "":
106 data["submission"]["infcoin_wallet"] = None
107 if data["submission"]["infcoin_wallet"] is not None and not (data["submission"]["infcoin_wallet"].isascii() and data["submission"]["infcoin_wallet"].isalnum() and len(data["submission"]["infcoin_wallet"]) == 34):
108 request.respond(200, {"errors": {"infcoin_wallet": "This doesnt seem like a valid address."}})
110 c = self.bot.api.create_dm_channel_with(data['user_id'])
111 existed = self._wallet_store(self.datadir+data["callback_id"], ".json", json.dumps({"wallet":data["submission"]["infcoin_wallet"]}))
112 if not existed and data["submission"]["infcoin_wallet"] is not None:
113 self.award_infcoins(data["user_id"], self.infcoin_req_amount, "wallet-set")
114 p = self.bot.api.create_post(c['id'], "``AUTODELETE-DAY`` Wallet address set. Inf-Coins requested.", props={"from_webhook":"true"})
116 p = self.bot.api.create_post(c['id'], "``AUTODELETE-DAY`` Did nothing.", props={"from_webhook":"true"})
118 p = self.bot.api.create_post(c['id'], "``AUTODELETE-DAY`` Wallet address updated. No Inf-Coins requested.", props={"from_webhook":"true"})
122 def award_infcoins(self, user_id, amount, reason_part):
123 infcoin_wallet = json.loads(self._wallet_load(self.datadir+"wallet-"+user_id, ".json", '{"wallet":""}'))
124 if infcoin_wallet["wallet"] != "":
125 r = requests.get(self.infcoin_req_url, {"auth_name":self.infcoin_req_user, "auth_secret":self.infcoin_req_pw, "addr":infcoin_wallet["wallet"], "amount":amount, "reason_uniq":"mm-"+reason_part+", uid="+user_id})
131 def _wallet_load(self, path, filename, default=""):
134 if os.path.isfile(path):
135 with open(path, "r") as f:
140 def _wallet_store(self, path, filename, data):
142 data = str(data).strip()
143 existed = os.path.isfile(path)
144 if not (not existed and data == json.dumps({"wallet":None})):
145 with open(path, "w") as f: