update:调整QQBot的返回值
This commit is contained in:
parent
61c9fc60a0
commit
4fabd514a7
@ -6,6 +6,7 @@ import com.yutou.qqbot.utlis.AppTools;
|
|||||||
import com.yutou.qqbot.utlis.HttpTools;
|
import com.yutou.qqbot.utlis.HttpTools;
|
||||||
import com.yutou.qqbot.utlis.RedisTools;
|
import com.yutou.qqbot.utlis.RedisTools;
|
||||||
import com.yutou.qqbot.utlis.StringUtils;
|
import com.yutou.qqbot.utlis.StringUtils;
|
||||||
|
import net.mamoe.mirai.message.MessageReceipt;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -63,7 +64,7 @@ public class AppController {
|
|||||||
@RequestMapping("/qq/send.do")
|
@RequestMapping("/qq/send.do")
|
||||||
public String sendQQ(@RequestBody JSONObject json) {
|
public String sendQQ(@RequestBody JSONObject json) {
|
||||||
File image = null;
|
File image = null;
|
||||||
String ret;
|
MessageReceipt<?> ret;
|
||||||
if(json.getString("message").isEmpty()){
|
if(json.getString("message").isEmpty()){
|
||||||
return "not message";
|
return "not message";
|
||||||
}
|
}
|
||||||
@ -76,7 +77,7 @@ public class AppController {
|
|||||||
} else {
|
} else {
|
||||||
ret = QQBotManager.getInstance().sendMessage(json.getLong("qq"), json.getString("message"));
|
ret = QQBotManager.getInstance().sendMessage(json.getLong("qq"), json.getString("message"));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret==null?"message send fail":"message send success";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@ -6,7 +6,9 @@ import com.yutou.qqbot.Listeners.QQMessageListener;
|
|||||||
import com.yutou.qqbot.utlis.*;
|
import com.yutou.qqbot.utlis.*;
|
||||||
import net.mamoe.mirai.Bot;
|
import net.mamoe.mirai.Bot;
|
||||||
import net.mamoe.mirai.BotFactory;
|
import net.mamoe.mirai.BotFactory;
|
||||||
|
import net.mamoe.mirai.contact.Group;
|
||||||
import net.mamoe.mirai.event.GlobalEventChannel;
|
import net.mamoe.mirai.event.GlobalEventChannel;
|
||||||
|
import net.mamoe.mirai.message.MessageReceipt;
|
||||||
import net.mamoe.mirai.message.data.Image;
|
import net.mamoe.mirai.message.data.Image;
|
||||||
import net.mamoe.mirai.message.data.MessageChain;
|
import net.mamoe.mirai.message.data.MessageChain;
|
||||||
import net.mamoe.mirai.message.data.MessageChainBuilder;
|
import net.mamoe.mirai.message.data.MessageChainBuilder;
|
||||||
@ -127,36 +129,37 @@ public class QQBotManager {
|
|||||||
return getNotLoginQQ();
|
return getNotLoginQQ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sendMessage(Long group, String text) {
|
public MessageReceipt<?> sendMessage(Long group, String text) {
|
||||||
if (bot != null) {
|
if (bot != null) {
|
||||||
try {
|
try {
|
||||||
if (QQNumberManager.getManager().isGroup(group)) {
|
if (QQNumberManager.getManager().isGroup(group)) {
|
||||||
return Objects.requireNonNull(bot.getGroup(group)).sendMessage(text).toString();
|
return Objects.requireNonNull(bot.getGroup(group)).sendMessage(text);
|
||||||
} else {
|
} else {
|
||||||
return Objects.requireNonNull(bot.getFriend(group)).sendMessage(text).toString();
|
return Objects.requireNonNull(bot.getFriend(group)).sendMessage(text);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getNotLoginQQ();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(Long group, MessageChainBuilder builder) {
|
public MessageReceipt<?> sendMessage(Long group, MessageChainBuilder builder) {
|
||||||
if (bot != null) {
|
if (bot != null) {
|
||||||
if (QQNumberManager.getManager().isGroup(group)) {
|
if (QQNumberManager.getManager().isGroup(group)) {
|
||||||
Objects.requireNonNull(bot.getGroup(group)).sendMessage(builder.asMessageChain());
|
return Objects.requireNonNull(bot.getGroup(group)).sendMessage(builder.asMessageChain());
|
||||||
} else {
|
} else {
|
||||||
Objects.requireNonNull(bot.getFriend(group)).sendMessage(builder.asMessageChain());
|
return Objects.requireNonNull(bot.getFriend(group)).sendMessage(builder.asMessageChain());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sendMessage(File imageFile, Long qq, String text) {
|
public MessageReceipt<?> sendMessage(File imageFile, Long qq, String text) {
|
||||||
return sendMessage(imageFile, qq, null, text);
|
return sendMessage(imageFile, qq, null, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sendMessage(File imageFile, Long qq, MessageChain replyMessage, String text) {
|
public MessageReceipt<?> sendMessage(File imageFile, Long qq, MessageChain replyMessage, String text) {
|
||||||
try {
|
try {
|
||||||
if (bot != null) {
|
if (bot != null) {
|
||||||
Image image = getImage(imageFile, qq);
|
Image image = getImage(imageFile, qq);
|
||||||
@ -169,19 +172,19 @@ public class QQBotManager {
|
|||||||
}
|
}
|
||||||
builder.append(text);
|
builder.append(text);
|
||||||
if (QQNumberManager.getManager().isGroup(qq)) {
|
if (QQNumberManager.getManager().isGroup(qq)) {
|
||||||
return Objects.requireNonNull(bot.getGroup(qq)).sendMessage(builder.asMessageChain()).toString();
|
return Objects.requireNonNull(bot.getGroup(qq)).sendMessage(builder.asMessageChain());
|
||||||
} else {
|
} else {
|
||||||
return Objects.requireNonNull(bot.getFriend(qq)).sendMessage(builder.asMessageChain()).toString();
|
return Objects.requireNonNull(bot.getFriend(qq)).sendMessage(builder.asMessageChain());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return getNotLoginQQ();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sendMessage(File imageFile, String text) {
|
public MessageReceipt<?> sendMessage(File imageFile, String text) {
|
||||||
return sendMessage(imageFile, qqGroup, text);
|
return sendMessage(imageFile, qqGroup, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user