新增查看授权信息

This commit is contained in:
Yutousama 2021-12-07 22:31:33 +08:00
parent 3eec3a51a3
commit dbb7e3ea68
5 changed files with 36 additions and 12 deletions

View File

@ -36,7 +36,6 @@ public class QQMessageListener extends SimpleListenerHost {
if (event.getSource().getFromId() == 583819556) {
new AdminMessage(qqNumber, event.getMessage().contentToString());
}
System.out.println("isGroup = " + isGroup);
for (Class<?> model : Model.classList) {
if (QQNumberManager.getManager().isUseModel(qqNumber, model)) {
try {

View File

@ -3,6 +3,7 @@ package com.yutou.qqbot.MessageEvent;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.QQNumberManager;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.RedisTools;
import com.yutou.qqbot.utlis.StringUtils;
import java.util.List;
@ -16,6 +17,9 @@ public class AdminMessage extends Message {
private static final String MODEL_ADD = "!新增模块";
private static final String MODEL_SHOW = "!查看模块";
private static final String MODEL_DEL = "!删除模块";
private static final String SHOW="!列表";
private static final String HELP="!help";
}
public AdminMessage(Long qq, String msg) {
@ -27,8 +31,8 @@ public class AdminMessage extends Message {
for (Class<?> aClass : Model.classList) {
System.err.println(aClass.getName());
}
String[] commands;
switch (msgGroup[0]) {
case QQCommands.HELP -> QQBotManager.getInstance().sendMessage(qq,Model.getCommands(QQCommands.class).toString());
case QQCommands.POWER_ADD -> {
if (msgGroup.length == 1) {
StringBuilder builder = Model.getCommands(Model.QQGroupCommands.class);
@ -106,6 +110,27 @@ public class AdminMessage extends Message {
}
}
}
case QQCommands.SHOW -> {
List<Long> users=QQNumberManager.getManager().getNumber();
StringBuilder builder=new StringBuilder();
for (Long user : users) {
builder.append(user).append(":\n");
if(QQNumberManager.getManager().isGroup(user)){
List<String> list=QQNumberManager.getManager().getUseModel(user);
builder.append("模块(").append(list.size()).append("):\n");
for (String model : list) {
builder.append(model).append("\n");
}
}
List<String> list=QQNumberManager.getManager().getPower(user);
builder.append("权限(").append(list.size()).append("):\n");
for (String power : list) {
builder.append(power).append("\n");
}
builder.append("\n");
}
QQBotManager.getInstance().sendMessage(qq,builder.toString());
}
}
}

View File

@ -1,6 +1,7 @@
package com.yutou.qqbot;
import com.yutou.qqbot.Listeners.QQMessageListener;
import com.yutou.qqbot.models.Animal.TurnipProphet;
import com.yutou.qqbot.models.Commands.Bangumi;
import com.yutou.qqbot.models.Commands.System.*;
import com.yutou.qqbot.models.Model;
@ -33,6 +34,8 @@ public class QQBotManager {
Model.classList.add(UpdateIP.class);
Model.classList.add(Version.class);
Model.classList.add(Bangumi.class);
Model.classList.add(TurnipProphet.class);
}
private static QQBotManager botManager = null;
private Bot bot;

View File

@ -35,7 +35,7 @@ public class QQNumberManager {
public List<Long> getNumber(){
List<Long> list =new ArrayList<>();
Jedis jedis=RedisTools.getRedis();
jedis.select(3);
jedis.select(RedisTools.QQBOT_USER);
Set<String> set=jedis.keys("*");
for (String s : set) {
list.add(Long.parseLong(s));

View File

@ -17,6 +17,7 @@ import java.util.Set;
public class RedisTools {
public static final int QQBOT_USER = 3;
private static boolean isNotInstallRedis = false;
private static String host;
private static int port;
@ -78,11 +79,11 @@ public class RedisTools {
}
public static boolean set(Object key, String value) {
return set(3, key+"", value);
return set(QQBOT_USER, key+"", value);
}
public static boolean set(String key, String value, long timeout) {
return set(key, value, timeout,3);
return set(key, value, timeout,QQBOT_USER);
}
public static String get(String key, int dbIndex) {
@ -102,11 +103,11 @@ public class RedisTools {
}
public static String get(Object key) {
return get(key+"", 3);
return get(key+"", QQBOT_USER);
}
public static boolean remove(String key) {
return remove(key,3);
return remove(key,QQBOT_USER);
}
public static void removeLoginState(String uid) {
@ -127,7 +128,7 @@ public class RedisTools {
return tmp;
}
public static boolean exists(Object key,String value){
return exists(3,key,value);
return exists(QQBOT_USER,key,value);
}
public static boolean exists(int db,Object key, String value) {
if (isNotInstallRedis) {
@ -194,13 +195,9 @@ public class RedisTools {
}
public static void pullMsg(String channel, String msg) {
Log.i("1");
Jedis jedis = getPoolRedis();
Log.i("2");
jedis.publish(channel, msg);
Log.i("3");
jedis.close();
Log.i("4");
}
private static boolean init = false;