增加大头菜对群的支持
Model新增识别群并@发送人的方法
This commit is contained in:
parent
8f19448239
commit
ba7b933bdb
@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class QQBotApplication {
|
||||
public static final String version="QQBot v.1.2.5";
|
||||
public static final String version="QQBot v.1.2.6";
|
||||
public static void main(String[] args) {
|
||||
System.out.println("version = " + version);
|
||||
SpringApplication.run(QQBotApplication.class, args);
|
||||
|
@ -54,29 +54,39 @@ public class TurnipProphet extends Model {
|
||||
};
|
||||
}
|
||||
|
||||
Long user, sendQQ;
|
||||
|
||||
@Override
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
user = qq;
|
||||
sendQQ = qq;
|
||||
if (isGroup) {
|
||||
return;
|
||||
if (!event.getMessage().serializeToMiraiCode().contains("[mirai:at:3620756944]")) {
|
||||
return;
|
||||
}
|
||||
user = event.getSource().getFromId();
|
||||
}
|
||||
int money = -1;
|
||||
try {
|
||||
if (isGroup) {
|
||||
msg = msg.replace("@3620756944", "");
|
||||
}
|
||||
money = Integer.parseInt(msg.trim());
|
||||
} catch (Exception e) {
|
||||
if (msg.equals(QQFromCommands.TURNIP_PROPHET)) {
|
||||
showData(event.getSource().getFromId());
|
||||
showData();
|
||||
}
|
||||
return;
|
||||
}
|
||||
setData(money, event.getSource().getFromId());
|
||||
setData(money);
|
||||
}
|
||||
|
||||
private void showData(long qq) {
|
||||
String redisKey = qq + "_turnip";
|
||||
private void showData() {
|
||||
String redisKey = user + "_turnip";
|
||||
String data = RedisTools.get(redisKey);
|
||||
if (StringUtils.isEmpty(data)) {
|
||||
QQBotManager.getInstance().sendMessage(qq, "没有本周数据,无法预测");
|
||||
QQBotManager.getInstance().sendMessage(sendQQ, getMessage("没有本周数据,无法预测"));
|
||||
return;
|
||||
}
|
||||
JSONObject json = JSONObject.parseObject(data);
|
||||
@ -99,16 +109,16 @@ public class TurnipProphet extends Model {
|
||||
Map<String, String> map = null;
|
||||
try {
|
||||
map = openTurnip(prices, pattern);
|
||||
sendQQ(map, prices, pattern, qq);
|
||||
sendQQ(map, prices, pattern);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
showData(qq);
|
||||
showData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setData(int money, long qq) {
|
||||
String redisKey = qq + "_turnip";
|
||||
private void setData(int money) {
|
||||
String redisKey = user + "_turnip";
|
||||
String data = RedisTools.get(redisKey);
|
||||
String pattern = null;
|
||||
JSONObject json;
|
||||
@ -137,7 +147,7 @@ public class TurnipProphet extends Model {
|
||||
array = json.getJSONArray("turnip");
|
||||
}
|
||||
if (array.getInteger(0) == -1 && getDay() != 0) {
|
||||
QQBotManager.getInstance().sendMessage(qq, "没有周日买入信息,本周不收录 :(");
|
||||
QQBotManager.getInstance().sendMessage(sendQQ, getMessage("没有周日买入信息,本周不收录 :("));
|
||||
return;
|
||||
}
|
||||
if (json.containsKey("old_pattern")) {
|
||||
@ -186,13 +196,13 @@ public class TurnipProphet extends Model {
|
||||
case "小幅上涨(四期型)" -> pattern = "3";
|
||||
}
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(qq, "已记录,正在预测本周走势...");
|
||||
QQBotManager.getInstance().sendMessage(sendQQ, getMessage("已记录,正在预测本周走势..."));
|
||||
|
||||
Map<String, String> map = openTurnip(prices, pattern);
|
||||
if (map == null) {
|
||||
map = openTurnip(prices, pattern);
|
||||
}
|
||||
String tmp_pattern = sendQQ(map, prices, pattern, qq);
|
||||
String tmp_pattern = sendQQ(map, prices, pattern);
|
||||
if (!StringUtils.isEmpty(tmp_pattern)) {
|
||||
json.put("pattern", tmp_pattern);
|
||||
}
|
||||
@ -200,19 +210,19 @@ public class TurnipProphet extends Model {
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
setData(money, qq);
|
||||
setData(money);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private String sendQQ(Map<String, String> map, String prices, String pattern, long qq) {
|
||||
private String sendQQ(Map<String, String> map, String prices, String pattern) {
|
||||
String url = String.format("https://turnipprophet.io?prices=%s%s",
|
||||
prices,
|
||||
pattern == null ? "" : "&pattern=" + pattern
|
||||
);
|
||||
if (map == null) {
|
||||
QQBotManager.getInstance().sendMessage(qq, "没有结果,请检查数据是否有误。 \n网页预览:\n" + url);
|
||||
QQBotManager.getInstance().sendMessage(sendQQ, getMessage("没有结果,请检查数据是否有误。 \n网页预览:\n" + url));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -223,8 +233,8 @@ public class TurnipProphet extends Model {
|
||||
out.append(TurnipData.MODEL).append(prArray.getJSONObject(0).getString(TurnipData.MODEL)).append("\n");
|
||||
out.append(TurnipData.PR).append(prArray.getJSONObject(0).getString(TurnipData.PR)).append("\n");
|
||||
out.append("购入价:").append(prices.split("\\.")[0]).append("\n");
|
||||
if(getDay()==0){
|
||||
out.append("满背包(4行)购入价:").append(4000*Integer.parseInt(prices.split("\\.")[0])).append("\n");
|
||||
if (getDay() == 0) {
|
||||
out.append("满背包(4行)购入价:").append(4000 * Integer.parseInt(prices.split("\\.")[0])).append("\n");
|
||||
}
|
||||
out.append(TurnipData.MIX).append(map.get(TurnipData.MIX)).append("\n")
|
||||
.append(TurnipData.MAX).append(map.get(TurnipData.MAX)).append("\n")
|
||||
@ -255,7 +265,7 @@ public class TurnipProphet extends Model {
|
||||
out.append("祝好运 :)");
|
||||
|
||||
Log.i("TurnipProphet", out.toString());
|
||||
QQBotManager.getInstance().sendMessage(qq, out.toString());
|
||||
QQBotManager.getInstance().sendMessage(sendQQ, getMessage(out.toString()));
|
||||
return prArray.getJSONObject(0).getString(TurnipData.MODEL);
|
||||
}
|
||||
|
||||
@ -278,7 +288,6 @@ public class TurnipProphet extends Model {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
TurnipProphet prophet = new TurnipProphet();
|
||||
prophet.setData(92, 583819556);
|
||||
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@ import com.yutou.qqbot.QQNumberManager;
|
||||
import com.yutou.qqbot.interfaces.ModelInterface;
|
||||
import net.mamoe.mirai.event.events.GroupMessageEvent;
|
||||
import net.mamoe.mirai.event.events.MessageEvent;
|
||||
import net.mamoe.mirai.message.data.At;
|
||||
import net.mamoe.mirai.message.data.MessageChainBuilder;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
@ -39,8 +41,8 @@ public abstract class Model implements ModelInterface {
|
||||
public static final String TSDM_PAY = "!tsdm";
|
||||
public static final String TSDM_SIGN = "!tsdm签到";
|
||||
public static final String BAIDU_DOWN = "!bd";
|
||||
public static final String ROUTER_ADD="!添加设备";
|
||||
public static final String ROUTER_DEL="!删除设备";
|
||||
public static final String ROUTER_ADD = "!添加设备";
|
||||
public static final String ROUTER_DEL = "!删除设备";
|
||||
}
|
||||
|
||||
|
||||
@ -56,11 +58,15 @@ public abstract class Model implements ModelInterface {
|
||||
|
||||
public String msg;
|
||||
protected boolean isGroupPower = false;
|
||||
private boolean isGroup;
|
||||
private Long user;
|
||||
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
msg = event.getMessage().contentToString();
|
||||
msg = msg.replace("!", "!");
|
||||
if(isGroup) {
|
||||
this.isGroup = isGroup;
|
||||
if (isGroup) {
|
||||
user=event.getSource().getFromId();
|
||||
GroupMessageEvent groupEvent = (GroupMessageEvent) event;
|
||||
group = groupEvent.getGroup().getId();
|
||||
if (QQNumberManager.getManager().isExistsPower(group, msg.split(" ")[0])) {
|
||||
@ -85,4 +91,13 @@ public abstract class Model implements ModelInterface {
|
||||
return builder;
|
||||
}
|
||||
|
||||
public MessageChainBuilder getMessage(String text) {
|
||||
MessageChainBuilder chain = new MessageChainBuilder();
|
||||
if (isGroup) {
|
||||
chain.add(new At(user));
|
||||
chain.add("\n");
|
||||
}
|
||||
chain.add(text);
|
||||
return chain;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user