Software /
code /
prosody-modules
Annotate
mod_invites_api/mod_invites_api.lua @ 5856:75dee6127829 draft
Merge upstream
author | Trần H. Trung <xmpp:trần.h.trung@trung.fun> |
---|---|
date | Tue, 06 Feb 2024 18:32:01 +0700 |
parent | 5639:1664bd4c274b |
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(""); |
5637
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
136 print("Adjust:"); |
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"); |
5637
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
139 print("> prosodyctl mod_"..module.name.." rename JID NAME NEW_NAME"); |
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
|
140 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
|
141 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
|
142 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
|
143 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
|
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 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
|
146 return; |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 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
|
150 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
|
151 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
|
152 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
|
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(""); |
f7410850941f
mod_invites_api: Change and 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("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
|
156 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
|
157 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
|
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(""); |
f7410850941f
mod_invites_api: Change and 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("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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
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 print("========================================================================"); |
5637
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
169 elseif help_command == "rename" then |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
170 print("========================================================================"); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
171 print(""); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
172 print("Re-name a key:"); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
173 print(""); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
174 print("> prosodyctl mod_"..module.name.." rename JID NAME NEW_NAME"); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
175 print(""); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
176 print("------------------------------------------------------------------------"); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
177 print(""); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
178 print("Usage:"); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
179 print(""); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
180 print(" `JID` can only be a valid host."); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
181 print(""); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
182 print(" You need to supply a `NEW_NAME` to replace « `NAME` » the old one."); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
183 print(""); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
184 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
|
185 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
|
186 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
|
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("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
|
189 print(""); |
5637
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
190 print("> prosodyctl mod_"..module.name.." renew JID NAME"); |
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
|
191 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
|
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("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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
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("========================================================================"); |
f7410850941f
mod_invites_api: Change and 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 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
|
204 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
|
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("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
|
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("> 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
|
209 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
|
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("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
|
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(" 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
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 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
|
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 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
|
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(""); |
f7410850941f
mod_invites_api: Change and 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("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
|
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("> 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
|
232 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
|
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(""); |
f7410850941f
mod_invites_api: Change and 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("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
|
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 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
|
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 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
|
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(""); |
f7410850941f
mod_invites_api: Change and 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("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
|
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("> 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
|
246 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
|
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(""); |
f7410850941f
mod_invites_api: Change and 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("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
|
250 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
|
251 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
|
252 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
|
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 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
|
255 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
|
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("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
|
258 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
|
259 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
|
260 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
|
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("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
|
264 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
|
265 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
|
266 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
|
267 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
|
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 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
|
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 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
|
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(""); |
f7410850941f
mod_invites_api: Change and 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("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
|
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("> 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
|
278 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
|
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(""); |
f7410850941f
mod_invites_api: Change and 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("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
|
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 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
|
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 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
|
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(""); |
f7410850941f
mod_invites_api: Change and 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("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
|
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("> 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
|
292 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
|
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(""); |
f7410850941f
mod_invites_api: Change and 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("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
|
296 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
|
297 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
|
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 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 end |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
319 |
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
|
320 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
|
321 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
|
322 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
|
323 return 1; |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
332 local found = false; |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
333 local function error_found(username, name) |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
334 if name then |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
335 print("Error: Could not find "..name.." in "..domain); |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
336 print(""); |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
337 print("To make this API key, run:"); |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
338 print("> prosodyctl "..module.name.." create "..domain.." "..name); |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
339 return 1; |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
340 end |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
341 if username then |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
342 print("Error: Could not find "..username.."@"..domain); |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
343 print(""); |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
344 print("To make this API key, run:"); |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
345 print("> prosodyctl "..module.name.." create "..username.."@"..domain); |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
346 return 1; |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
347 end |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
348 end |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
349 |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
350 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
|
351 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
|
352 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
|
353 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
|
354 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
|
355 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
|
356 get_value(function (id, info) |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
357 if 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
|
358 date = datetime.datetime(info.created_at); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
359 print("Found:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
360 print(date, id, info.jid); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
361 util_id = id; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
362 util_token = info.token; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
363 found = true; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
364 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
365 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
366 if found == false then |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
367 api_key_store:set(nil, util_id, { |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
368 id = util_id; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
369 token = util_token; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
370 name = 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
|
371 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
|
372 created_at = os_time; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
373 allowed_methods = { GET = true, POST = true }; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
374 }); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
375 date = datetime.datetime(os_time); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
376 print("Created:"); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
377 print(date, util_id.."/"..util_token, 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
|
378 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
379 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
380 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
|
381 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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 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
|
392 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
|
393 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
|
394 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
|
395 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
|
396 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
|
397 found = true; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
398 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
|
399 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
|
400 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
|
401 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
|
402 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
|
403 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
|
404 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
|
405 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
|
406 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
|
407 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
|
408 }); |
f7410850941f
mod_invites_api: Change and 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 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
|
410 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
|
411 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
|
412 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
|
413 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
|
414 end |
5637
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
415 elseif command == "rename" then |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
416 local util_token = require "util.id".long(); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
417 local os_time = os.time(); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
418 if username then |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
419 if usermanager.user_exists(username, module.host) then |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
420 get_value(function (id, info) |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
421 if username.."@"..module.host == info.jid then |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
422 print("Found:"); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
423 print(date, id.."/"..util_token, info.jid); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
424 found = true; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
425 end |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
426 end); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
427 if not found then |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
428 error_found(username); |
5637
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
429 return 1; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
430 end |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
431 print("Error: not allow to rename user's account."); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
432 return 1; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
433 else |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
434 print("Error: "..username.."@"..domain.." doesn't exists!"); |
5637
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
435 return 1; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
436 end |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
437 elseif domain then |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
438 local arg_name_orig = table.remove(arg, 1); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
439 if not arg_name_orig or arg_name_orig == "" then |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
440 print("Error: key for host needs a `NAME`."); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
441 return 1; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
442 end |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
443 local arg_name_new = table.remove(arg, 1); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
444 if not arg_name_new or arg_name_new == "" then |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
445 print("Error: need a `NEW_NAME` to replace "..arg_name_orig); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
446 return 1; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
447 end |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
448 get_value(function (id, info) |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
449 if domain == info.jid and arg_name_orig == info.name then |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
450 api_key_store:set(nil, id, { |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
451 id = id; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
452 token = info.token; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
453 name = arg_name_new; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
454 jid = domain; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
455 created_at = os_time; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
456 allowed_methods = { GET = true, POST = true }; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
457 }); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
458 date = datetime.datetime(os_time); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
459 print("Re-named:"); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
460 print(date, id.."/"..info.token, info.jid, arg_name_new); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
461 found = true; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
462 end |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
463 end); |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
464 if not found then |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
465 error_found(nil, arg_name_orig); |
5637
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
466 return 1; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
467 end |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
468 return; |
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
469 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
|
470 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
|
471 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
|
472 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
|
473 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
|
474 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
|
475 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
|
476 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
|
477 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
|
478 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
|
479 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
|
480 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
|
481 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
|
482 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
|
483 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
|
484 }); |
f7410850941f
mod_invites_api: Change and 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 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
|
486 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
|
487 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
|
488 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
|
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 if not found then |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
492 error_found(username); |
5637
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
493 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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 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
|
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 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
|
501 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
|
502 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
|
503 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
|
504 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
|
505 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
|
506 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
|
507 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
|
508 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 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
|
514 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
|
515 }); |
f7410850941f
mod_invites_api: Change and 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 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
|
517 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
|
518 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
|
519 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
|
520 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
|
521 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
|
522 if not found then |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
523 error_found(nil, arg_name); |
5637
38783b8acbc9
mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5636
diff
changeset
|
524 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
|
525 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
526 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
|
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 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 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
|
534 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
|
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 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
|
537 if found == false then |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
538 error_found(nil, name); |
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
|
539 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
|
540 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
|
541 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
|
542 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
|
543 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
|
544 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
|
545 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
|
546 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
|
547 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
|
548 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
|
549 if found == false then |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
550 error_found(username); |
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
|
551 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
|
552 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
|
553 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
|
554 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
|
555 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
|
556 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
|
557 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
|
558 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
|
559 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
|
560 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
561 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
|
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 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
|
564 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
|
565 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
|
566 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
|
567 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
|
568 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
|
569 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
570 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
571 return; |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
572 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
|
573 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
|
574 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
|
575 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
|
576 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
|
577 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
|
578 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
|
579 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
|
580 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
|
581 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
|
582 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
|
583 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
|
584 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
|
585 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
|
586 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
|
587 end); |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
588 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
|
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 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
|
591 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
|
592 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
|
593 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
|
594 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
|
595 print(id); |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
596 found = 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
|
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); |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
599 if not found then |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
600 error_found(nil, name); |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
601 return 1; |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
602 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
|
603 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
|
604 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
|
605 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
|
606 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
|
607 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
|
608 print(id); |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
609 found = 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
|
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 end); |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
612 if not found then |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
613 error_found(username); |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
614 return 1; |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
615 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
|
616 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
|
617 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
|
618 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
|
619 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
|
620 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
|
621 else |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
622 print(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
|
623 end |
f7410850941f
mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5143
diff
changeset
|
624 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 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
|
626 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
|
627 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
|
628 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
|
629 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
|
630 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
|
631 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
|
632 print(id.."/"..info.token); |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
633 found = 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
|
634 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
|
635 end); |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
636 if not found then |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
637 error_found(nil, name); |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
638 return 1; |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
639 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
|
640 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
|
641 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
|
642 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
|
643 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
|
644 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
|
645 print(id.."/"..info.token); |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
646 found = 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
|
647 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
|
648 end); |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
649 if not found then |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
650 error_found(username); |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
651 return 1; |
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
652 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
|
653 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
|
654 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
|
655 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
|
656 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
|
657 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
|
658 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
|
659 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
|
660 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
|
661 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
|
662 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
|
663 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
|
664 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
|
665 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
|
666 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
|
667 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
|
668 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
|
669 print(get_url(id, info.token)); |
5638
4379e0e84ee5
mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5637
diff
changeset
|
670 found = 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
|
671 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
|
672 end); |
5638
4379e0e84ee5
mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5637
diff
changeset
|
673 if not found then |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
674 error_found(nil, name); |
5638
4379e0e84ee5
mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5637
diff
changeset
|
675 return 1; |
4379e0e84ee5
mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5637
diff
changeset
|
676 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
|
677 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
|
678 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
|
679 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
|
680 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
|
681 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
|
682 print(get_url(id, info.token)); |
5638
4379e0e84ee5
mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5637
diff
changeset
|
683 found = 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
|
684 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
|
685 end); |
5638
4379e0e84ee5
mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5637
diff
changeset
|
686 if not found then |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
687 error_found(username); |
5638
4379e0e84ee5
mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5637
diff
changeset
|
688 return 1; |
4379e0e84ee5
mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5637
diff
changeset
|
689 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
|
690 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
|
691 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
|
692 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
|
693 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
|
694 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
|
695 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
|
696 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
|
697 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
|
698 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
|
699 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
|
700 end |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
701 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
|
702 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
|
703 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
|
704 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
|
705 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
|
706 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
|
707 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
|
708 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
|
709 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
|
710 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
|
711 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
|
712 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
|
713 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
|
714 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
|
715 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
|
716 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
|
717 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
|
718 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
|
719 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
|
720 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
|
721 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
|
722 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
|
723 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
|
724 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
|
725 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
|
726 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
|
727 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
|
728 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
|
729 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
|
730 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
|
731 if not api_key_store:get(nil, arg_id) then |
5639
1664bd4c274b
mod_invites_api: refactor to keep consistent error message.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents:
5638
diff
changeset
|
732 print("Error: key not found!"); |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
733 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
|
734 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
|
735 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
|
736 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
|
737 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
|
738 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
|
739 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
|
740 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
|
741 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
|
742 return; |
4115
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
743 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
744 else |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
745 print("Unknown command - "..command); |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
746 end |
165ade4ce97b
mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
747 end |