mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-11-01 10:56:17 +08:00
xml config support & multi-step command matcher
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package love.sola.netsupport.wechat.matcher;
|
||||
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import me.chanjar.weixin.mp.api.WxMpMessageMatcher;
|
||||
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/11/26.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class CommandMatcher implements WxMpMessageMatcher {
|
||||
|
||||
public static Map<String, Command> inCmdUsers = new ConcurrentHashMap<>();
|
||||
|
||||
Command command;
|
||||
|
||||
public CommandMatcher(Command command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(WxMpXmlMessage message) {
|
||||
String fromUser = message.getFromUserName();
|
||||
if (inCmdUsers.containsKey(fromUser)) {
|
||||
return command == inCmdUsers.get(fromUser);
|
||||
} else {
|
||||
return message.getContent().matches(command.getRegex());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user