mirror of
https://github.com/jie65535/gc-openchat-plugin.git
synced 2025-06-01 17:29:11 +08:00
feat: implement group command response
This commit is contained in:
parent
e795c5a9c4
commit
dc90a17824
@ -45,7 +45,6 @@ Server command (requires `server.chat.others` permissions) :
|
||||
- `/serverchat op|deop <userId(QQ)>` Set or remove op
|
||||
- The account set as op can directly execute commands with the admin prefix in the specified group
|
||||
- The command prefix can be set in the configuration file `adminPrefix`, the default is `/`, for example `/sc ban @10002`
|
||||
- At present, there is no reply when executing commands in the group, because the console execution process will only log to the console, which is not easy to capture
|
||||
|
||||
`/serverchat` can be aliased as `/sc`
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
在游戏内与服务器账号对话,相当于发送到世界频道,服务器内所有玩家均可收到消息。
|
||||
|
||||
## TODO List
|
||||
## 功能列表
|
||||
- [x] 玩家间聊天
|
||||
- [x] 聊天管理命令
|
||||
- [x] 发言频率限制
|
||||
@ -72,12 +72,10 @@
|
||||
7. 在GC中使用 `/sc op <userId(QQ)>` 来设置管理员账号
|
||||
8. 现在,理论上已经完成了群服互联,在群里可以看到玩家上下线和聊天,同时玩家也可以在游戏里看到群里聊天,
|
||||
你还可以在群里用默认前缀 `/` 来执行命令,
|
||||
但是暂时**不会**回复结果,你可能需要自己看控制台来查看执行结果。
|
||||
|
||||
|
||||
_值得注意的是,本插件支持的是 [OneBot-v11](https://github.com/botuniverse/onebot-11) 协议,理论上所有支持OneBot-v11 [反向WebSocket](https://github.com/botuniverse/onebot-11/blob/master/communication/ws-reverse.md) 的机器人框架都可以连接,不仅限于cqhttp。_
|
||||
|
||||
_TODO: 计划会出一个极简的纯对话协议,比OneBot更简单,方便第三方对接。_
|
||||
|
||||
---
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
*/
|
||||
package com.github.jie65535.openchat;
|
||||
|
||||
import emu.grasscutter.command.CommandMap;
|
||||
import emu.grasscutter.server.event.game.ReceiveCommandFeedbackEvent;
|
||||
import emu.grasscutter.server.event.player.PlayerJoinEvent;
|
||||
|
||||
public final class EventListeners {
|
||||
@ -26,4 +28,31 @@ public final class EventListeners {
|
||||
((OpenChatSystem) cs).onPlayerJoin(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static final StringBuilder consoleMessageHandler = new StringBuilder();
|
||||
private static StringBuilder commandResponseHandler;
|
||||
public static String runConsoleCommand(String rawCommand) {
|
||||
synchronized (consoleMessageHandler) {
|
||||
commandResponseHandler = consoleMessageHandler;
|
||||
consoleMessageHandler.setLength(0);
|
||||
// 尝试执行管理员命令
|
||||
CommandMap.getInstance().invoke(null, null, rawCommand);
|
||||
commandResponseHandler = null;
|
||||
return consoleMessageHandler.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 命令执行反馈事件处理
|
||||
*/
|
||||
public static void onCommandResponse(ReceiveCommandFeedbackEvent event) {
|
||||
if (commandResponseHandler == null || event.getPlayer() != null) return;
|
||||
|
||||
if (!consoleMessageHandler.isEmpty()) {
|
||||
// New line
|
||||
consoleMessageHandler.append(System.lineSeparator());
|
||||
}
|
||||
consoleMessageHandler.append(event.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import com.github.jie65535.openchat.utils.SensitiveWordFilter;
|
||||
import emu.grasscutter.plugin.Plugin;
|
||||
import emu.grasscutter.server.event.EventHandler;
|
||||
import emu.grasscutter.server.event.HandlerPriority;
|
||||
import emu.grasscutter.server.event.game.ReceiveCommandFeedbackEvent;
|
||||
import emu.grasscutter.server.event.player.PlayerJoinEvent;
|
||||
import emu.grasscutter.utils.JsonUtils;
|
||||
|
||||
@ -58,6 +59,10 @@ public final class OpenChatPlugin extends Plugin {
|
||||
.priority(HandlerPriority.NORMAL)
|
||||
.listener(EventListeners::onJoin)
|
||||
.register(this);
|
||||
new EventHandler<>(ReceiveCommandFeedbackEvent.class)
|
||||
.priority(HandlerPriority.NORMAL)
|
||||
.listener(EventListeners::onCommandResponse)
|
||||
.register(this);
|
||||
|
||||
// Register commands.
|
||||
getHandle().registerCommand(new ChatServerCommands());
|
||||
|
@ -20,7 +20,6 @@ package com.github.jie65535.openchat;
|
||||
import com.github.jie65535.minionebot.MiniOneBot;
|
||||
import com.github.jie65535.minionebot.events.GroupMessage;
|
||||
import emu.grasscutter.GameConstants;
|
||||
import emu.grasscutter.command.CommandMap;
|
||||
import emu.grasscutter.game.chat.ChatSystem;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.server.event.player.PlayerJoinEvent;
|
||||
@ -259,9 +258,9 @@ public class OpenChatSystem extends ChatSystem {
|
||||
) {
|
||||
try {
|
||||
logger.info("Command used by op [{}({})]: {}", event.senderCardOrNickname(), event.senderId(), event.message());
|
||||
// 尝试执行管理员命令
|
||||
CommandMap.getInstance().invoke(null, null,
|
||||
event.message().substring(plugin.getConfig().adminPrefix.length()));
|
||||
String rawCommand = event.message().substring(plugin.getConfig().adminPrefix.length());
|
||||
String result = EventListeners.runConsoleCommand(rawCommand);
|
||||
miniOneBot.sendGroupMessage(event.groupId(), result);
|
||||
} catch (Exception ex) {
|
||||
logger.error("Administrator command execution failed", ex);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user