Mercurial > prosody-modules
diff mod_easy_invite/mod_easy_invite.lua @ 4022:3ac31ddab7eb
mod_easy_invite: Add commands to telnet console
Handy if all you have is SSH access and no ad-hoc capable client
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 16 May 2020 19:48:26 +0200 |
parents | 14028430638b |
children | 7e2db4d61f6c |
line wrap: on
line diff
--- a/mod_easy_invite/mod_easy_invite.lua Sat May 16 18:30:01 2020 +0200 +++ b/mod_easy_invite/mod_easy_invite.lua Sat May 16 19:48:26 2020 +0200 @@ -184,6 +184,35 @@ subscribe_both(module.host, inviter_username, contact_username); end); +do + -- Telnet command + -- Since the telnet console is global this overwrites the command for + -- each host it's loaded on, but this should be fine. + + local get_module = require "core.modulemanager".get_module; + + local console_env = module:shared("/*/admin_telnet/env"); + + -- luacheck: ignore 212/self + console_env.invite = {}; + function console_env.invite:create_account(user_jid) + local username, host = jid_split(user_jid); + local mod_invites, err = get_module(host, "invites"); + if not mod_invites then return nil, err or "mod_invites not loaded on this host"; end + local invite, err = mod_invites.create_account(username); + if not invite then return nil, err; end + return true, invite.uri; + end + + function console_env.invite:create_contact(user_jid, allow_registration) + local username, host = jid_split(user_jid); + local mod_invites, err = get_module(host, "invites"); + if not mod_invites then return nil, err or "mod_invites not loaded on this host"; end + local invite, err = mod_invites.create_contact(username, allow_registration); + if not invite then return nil, err; end + return true, invite.uri; + end +end local sm = require "core.storagemanager"; function module.command(arg)