2021-12-07 21:59:41 +08:00
|
|
|
package com.yutou.qqbot;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.yutou.qqbot.utlis.Log;
|
|
|
|
import com.yutou.qqbot.utlis.RedisTools;
|
|
|
|
import redis.clients.jedis.Jedis;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
public class QQNumberManager {
|
|
|
|
private static QQNumberManager manager;
|
|
|
|
private QQNumberManager(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static QQNumberManager getManager() {
|
|
|
|
if(manager==null) {
|
|
|
|
manager=new QQNumberManager();
|
|
|
|
}
|
|
|
|
return manager;
|
|
|
|
}
|
|
|
|
public void addNumber(Long qq,boolean isGroup){
|
|
|
|
if(RedisTools.exists(qq,null)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JSONObject json=new JSONObject();
|
|
|
|
json.put("group",isGroup);
|
|
|
|
json.put("power",new JSONArray());
|
|
|
|
json.put("model",new JSONArray());
|
|
|
|
RedisTools.set(qq,json.toJSONString());
|
|
|
|
}
|
|
|
|
public List<Long> getNumber(){
|
|
|
|
List<Long> list =new ArrayList<>();
|
|
|
|
Jedis jedis=RedisTools.getRedis();
|
2021-12-07 22:31:33 +08:00
|
|
|
jedis.select(RedisTools.QQBOT_USER);
|
2021-12-07 21:59:41 +08:00
|
|
|
Set<String> set=jedis.keys("*");
|
|
|
|
for (String s : set) {
|
2021-12-09 02:50:53 +08:00
|
|
|
try {
|
2021-12-07 21:59:41 +08:00
|
|
|
list.add(Long.parseLong(s));
|
2021-12-09 02:50:53 +08:00
|
|
|
}catch (Exception ignored){
|
|
|
|
|
|
|
|
}
|
2021-12-07 21:59:41 +08:00
|
|
|
}
|
|
|
|
jedis.close();
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
public boolean addPower(Long qq, String power){
|
|
|
|
if(RedisTools.exists(qq,null)){
|
|
|
|
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
|
|
|
JSONArray array=json.getJSONArray("power");
|
|
|
|
array.add(power);
|
|
|
|
json.put("power",array);
|
|
|
|
return RedisTools.set(qq,json.toJSONString());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
public List<String> getPower(Long qq){
|
|
|
|
List<String> list=new ArrayList<>();
|
|
|
|
if(RedisTools.exists(qq,null)){
|
|
|
|
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
|
|
|
JSONArray array=json.getJSONArray("power");
|
|
|
|
for (Object power : array) {
|
|
|
|
list.add((String) power);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
public List<String> getUseModel(long qq) {
|
|
|
|
List<String> list=new ArrayList<>();
|
|
|
|
if(RedisTools.exists(qq,null)){
|
|
|
|
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
|
|
|
JSONArray array=json.getJSONArray("model");
|
|
|
|
for (Object power : array) {
|
|
|
|
list.add((String) power);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
public boolean delPower(Long qq, String power){
|
|
|
|
if(RedisTools.exists(qq,null)){
|
|
|
|
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
|
|
|
JSONArray array=json.getJSONArray("power");
|
|
|
|
array.remove(power);
|
|
|
|
json.put("power",array);
|
|
|
|
return RedisTools.set(qq,json.toJSONString());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
public boolean addUseModel(Long qq,Class<?> modelClass){
|
|
|
|
if(RedisTools.exists(qq,null)){
|
|
|
|
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
|
|
|
JSONArray array=json.getJSONArray("model");
|
|
|
|
array.add(modelClass.getName());
|
|
|
|
json.put("model",array);
|
|
|
|
return RedisTools.set(qq,json.toJSONString());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
public boolean delUseModel(Long qq,Class<?> modelClass){
|
|
|
|
if(RedisTools.exists(qq,null)){
|
|
|
|
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
|
|
|
JSONArray array=json.getJSONArray("model");
|
|
|
|
array.remove(modelClass.getName());
|
|
|
|
json.put("model",array);
|
|
|
|
return RedisTools.set(qq,json.toJSONString());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
public boolean isExistsPower(Long qq, String... power){
|
|
|
|
if(RedisTools.exists(qq,null)){
|
|
|
|
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
|
|
|
JSONArray array=json.getJSONArray("power");
|
|
|
|
for (String key : power) {
|
|
|
|
if(!array.contains(key)){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
public boolean isGroup(Long qq){
|
|
|
|
if(RedisTools.exists(qq,null)){
|
|
|
|
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
|
|
|
return json.getBoolean("group");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
public boolean isUseModel(Long qq,Class<?> modelClass){
|
|
|
|
if(RedisTools.exists(qq,null)){
|
|
|
|
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
|
|
|
JSONArray array=json.getJSONArray("model");
|
|
|
|
return array.contains(modelClass.getName());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|