Software /
code /
prosody-modules
Annotate
mod_invites_api/mod_invites_api.lua @ 5633:758866b43aa4
mod_webpresence: use module:http_url() to get the correct url.
author | Trần H. Trung <xmpp:trần.h.trung@trung.fun> |
---|---|
date | Sat, 29 Jul 2023 18:08:58 +0700 |
parent | 5629:160868fdddd6 |
child | 5636:7e5701fbae88 |
rev | line source |
---|---|
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local http_formdecode = require "net.http".formdecode; |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
2 local jid = require "util.jid"; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
3 local usermanager = require "core.usermanager"; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
4 local datetime = require "util.datetime"; |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
6 -- Whether local users can invite other users to create an account on this server |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
7 local allow_user_invites = module:get_option_boolean("allow_user_invites", false); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
8 -- Who can see and use the contact invite command. It is strongly recommened to |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
9 -- keep this available to all local users. To allow/disallow invite-registration |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
10 -- on the server, use the option above instead. |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
11 local allow_contact_invites = module:get_option_boolean("allow_contact_invites", true); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
12 |
5629
160868fdddd6
mod_invites_api: remove unnecessary variables.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5628
diff
changeset
|
13 local api_key_store, api_key_store_kv, invites, date; |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 -- COMPAT: workaround to avoid executing inside prosodyctl |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 if prosody.shutdown then |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 module:depends("http"); |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 api_key_store = module:open_store("invite_api_keys", "map"); |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 invites = module:depends("invites"); |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
19 api_key_store_kv = module:open_store("invite_api_keys"); |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 local function get_api_user(request, params) |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 local combined_key; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 local auth_header = request.headers.authorization; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 if not auth_header then |
5143
1cae382e88a1
mod_invites_api: Fix traceback when no query params (thanks Menel)
Matthew Wild <mwild1@gmail.com>
parents:
5142
diff
changeset
|
28 params = params or http_formdecode(request.url.query or "="); |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 combined_key = params.key; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 else |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 local auth_type, value = auth_header:match("^(%S+)%s(%S+)$"); |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 if auth_type ~= "Bearer" then |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 return; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 combined_key = value; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 if not combined_key then |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 return; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 local key_id, key_token = combined_key:match("^([^/]+)/(.+)$"); |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 if not key_id then |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 return; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 local api_user = api_key_store:get(nil, key_id); |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 if not api_user or api_user.token ~= key_token then |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 return; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 -- TODO: key expiry, rate limiting, etc. |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 return api_user; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 function handle_request(event) |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 local query_params = http_formdecode(event.request.url.query); |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 local api_user = get_api_user(event.request, query_params); |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 if not api_user then |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 return 403; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 |
4216
35b678609b79
mod_invites_api: Allow restricting HTTP methods per key (once implemented)
Matthew Wild <mwild1@gmail.com>
parents:
4115
diff
changeset
|
67 if api_user.allowed_methods and not api_user.allowed_methods[event.request.method] then |
35b678609b79
mod_invites_api: Allow restricting HTTP methods per key (once implemented)
Matthew Wild <mwild1@gmail.com>
parents:
4115
diff
changeset
|
68 return 405; |
35b678609b79
mod_invites_api: Allow restricting HTTP methods per key (once implemented)
Matthew Wild <mwild1@gmail.com>
parents:
4115
diff
changeset
|
69 end |
35b678609b79
mod_invites_api: Allow restricting HTTP methods per key (once implemented)
Matthew Wild <mwild1@gmail.com>
parents:
4115
diff
changeset
|
70 |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
71 local invite; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
72 local username, domain = jid.prepped_split(api_user.jid); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
73 if username and usermanager.user_exists(username, domain) then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
74 local ttl = module:get_option_number("invite_expiry", 86400 * 7); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
75 invite = invites.create_contact(username, |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
76 allow_user_invites, -- allow_registration |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
77 { source = "api/token/"..api_user.id }, -- additional_data |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
78 ttl |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
79 ); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
80 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
81 invite = invites.create_account(nil, { source = "api/token/"..api_user.id }); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
82 end |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 if not invite then |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 return 500; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 event.response.headers.Location = invite.landing_page or invite.uri; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 if query_params.redirect then |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 return 303; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 return 201; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 if invites then |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 module:provides("http", { |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 route = { |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 ["GET"] = handle_request; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 }; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 }); |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
103 function get_value(callback) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
104 for key_id, key_info in pairs(api_key_store_kv:get(nil) or {}) do |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
105 date = datetime.datetime(key_info.created_at); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
106 callback(key_id, key_info); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
107 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
108 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
109 |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
110 local function get_url(id, token) |
5628
a74b07764d3f
mod_invites_api: use the nice `module:http_url()` to get the correct url.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5595
diff
changeset
|
111 local url_base = module:context(module.host):http_url(module.name, "/"..module.name); |
a74b07764d3f
mod_invites_api: use the nice `module:http_url()` to get the correct url.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5595
diff
changeset
|
112 return url_base.."?key="..id.."/"..token.."&redirect=true"; |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
113 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
114 |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 function module.command(arg) |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 if #arg < 2 then |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
117 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
118 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
119 print("Create:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
120 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
121 print("> prosodyctl mod_"..module.name.." create JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
122 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
123 print("Query:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
124 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
125 print("> prosodyctl mod_"..module.name.." get JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
126 print("> prosodyctl mod_"..module.name.." date JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
127 print("> prosodyctl mod_"..module.name.." id JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
128 print("> prosodyctl mod_"..module.name.." key JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
129 print("> prosodyctl mod_"..module.name.." url JID NAME"); |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 print(""); |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
131 print("Revoke:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
132 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
133 print("> prosodyctl mod_"..module.name.." delete JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
134 print("> prosodyctl mod_"..module.name.." delete-id HOST ID"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
135 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
136 print("Renew:"); |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 print(""); |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
138 print("> prosodyctl mod_"..module.name.." renew JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
139 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
140 print("Help:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
141 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
142 print("> prosodyctl mod_"..module.name.." help COMMAND"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
143 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
144 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
145 return; |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 local command = table.remove(arg, 1); |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
149 if command == "help" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
150 help_command = table.remove(arg, 1); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
151 if help_command == "create" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
152 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
153 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
154 print("Create a key:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
155 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
156 print("> prosodyctl mod_"..module.name.." create JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
157 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
158 print("------------------------------------------------------------------------"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
159 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
160 print("Usage:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
161 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
162 print(" `JID` can either be a user's account or a host."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
163 print(" When `JID` is a host, you need to supply a `NAME`."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
164 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
165 print(" Each user's account can only have 1 API key but hosts are unlimited."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
166 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
167 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
168 elseif help_command == "renew" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
169 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
170 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
171 print("Re-new a key:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
172 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
173 print("> prosodyctl mod_"..module.name.." create JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
174 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
175 print("------------------------------------------------------------------------"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
176 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
177 print("Usage:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
178 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
179 print(" `JID` can either be a user's account or a host."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
180 print(" When `JID` is a host, you need to supply a `NAME`."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
181 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
182 print(" The old `ID` will be kept and a new token will be generated for the API"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
183 print(" key you specified."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
184 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
185 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
186 elseif help_command == "get" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
187 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
188 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
189 print("Get info of a key:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
190 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
191 print("> prosodyctl mod_"..module.name.." get JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
192 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
193 print("------------------------------------------------------------------------"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
194 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
195 print("Usage:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
196 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
197 print(" When `JID` is a domain, it will list all the keys under that host."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
198 print(" When `JID` is a user's account, it fetches the key for that user."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
199 print(" If you supply both a host and a `NAME`, it fetches the key with `NAME`"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
200 print(" under that host.") |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
201 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
202 print(" Output for a host is: DATE, ID, JID, NAME."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
203 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
204 print(" Output for a user's account is: DATE, ID, URL."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
205 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
206 print(" Output for a host with a valid `NAME` is: DATE, ID, URL."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
207 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
208 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
209 elseif help_command == "date" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
210 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
211 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
212 print("Get the time stamp of a key:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
213 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
214 print("> prosodyctl mod_"..module.name.." date JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
215 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
216 print("------------------------------------------------------------------------"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
217 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
218 print("Usage:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
219 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
220 print(" Same as the `get` command but print only the birthday of the key."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
221 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
222 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
223 elseif help_command == "id" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
224 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
225 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
226 print("Print the ID of a key:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
227 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
228 print("> prosodyctl mod_"..module.name.." id JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
229 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
230 print("------------------------------------------------------------------------"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
231 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
232 print("Usage:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
233 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
234 print(" Same as the `get` command but print only the ID of the key."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
235 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
236 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
237 elseif help_command == "key" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
238 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
239 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
240 print("Print the API key:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
241 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
242 print("> prosodyctl mod_"..module.name.." key JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
243 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
244 print("------------------------------------------------------------------------"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
245 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
246 print("Usage:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
247 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
248 print(" Same as the `get` command but print only the key."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
249 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
250 print(" The key has the format: ID/TOKEN"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
251 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
252 print(" The `renew` command will generate a new token and revoke the old one."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
253 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
254 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
255 elseif help_command == "url" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
256 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
257 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
258 print("Print the URL of a key:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
259 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
260 print("> prosodyctl mod_"..module.name.." url JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
261 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
262 print("------------------------------------------------------------------------"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
263 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
264 print("Usage:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
265 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
266 print(" Same as the `get` command but print only the URL of the key."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
267 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
268 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
269 elseif help_command == "delete" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
270 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
271 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
272 print("Delete a key by JID and NAME:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
273 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
274 print("> prosodyctl mod_"..module.name.." delete JID NAME"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
275 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
276 print("------------------------------------------------------------------------"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
277 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
278 print("Usage:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
279 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
280 print(" Same as `create` command but delete the key specified."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
281 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
282 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
283 elseif help_command == "delete-id" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
284 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
285 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
286 print("Delete API key by ID:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
287 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
288 print("> prosodyctl mod_"..module.name.." delete HOST ID"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
289 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
290 print("------------------------------------------------------------------------"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
291 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
292 print("Usage:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
293 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
294 print(" Input must be a valid host - cannot be a user's account."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
295 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
296 print(" To get the ID of a key, use the `id` command."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
297 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
298 print("========================================================================"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
299 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
300 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
301 end |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
302 |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
303 local username, domain = jid.prepped_split(table.remove(arg, 1)); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
304 if not prosody.hosts[domain] then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
305 print("Error: please supply a valid host."); |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
306 return 1; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
307 end |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
308 require "core.storagemanager".initialize_host(domain); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
309 module.host = domain; --luacheck: ignore 122/module |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
310 usermanager.initialize_host(module.host); |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
311 api_key_store = module:open_store("invite_api_keys", "map"); |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
312 api_key_store_kv = module:open_store("invite_api_keys"); |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
313 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
314 if command == "create" then |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
315 local util_id = require "util.id".short(); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
316 local util_token = require "util.id".long(); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
317 local found = false; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
318 local os_time = os.time(); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
319 if username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
320 if usermanager.user_exists(username, module.host) then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
321 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
322 if username.."@"..module.host == info.jid then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
323 date = datetime.datetime(info.created_at); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
324 print("Found:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
325 print(date, id, info.jid); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
326 util_id = id; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
327 util_token = info.token; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
328 found = true; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
329 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
330 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
331 if found == false then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
332 api_key_store:set(nil, util_id, { |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
333 id = util_id; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
334 token = util_token; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
335 name = nil; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
336 jid = username.."@"..domain; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
337 created_at = os_time; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
338 allowed_methods = { GET = true, POST = true }; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
339 }); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
340 date = datetime.datetime(os_time); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
341 print("Created:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
342 print(date, util_id.."/"..util_token, username.."@"..domain); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
343 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
344 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
345 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
346 print("Error: "..username.."@"..domain.." does not exists."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
347 return 1; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
348 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
349 elseif domain then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
350 local arg_name = table.remove(arg, 1); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
351 if not arg_name or arg_name == "" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
352 print("Error: key for host needs a `NAME`."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
353 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
354 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
355 found = false; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
356 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
357 if domain == info.jid and arg_name == info.name then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
358 date = datetime.datetime(info.created_at); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
359 print("Found:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
360 print(date, id, info.jid, info.name); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
361 util_id = id; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
362 util_token = info.token; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
363 found = true; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
364 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
365 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
366 if found == false then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
367 api_key_store:set(nil, util_id, { |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
368 id = util_id; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
369 token = util_token; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
370 name = arg_name; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
371 jid = domain; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
372 created_at = os_time; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
373 allowed_methods = { GET = true, POST = true }; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
374 }); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
375 date = datetime.datetime(os_time); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
376 print("Created:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
377 print(date, util_id.."/"..util_token, domain, arg_name); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
378 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
379 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
380 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
381 elseif command == "renew" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
382 local util_token = require "util.id".long(); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
383 local os_time = os.time(); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
384 if username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
385 local found; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
386 if usermanager.user_exists(username, module.host) then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
387 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
388 if username.."@"..module.host == info.jid then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
389 api_key_store:set(nil, id, { |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
390 id = id; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
391 token = util_token; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
392 name = arg[1]; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
393 jid = username.."@"..domain; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
394 created_at = os_time; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
395 allowed_methods = { GET = true, POST = true }; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
396 }); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
397 found = true; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
398 date = datetime.datetime(os_time); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
399 print("Re-newed:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
400 print(date, id.."/"..util_token, info.jid); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
401 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
402 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
403 if not found then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
404 print("Error: Could not find the key for "..username.."@"..domain); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
405 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
406 print("To make this API key, run:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
407 print("prosodyctl "..module.name.." create "..username.."@"..domain); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
408 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
409 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
410 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
411 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
412 print("Error: "..username.."@"..domain.." does not exists."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
413 return 1; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
414 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
415 elseif domain then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
416 local arg_name = table.remove(arg, 1); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
417 if not arg_name or arg_name == "" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
418 print("Error: key for host needs a `NAME`."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
419 return 1; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
420 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
421 found = false; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
422 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
423 if domain == info.jid and arg_name == info.name then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
424 api_key_store:set(nil, id, { |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
425 id = id; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
426 token = util_token; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
427 name = arg_name; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
428 jid = domain; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
429 created_at = os_time; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
430 allowed_methods = { GET = true, POST = true }; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
431 }); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
432 date = datetime.datetime(os_time); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
433 print("Re-newed:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
434 print(date, id.."/"..util_token, info.jid, info.name); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
435 found = true; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
436 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
437 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
438 if not found then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
439 date = datetime.datetime(os_time); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
440 print("Error: Could not find "..arg_name.." in "..domain); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
441 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
442 print("To make this API key, run:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
443 print("prosodyctl "..module.name.." create "..domain.." "..arg_name); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
444 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
445 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
446 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
447 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
448 elseif command == "get" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
449 local name = table.remove(arg, 1); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
450 local found = false; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
451 if name and not username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
452 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
453 if info.name == name then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
454 print(date, id, get_url(id, info.token)); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
455 found = true; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
456 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
457 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
458 if found == false then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
459 print("Error: could not find "..name.." in "..domain); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
460 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
461 print("You can create it with:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
462 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
463 print("> prosodyctl "..module.name.." create "..domain.." "..name); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
464 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
465 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
466 elseif username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
467 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
468 local j = jid.prepped_split(info.jid); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
469 if j == username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
470 print(date, id, get_url(id, info.token)); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
471 found = true; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
472 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
473 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
474 if found == false then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
475 print("Error: could not find the key for "..username.."@"..domain); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
476 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
477 print("You can create it with:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
478 print(""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
479 print("> prosodyctl "..module.name.." create "..username.."@"..domain); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
480 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
481 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
482 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
483 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
484 if info.jid == module.host then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
485 print(date, id, info.jid, info.name or "<unknown>"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
486 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
487 print(date, id, info.jid, info.name or ""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
488 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
489 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
490 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
491 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
492 elseif command == "date" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
493 local name = table.remove(arg, 1); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
494 if name and not username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
495 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
496 if info.name == name then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
497 print(date); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
498 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
499 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
500 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
501 elseif username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
502 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
503 local j = jid.prepped_split(info.jid); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
504 if j == username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
505 print(date); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
506 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
507 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
508 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
509 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
510 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
511 if info.jid == module.host then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
512 print(date, info.jid, info.name or "<unknown>"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
513 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
514 print(date, info.jid); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
515 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
516 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
517 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
518 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
519 elseif command == "id" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
520 local name = table.remove(arg, 1); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
521 if name and not username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
522 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
523 if info.name == name then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
524 print(id); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
525 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
526 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
527 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
528 elseif username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
529 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
530 local j = jid.prepped_split(info.jid); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
531 if j == username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
532 print(id); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
533 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
534 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
535 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
536 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
537 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
538 if info.jid == module.host then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
539 print(id, info.jid, info.name or "<unknown>"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
540 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
541 print(id, info.jid); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
542 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
543 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
544 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
545 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
546 elseif command == "key" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
547 local name = table.remove(arg, 1); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
548 if name and not username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
549 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
550 if info.name == name then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
551 print(id.."/"..info.token); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
552 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
553 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
554 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
555 elseif username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
556 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
557 local j = jid.prepped_split(info.jid); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
558 if j == username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
559 print(id.."/"..info.token); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
560 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
561 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
562 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
563 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
564 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
565 if info.jid == module.host then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
566 print(id.."/"..info.token, info.jid, info.name or "<unknown>"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
567 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
568 print(id.."/"..info.token, info.jid); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
569 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
570 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
571 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
572 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
573 elseif command == "url" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
574 local name = table.remove(arg, 1); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
575 if name and not username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
576 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
577 if info.name == name then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
578 print(get_url(id, info.token)); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
579 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
580 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
581 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
582 elseif username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
583 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
584 local j = jid.prepped_split(info.jid); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
585 if j == username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
586 print(get_url(id, info.token)); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
587 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
588 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
589 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
590 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
591 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
592 if info.jid == module.host then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
593 print(get_url(id, info.token), info.jid, info.name or "<unknown>"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
594 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
595 print(get_url(id, info.token), info.jid); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
596 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
597 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
598 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
599 end |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
600 elseif command == "delete" then |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
601 local name = table.remove(arg, 1); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
602 if name and not username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
603 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
604 if info.name == name then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
605 api_key_store:set(nil, id, nil); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
606 print("Deleted:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
607 print(date, id.."/"..info.token, info.jid, info.name or ""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
608 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
609 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
610 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
611 elseif username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
612 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
613 local j = jid.prepped_split(info.jid); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
614 if j == username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
615 api_key_store:set(nil, id, nil); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
616 print("Deleted:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
617 print(date, id.."/"..info.token, info.jid, info.name or ""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
618 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
619 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
620 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
621 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
622 print("Error: Needs a valid `JID`. Or a host and a `NAME`."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
623 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
624 elseif command == "delete-id" then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
625 if username then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
626 print("Error: Input must be a valid host - cannot be a user's account."); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
627 return 1; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
628 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
629 local arg_id = table.remove(arg, 1); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
630 if not api_key_store:get(nil, arg_id) then |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
631 print("Error: key not found"); |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
632 return 1; |
5595
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
633 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
634 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
635 if arg_id == id then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
636 api_key_store:set(nil, id, nil); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
637 print("Deleted:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
638 print(date, id, info.jid, info.name or ""); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
639 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
640 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
641 return; |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
642 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
643 else |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
644 print("Unknown command - "..command); |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
645 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
646 end |