Annotate

mod_invites_api/mod_invites_api.lua @ 5636:7e5701fbae88

mod_invites_api: add `module:depends("http");` to use `module:http_url()` in `prosodyctl`.
author Trần H. Trung <xmpp:trần.h.trung@trung.fun>
date Mon, 31 Jul 2023 11:52:00 +0700
parent 5629:160868fdddd6
child 5637:38783b8acbc9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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);
5636
7e5701fbae88 mod_invites_api: add `module:depends("http");` to use `module:http_url()` in `prosodyctl`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5629
diff changeset
309 module:depends("http");
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
310 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
311 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
312 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
313 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
314
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
315 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
316 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
317 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
318 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
319 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
320 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
321 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
322 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
323 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
324 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
325 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
326 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
327 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
328 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
329 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
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 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
332 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
333 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
334 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
335 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
336 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
337 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
338 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
339 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
340 });
f7410850941f mod_invites_api: Change and 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 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
342 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
343 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
344 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
345 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
346 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
347 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
348 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
349 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
350 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
351 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
352 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
353 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
354 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
355 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
356 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
357 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
358 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
359 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
360 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
361 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
362 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
363 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
364 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
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 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
367 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
368 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
369 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
370 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
371 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
372 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
373 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
374 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
375 });
f7410850941f mod_invites_api: Change and 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 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
377 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
378 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
379 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
380 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
381 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
382 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
383 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
384 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
385 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
386 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
387 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
388 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
389 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
390 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
391 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
392 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
393 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
394 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
395 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
396 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
397 });
f7410850941f mod_invites_api: Change and 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 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
399 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
400 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
401 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
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 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
404 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
405 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
406 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
407 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
408 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
409 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
410 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
411 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
412 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
413 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
414 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
415 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
416 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
417 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
418 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
419 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
420 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
421 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
422 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
423 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
424 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
425 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
426 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
427 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
428 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
429 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
430 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
431 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
432 });
f7410850941f mod_invites_api: Change and 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 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
434 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
435 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
436 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
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 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
439 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
440 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
441 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
442 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
443 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
444 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
445 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
446 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
447 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
448 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
449 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
450 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
451 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
452 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
453 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
454 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
455 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
456 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
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 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
459 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
460 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
461 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
462 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
463 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
464 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
465 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
466 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
467 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
468 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
469 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
470 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
471 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
472 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
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 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
475 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
476 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
477 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
478 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
479 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
480 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
481 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
482 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
483 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
484 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
485 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
486 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
487 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
488 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
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 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
491 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
492 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
493 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
494 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
495 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
496 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
497 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
498 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
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 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
501 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
502 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
503 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
504 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
505 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
506 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
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 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
509 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
510 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
511 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
512 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
513 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
514 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
515 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
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 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
518 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
519 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
520 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
521 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
522 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
523 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
524 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
525 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
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 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
528 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
529 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
530 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
531 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
532 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
533 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
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 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
536 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
537 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
538 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
539 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
540 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
541 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
542 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
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 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
545 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
546 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
547 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
548 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
549 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
550 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
551 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
552 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
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 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
555 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
556 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
557 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
558 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
559 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
560 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
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 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
563 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
564 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
565 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
566 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
567 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
568 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
569 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
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 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
572 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
573 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
574 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
575 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
576 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
577 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
578 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
579 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
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 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
582 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
583 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
584 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
585 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
586 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
587 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
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 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
590 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
591 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
592 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
593 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
594 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
595 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
596 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
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 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
599 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
600 end
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
601 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
602 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
603 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
604 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
605 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
606 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
607 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
608 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
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 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
611 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
612 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
613 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
614 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
615 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
616 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
617 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
618 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
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 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
621 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
622 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
623 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
624 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
625 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
626 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
627 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
628 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
629 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
630 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
631 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
632 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
633 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
634 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
635 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
636 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
637 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
638 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
639 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
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 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
642 return;
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
643 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
644 else
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
645 print("Unknown command - "..command);
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
646 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
647 end