Compare commits
2 Commits
1705f4d752
...
使用mirai的最后
| Author | SHA1 | Date | |
|---|---|---|---|
| d4b8e58946 | |||
| 22416227d8 |
@@ -2,6 +2,7 @@ package com.yutou.qqbot;
|
||||
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import net.mamoe.mirai.Bot;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
@@ -33,4 +34,16 @@ public class QQBotController {
|
||||
AppTools.sendServer(title, msg);
|
||||
return "ok";
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/bot/test.do")
|
||||
public String testLogin(){
|
||||
Bot bot = QQBotManager.getInstance().getBot();
|
||||
return bot.isOnline()+"";
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/bot/login.do")
|
||||
public String login(){
|
||||
QQBotManager.getInstance().reLogin();
|
||||
return "ok";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.yutou.qqbot.Listeners.QQMessageListener;
|
||||
import com.yutou.qqbot.utlis.*;
|
||||
import net.mamoe.mirai.Bot;
|
||||
import net.mamoe.mirai.BotFactory;
|
||||
import net.mamoe.mirai.auth.BotAuthorization;
|
||||
import net.mamoe.mirai.event.GlobalEventChannel;
|
||||
import net.mamoe.mirai.message.MessageReceipt;
|
||||
import net.mamoe.mirai.message.data.*;
|
||||
@@ -55,7 +54,11 @@ public class QQBotManager {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String test = HttpTools.get("http://192.168.31.88:7400/");
|
||||
String url=ConfigTools.load(ConfigTools.CONFIG,"sign_url",String.class);
|
||||
if(StringUtils.isEmpty(url)){
|
||||
url="http://192.168.31.88:7400/";
|
||||
}
|
||||
String test = HttpTools.get(url);
|
||||
try {
|
||||
JSONObject json = JSONObject.parseObject(test);
|
||||
if (json.getInteger("code") != 0) {
|
||||
@@ -101,7 +104,6 @@ public class QQBotManager {
|
||||
}
|
||||
}).start();
|
||||
bot.join();
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
@@ -266,4 +268,12 @@ public class QQBotManager {
|
||||
public Bot getBot() {
|
||||
return bot;
|
||||
}
|
||||
|
||||
public void reLogin() {
|
||||
isInit=false;
|
||||
if(bot.isOnline()){
|
||||
bot.close();
|
||||
}
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,56 +13,61 @@ import java.util.Set;
|
||||
|
||||
public class QQNumberManager {
|
||||
private static QQNumberManager manager;
|
||||
private QQNumberManager(){
|
||||
|
||||
private QQNumberManager() {
|
||||
|
||||
}
|
||||
|
||||
public static QQNumberManager getManager() {
|
||||
if(manager==null) {
|
||||
manager=new QQNumberManager();
|
||||
if (manager == null) {
|
||||
manager = new QQNumberManager();
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
public void addNumber(Long qq,boolean isGroup){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
|
||||
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());
|
||||
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();
|
||||
|
||||
public List<Long> getNumber() {
|
||||
List<Long> list = new ArrayList<>();
|
||||
Jedis jedis = RedisTools.getRedis();
|
||||
jedis.select(RedisTools.QQBOT_USER);
|
||||
Set<String> set=jedis.keys("*");
|
||||
Set<String> set = jedis.keys("*");
|
||||
for (String s : set) {
|
||||
try {
|
||||
list.add(Long.parseLong(s));
|
||||
}catch (Exception ignored){
|
||||
list.add(Long.parseLong(s));
|
||||
} catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
jedis.close();
|
||||
return list;
|
||||
}
|
||||
public boolean addPower(Long qq, String power){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("power");
|
||||
|
||||
public boolean addPower(Long qq, String power) {
|
||||
if (RedisTools.exists(qq, null)) {
|
||||
JSONObject json = JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array = json.getJSONArray("power");
|
||||
array.add(power);
|
||||
json.put("power",array);
|
||||
return RedisTools.set(qq,json.toJSONString());
|
||||
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=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("power");
|
||||
|
||||
public List<String> getPower(Long qq) {
|
||||
List<String> list = new ArrayList<>();
|
||||
if (RedisTools.exists(qq, null)) {
|
||||
JSONObject json = JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array = json.getJSONArray("power");
|
||||
for (Object power : array) {
|
||||
list.add((String) power);
|
||||
}
|
||||
@@ -70,11 +75,12 @@ public class QQNumberManager {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<String> getUseModel(long qq) {
|
||||
List<String> list=new ArrayList<>();
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("model");
|
||||
List<String> list = new ArrayList<>();
|
||||
if (RedisTools.exists(qq, null)) {
|
||||
JSONObject json = JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array = json.getJSONArray("model");
|
||||
for (Object power : array) {
|
||||
list.add((String) power);
|
||||
}
|
||||
@@ -82,43 +88,47 @@ public class QQNumberManager {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
public boolean delPower(Long qq, String power){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("power");
|
||||
|
||||
public boolean delPower(Long qq, String power) {
|
||||
if (RedisTools.exists(qq, null)) {
|
||||
JSONObject json = JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array = json.getJSONArray("power");
|
||||
array.remove(power);
|
||||
json.put("power",array);
|
||||
return RedisTools.set(qq,json.toJSONString());
|
||||
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=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("model");
|
||||
|
||||
public boolean addUseModel(Long qq, Class<?> modelClass) {
|
||||
if (RedisTools.exists(qq, null)) {
|
||||
JSONObject json = JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array = json.getJSONArray("model");
|
||||
array.add(modelClass.getName());
|
||||
json.put("model",array);
|
||||
return RedisTools.set(qq,json.toJSONString());
|
||||
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=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("model");
|
||||
|
||||
public boolean delUseModel(Long qq, Class<?> modelClass) {
|
||||
if (RedisTools.exists(qq, null)) {
|
||||
JSONObject json = JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array = json.getJSONArray("model");
|
||||
array.remove(modelClass.getName());
|
||||
json.put("model",array);
|
||||
return RedisTools.set(qq,json.toJSONString());
|
||||
json.put("model", array);
|
||||
return RedisTools.set(qq, json.toJSONString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean isExistsPower(Long qq, String... power){
|
||||
|
||||
public boolean isExistsPower(Long qq, String... power) {
|
||||
//1
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("power");
|
||||
if (RedisTools.exists(qq, null)) {
|
||||
JSONObject json = JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array = json.getJSONArray("power");
|
||||
for (String key : power) {
|
||||
if(!array.contains(key)){
|
||||
if (!array.contains(key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -126,18 +136,25 @@ public class QQNumberManager {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean isGroup(Long qq){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json= JSON.parseObject(RedisTools.get(qq));
|
||||
|
||||
public boolean isGroup(Long qq) {
|
||||
if (RedisTools.exists(qq, null)) {
|
||||
JSONObject json = JSON.parseObject(RedisTools.get(qq));
|
||||
return json.getBooleanValue("group");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean isUseModel(Long qq,Class<?> modelClass){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("model");
|
||||
return array.contains(modelClass.getName());
|
||||
|
||||
public boolean isUseModel(Long qq, Class<?> modelClass) {
|
||||
try {
|
||||
if (RedisTools.exists(qq, null)) {
|
||||
JSONObject json = JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array = json.getJSONArray("model");
|
||||
return array.contains(modelClass.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.i("isUseModel", qq + " " + modelClass.getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user