Skeleton for modular AS admin command processing
This commit is contained in:
@@ -27,6 +27,7 @@ import io.kamax.matrix.client.MatrixClientContext;
|
|||||||
import io.kamax.matrix.client.as.MatrixApplicationServiceClient;
|
import io.kamax.matrix.client.as.MatrixApplicationServiceClient;
|
||||||
import io.kamax.matrix.event.EventKey;
|
import io.kamax.matrix.event.EventKey;
|
||||||
import io.kamax.matrix.json.GsonUtil;
|
import io.kamax.matrix.json.GsonUtil;
|
||||||
|
import io.kamax.mxisd.as.processor.event.EventTypeProcessor;
|
||||||
import io.kamax.mxisd.as.processor.event.MembershipEventProcessor;
|
import io.kamax.mxisd.as.processor.event.MembershipEventProcessor;
|
||||||
import io.kamax.mxisd.as.processor.event.MessageEventProcessor;
|
import io.kamax.mxisd.as.processor.event.MessageEventProcessor;
|
||||||
import io.kamax.mxisd.as.registration.SynapseRegistrationYaml;
|
import io.kamax.mxisd.as.registration.SynapseRegistrationYaml;
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* mxisd - Matrix Identity Server Daemon
|
||||||
|
* Copyright (C) 2019 Kamax Sarl
|
||||||
|
*
|
||||||
|
* https://www.kamax.io/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.kamax.mxisd.as.processor.command;
|
||||||
|
|
||||||
|
import io.kamax.matrix.client._MatrixClient;
|
||||||
|
import io.kamax.matrix.hs._MatrixRoom;
|
||||||
|
import io.kamax.mxisd.Mxisd;
|
||||||
|
|
||||||
|
public interface CommandProcessor {
|
||||||
|
|
||||||
|
void process(Mxisd m, _MatrixClient client, _MatrixRoom room, String command, String[] arguments);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* mxisd - Matrix Identity Server Daemon
|
||||||
|
* Copyright (C) 2019 Kamax Sarl
|
||||||
|
*
|
||||||
|
* https://www.kamax.io/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.kamax.mxisd.as.processor.command;
|
||||||
|
|
||||||
|
import io.kamax.matrix.client._MatrixClient;
|
||||||
|
import io.kamax.matrix.hs._MatrixRoom;
|
||||||
|
import io.kamax.mxisd.Mxisd;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
public class InviteCommandProcessor implements CommandProcessor {
|
||||||
|
|
||||||
|
public static final String Command = "invite";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(Mxisd m, _MatrixClient client, _MatrixRoom room, String command, String[] arguments) {
|
||||||
|
if (arguments.length < 1) {
|
||||||
|
room.sendText(buildHelp());
|
||||||
|
}
|
||||||
|
|
||||||
|
String subcmd = arguments[0];
|
||||||
|
String response;
|
||||||
|
if (StringUtils.equals("list", subcmd)) {
|
||||||
|
response = buildError("This command is not supported yet", false);
|
||||||
|
} else if (StringUtils.endsWith("show", subcmd)) {
|
||||||
|
response = buildError("This command is not supported yet", false);
|
||||||
|
} else if (StringUtils.equals("revoke", subcmd)) {
|
||||||
|
response = buildError("This command is not supported yet", false);
|
||||||
|
} else {
|
||||||
|
response = buildError("Unknown command: " + subcmd, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
room.sendText(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildError(String message, boolean showHelp) {
|
||||||
|
if (showHelp) {
|
||||||
|
message = message + "\n\n" + buildHelp();
|
||||||
|
}
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildHelp() {
|
||||||
|
return "Available actions:\n\n" +
|
||||||
|
"list - List invites\n" +
|
||||||
|
"show - Show detailed info about a specific invite\n" +
|
||||||
|
"revoke - Revoke a pending invite by resolving it to the configured Expiration user\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* mxisd - Matrix Identity Server Daemon
|
||||||
|
* Copyright (C) 2019 Kamax Sarl
|
||||||
|
*
|
||||||
|
* https://www.kamax.io/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.kamax.mxisd.as.processor.command;
|
||||||
|
|
||||||
|
import io.kamax.matrix.client._MatrixClient;
|
||||||
|
import io.kamax.matrix.hs._MatrixRoom;
|
||||||
|
import io.kamax.mxisd.Mxisd;
|
||||||
|
|
||||||
|
public class PingCommandProcessor implements CommandProcessor {
|
||||||
|
|
||||||
|
public static final String Command = "ping";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(Mxisd m, _MatrixClient client, _MatrixRoom room, String command, String[] arguments) {
|
||||||
|
room.sendText("Pong!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.kamax.mxisd.as;
|
package io.kamax.mxisd.as.processor.event;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import io.kamax.matrix._MatrixID;
|
import io.kamax.matrix._MatrixID;
|
||||||
@@ -28,7 +28,6 @@ import io.kamax.matrix._ThreePid;
|
|||||||
import io.kamax.matrix.client.as.MatrixApplicationServiceClient;
|
import io.kamax.matrix.client.as.MatrixApplicationServiceClient;
|
||||||
import io.kamax.matrix.event.EventKey;
|
import io.kamax.matrix.event.EventKey;
|
||||||
import io.kamax.matrix.hs._MatrixRoom;
|
import io.kamax.matrix.hs._MatrixRoom;
|
||||||
import io.kamax.mxisd.as.EventTypeProcessor;
|
|
||||||
import io.kamax.mxisd.backend.sql.synapse.Synapse;
|
import io.kamax.mxisd.backend.sql.synapse.Synapse;
|
||||||
import io.kamax.mxisd.config.MxisdConfig;
|
import io.kamax.mxisd.config.MxisdConfig;
|
||||||
import io.kamax.mxisd.invitation.IMatrixIdInvite;
|
import io.kamax.mxisd.invitation.IMatrixIdInvite;
|
||||||
|
|||||||
@@ -26,12 +26,16 @@ import io.kamax.matrix._MatrixUserProfile;
|
|||||||
import io.kamax.matrix.client.as.MatrixApplicationServiceClient;
|
import io.kamax.matrix.client.as.MatrixApplicationServiceClient;
|
||||||
import io.kamax.matrix.hs._MatrixRoom;
|
import io.kamax.matrix.hs._MatrixRoom;
|
||||||
import io.kamax.matrix.json.event.MatrixJsonRoomMessageEvent;
|
import io.kamax.matrix.json.event.MatrixJsonRoomMessageEvent;
|
||||||
import io.kamax.mxisd.as.EventTypeProcessor;
|
import io.kamax.mxisd.as.processor.command.CommandProcessor;
|
||||||
|
import io.kamax.mxisd.as.processor.command.InviteCommandProcessor;
|
||||||
|
import io.kamax.mxisd.as.processor.command.PingCommandProcessor;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class MessageEventProcessor implements EventTypeProcessor {
|
public class MessageEventProcessor implements EventTypeProcessor {
|
||||||
@@ -39,9 +43,14 @@ public class MessageEventProcessor implements EventTypeProcessor {
|
|||||||
private static final Logger log = LoggerFactory.getLogger(MessageEventProcessor.class);
|
private static final Logger log = LoggerFactory.getLogger(MessageEventProcessor.class);
|
||||||
|
|
||||||
private final MatrixApplicationServiceClient client;
|
private final MatrixApplicationServiceClient client;
|
||||||
|
private Map<String, CommandProcessor> processors;
|
||||||
|
|
||||||
public MessageEventProcessor(MatrixApplicationServiceClient client) {
|
public MessageEventProcessor(MatrixApplicationServiceClient client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
|
processors = new HashMap<>();
|
||||||
|
processors.put(PingCommandProcessor.Command, new PingCommandProcessor());
|
||||||
|
processors.put(InviteCommandProcessor.Command, new InviteCommandProcessor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user