Skip to content

Commit

Permalink
Organize
Browse files Browse the repository at this point in the history
  • Loading branch information
khjxiaogu committed Aug 21, 2022
1 parent bfe2173 commit c1bb3c2
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
Expand Down Expand Up @@ -361,7 +357,7 @@ public void reload() {
((YamlMap) excs.get(cmd)).getString("card")));
}
commands.put("/msp", (ev, args) -> {
if (!matcher.match(new MatchInfo(args[0], ev.getSender(), true)).and(matcher.match(new MatchInfo(args[0] + "." + args[1], ev.getSender(), true))).isForceAllowed())
if (!matcher.match(new MatchInfo(args[0], ev.getSender(), true).mustMatchCommand()).and(matcher.match(new MatchInfo(args[0] + "." + args[1], ev.getSender(), true).mustMatchCommand())).isForceAllowed())
return;
if (args[1].equals("reload")) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.khjxiaogu.MiraiSongPlugin.musicsource;

import java.io.FileReader;
import java.net.URLDecoder;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

import com.google.gson.JsonArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ public class BotMatcher implements PermissionMatcher {

@Override
public PermissionResult match(MatchInfo info) {
if(info.mustMatchCommand) {
PermissionMatcher pmc = commands.get(info.cmd);
if(pmc!=null)
return pmc.match(info);
return PermissionResult.UNSPECIFIED;
}
PermissionResult pr = wildcard;

for (PermissionMatcher pm : restricted.values()) {
pr = pr.and(pm.match(info));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import net.mamoe.mirai.contact.Member;
import net.mamoe.mirai.contact.MemberPermission;
import net.mamoe.mirai.contact.User;

public class CommandMatcher implements PermissionMatcher {
PermissionResult wildcard = PermissionResult.UNSPECIFIED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.util.Arrays;
import java.util.List;

import net.mamoe.mirai.contact.User;

public class FriendMatcher implements PermissionMatcher {
PermissionResult result;
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

import net.mamoe.mirai.Bot;
import net.mamoe.mirai.contact.Group;
import net.mamoe.mirai.contact.Member;
import net.mamoe.mirai.contact.User;

public class GlobalMatcher implements PermissionMatcher {
BotMatcher global;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@

import com.khjxiaogu.MiraiSongPlugin.permission.CommandMatcher.PermissionFactory;

import net.mamoe.mirai.contact.Member;
import net.mamoe.mirai.contact.User;

public class GroupMatcher implements PermissionMatcher {
PermissionResult wildcard=PermissionResult.UNSPECIFIED;
LinkedHashMap<String,PermissionMatcher> restricted=new LinkedHashMap<>(5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class MatchInfo {
long groupid;
String cmd;
boolean isTemp;
boolean mustMatchCommand;
public MatchInfo() {
}
public MatchInfo(String cmd,long memberid,long groupid,Bot bot) {
Expand All @@ -27,4 +28,8 @@ public MatchInfo(String cmd,User u,boolean temp) {
this(cmd,u.getId(),0,u.getBot());
this.isTemp=temp;
}
public MatchInfo mustMatchCommand() {
mustMatchCommand=true;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import net.mamoe.mirai.contact.Group;
import net.mamoe.mirai.contact.Member;
import net.mamoe.mirai.contact.User;

public class MemberPermissionMatcher implements PermissionMatcher {
PermissionResult result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
import java.util.Arrays;
import java.util.List;

import net.mamoe.mirai.contact.Member;
import net.mamoe.mirai.contact.User;

public final class NullOperationMatcher implements PermissionMatcher {
public static final NullOperationMatcher INSTANCE=new NullOperationMatcher();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

import java.util.List;

import net.mamoe.mirai.contact.Member;
import net.mamoe.mirai.contact.User;

public interface PermissionMatcher {
PermissionResult match(MatchInfo info);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
import java.util.Arrays;
import java.util.List;

import net.mamoe.mirai.contact.Member;
import net.mamoe.mirai.contact.User;

public class StrangerMatcher implements PermissionMatcher {
PermissionResult result;
@Override
Expand Down

0 comments on commit c1bb3c2

Please sign in to comment.