Skip to content

Commit

Permalink
update group temp message and private send message error
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksgata committed Feb 1, 2024
1 parent d31b5fa commit 2e56ed9
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public interface DiceMessageEventHandler {
//需要考虑并发安全
void onGroupMessage(DiceMessageDTO event);

void onFriendMessage(DiceMessageDTO data);

//处理在处理事件中发生的未捕获异常
void handleException(@NotNull Throwable exception);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package com.github.eiriksgata.rulateday.platform.dice;

import com.alibaba.fastjson.JSONObject;
import com.github.eiriksgata.rulateday.platform.dice.config.GlobalData;
import com.github.eiriksgata.rulateday.platform.dice.dto.DiceMessageDTO;
import com.github.eiriksgata.rulateday.platform.dice.service.ApiReportService;
import com.github.eiriksgata.rulateday.platform.dice.service.BotControlService;
import com.github.eiriksgata.rulateday.platform.dice.service.ChatRecordService;
import com.github.eiriksgata.rulateday.platform.dice.service.UserConversationService;
import com.github.eiriksgata.rulateday.platform.mapper.DiceConfigMapper;
import com.github.eiriksgata.rulateday.platform.pojo.DiceConfigEntity;
import com.github.eiriksgata.rulateday.platform.utils.ExceptionUtils;
import com.github.eiriksgata.rulateday.platform.websocket.api.ShamrockService;
import com.github.eiriksgata.rulateday.platform.websocket.vo.shamrock.EventEnum;
import com.github.eiriksgata.trpg.dice.exception.DiceInstructException;
import com.github.eiriksgata.trpg.dice.exception.ExceptionEnum;
import com.github.eiriksgata.trpg.dice.message.handle.InstructHandle;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.exceptions.PersistenceException;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -24,6 +27,7 @@
import java.util.Objects;

@Component
@Slf4j
public class DiceMessageEventHandlerImpl implements DiceMessageEventHandler {

@Autowired
Expand Down Expand Up @@ -74,7 +78,8 @@ public void onFriendRequest(DiceMessageDTO diceMessageDTO) {
@Override
public void OnDiceMessage(DiceMessageDTO data) {

if (Objects.equals(data.getMessageEvent().getSub_type(), EventEnum.MessageSubType.FRIEND.getName())) {
if (Objects.equals(data.getMessageEvent().getSub_type(), EventEnum.MessageSubType.FRIEND.getName()) ||
Objects.equals(data.getMessageEvent().getSub_type(), EventEnum.MessageSubType.GROUP.getName())) {
onFriendMessage(data);
}

Expand All @@ -89,8 +94,10 @@ public void onGroupMessage(DiceMessageDTO event) {
groupMessageHandle(event);
}

@Override
public void onFriendMessage(DiceMessageDTO data) {
if (diceConfigMapper.selectById().getPrivate_chat() == 0) {
JSONObject diceConfigEntity = diceConfigMapper.selectOne();
if (diceConfigEntity.getInteger("private_chat") == 0) {
return;
}

Expand All @@ -113,10 +120,10 @@ public void onFriendMessage(DiceMessageDTO data) {
if (result != null) {
result.forEach((text) ->
shamrockService.sendPrivateMessage(
data.getSanderId(), text,
data.getSanderId(),
text,
data.getWsServerEndpoint()));
}

}

//处理在处理事件中发生的未捕获异常
Expand Down Expand Up @@ -219,7 +226,6 @@ public List<String> personalMessageEventHandler(DiceMessageDTO data) {
}

data.setBody(data.getBody().substring(prefix.length()));
data.setBody(data.getBody().toUpperCase());

try {
String returnText = (String) instructHandle.instructCheck(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.alibaba.fastjson.JSONObject;
import com.github.eiriksgata.rulateday.platform.dice.dto.GroupRecordDTO;
import com.github.eiriksgata.rulateday.platform.dice.utlis.HmacSHA256Util;
import com.github.eiriksgata.rulateday.platform.dice.utlis.OsUtils;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -14,27 +12,9 @@ public class GlobalData {

public static Map<String, Map<String, String>> documentContext;

public static String machineCode;

public static Map<String, Long> groupChatRecordEnableMap = new HashMap<>();
public static Map<String, GroupRecordDTO> groupChatRecordDataMap = new HashMap<>();

public static int randomPictureApiType = 6;

static {
try {
String result = "";
if (OsUtils.isLinux()) {
result = OsUtils.getIdentifierByLinux();
} else {
result = OsUtils.getIdentifierByWindows();
}
machineCode = HmacSHA256Util.hmacSHA256("rulateday-dice", result);
System.out.println("Rulateday-dice INFO: your device code:" + machineCode);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Rulateday-dice ERROR: your device code get fail!");
}
}
public static int randomPictureApiType = 1;

}
Original file line number Diff line number Diff line change
Expand Up @@ -207,23 +207,23 @@ public String quitGroupByMaster(DiceMessageDTO data) {
} else {
return CustomText.getText("bot.group.quit.id.error");
}
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.FRIEND.getName())) {
shamrockService.sendPrivateMessage(
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.NORMAL.getName())) {
shamrockService.sendGroupMessage(
data.getSanderId(),
data.getMessageEvent().getGroup_id(),
CustomText.getText("bot.group.quit.success", groupId),
data.getWsServerEndpoint()

);
shamrockService.quitGroup(groupId, data.getWsServerEndpoint());

} else {
shamrockService.sendGroupMessage(
shamrockService.sendPrivateMessage(
data.getSanderId(),
data.getMessageEvent().getGroup_id(),
CustomText.getText("bot.group.quit.success", groupId),
data.getWsServerEndpoint()

);
shamrockService.quitGroup(groupId, data.getWsServerEndpoint());

}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public String drawAdd(DiceMessageDTO data) {
}
String[] addDataArr = cardsTypeList.getContent().split(",");
Long groupId;
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.FRIEND.getName())) {
groupId = -data.getMessageEvent().getUser_id();
} else {
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.NORMAL.getName())) {
groupId = data.getMessageEvent().getGroup_id();
} else {
groupId = -data.getMessageEvent().getUser_id();
}

for (String anAddDataArr : addDataArr) {
Expand Down Expand Up @@ -130,22 +130,22 @@ public String drawList(DiceMessageDTO data) {
@InstructReflex(value = {"drawHide", "drawhide"}, priority = 3)
public String drawHideOut(DiceMessageDTO data) {
Long groupId;
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.FRIEND.getName())) {
groupId = -data.getSanderId();
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.NORMAL.getName())) {
groupId = data.getMessageEvent().getGroup_id();
CardsGroupData result = cardsGroupDataMapper.randomGetCard(groupId);
shamrockService.sendPrivateMessage(
shamrockService.sendGroupMessage(
data.getSanderId(),
data.getMessageEvent().getGroup_id(),
CustomText.getText(
"cards.draw.hide.group.result",
groupId, result.getValue()),
data.getWsServerEndpoint()
);
} else {
groupId = data.getMessageEvent().getGroup_id();
groupId = -data.getSanderId();
CardsGroupData result = cardsGroupDataMapper.randomGetCard(groupId);
shamrockService.sendGroupMessage(
shamrockService.sendPrivateMessage(
data.getSanderId(),
data.getMessageEvent().getGroup_id(),
CustomText.getText(
"cards.draw.hide.group.result",
groupId, result.getValue()),
Expand All @@ -163,10 +163,11 @@ public String drawHideOut(DiceMessageDTO data) {
@InstructReflex(value = {"draw"}, priority = 2)
public String drawOut(DiceMessageDTO data) {
Long groupId;
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.FRIEND.getName())) {
groupId = -data.getSanderId();
} else {
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.NORMAL.getName())) {
groupId = data.getMessageEvent().getGroup_id();
} else {
groupId = -data.getSanderId();

}

CardsGroupData result = cardsGroupDataMapper.randomGetCard(groupId);
Expand All @@ -180,10 +181,11 @@ public String drawOut(DiceMessageDTO data) {
@InstructReflex(value = {"drawclear", "drawClear"}, priority = 3)
public String drawClear(DiceMessageDTO data) {
Long groupId;
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.FRIEND.getName())) {
groupId = -data.getSanderId();
} else {
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.NORMAL.getName())) {
groupId = data.getMessageEvent().getGroup_id();
} else {
groupId = -data.getSanderId();

}
cardsGroupDataMapper.clearByGroupId(groupId);
return CustomText.getText("cards.draw.clear");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class InfiniteLibInstruct {

@InstructReflex(value = {"ir2"})
public String infiniteLibOnlineQuery(DiceMessageDTO data) {
if (diceConfigMapper.selectById().getBeta_version() == 0) {

if (diceConfigMapper.selectOne().getInteger("beta_version") == 0) {
return CustomText.getText("infinite.lib.ir2.no.enable");
}
//如果输入的数据是无关键字的
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public class InitiativeInstruct {
public String getAtkList(DiceMessageDTO data) {
String resultText;
String groupId;
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.FRIEND.getName())) {
groupId = "-" + data.getMessageEvent().getUser_id();
} else {
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.NORMAL.getName())) {
groupId = "" + data.getMessageEvent().getGroup_id();
} else {
groupId = "-" + data.getMessageEvent().getUser_id();
}
return initiativeService.showInitiativeList(groupId);
}
Expand All @@ -53,10 +53,11 @@ public String delAtk(DiceMessageDTO data) {
String finalTempName = tempName;

String groupId;
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.FRIEND.getName())) {
groupId = "-" + data.getMessageEvent().getUser_id();
} else {
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.NORMAL.getName())) {
groupId = "" + data.getMessageEvent().getGroup_id();
} else {
groupId = "-" + data.getMessageEvent().getUser_id();

}

String name = data.getMessageEvent().getSender().getNickname();
Expand All @@ -73,10 +74,11 @@ public String delAtk(DiceMessageDTO data) {
@InstructReflex(value = {"atkClear", "clearAtk", "atkclear", "AtkClear"}, priority = 2)
public String clearAtkList(DiceMessageDTO data) {
String groupId;
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.FRIEND.getName())) {
groupId = "-" + data.getMessageEvent().getUser_id();
} else {
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.NORMAL.getName())) {

groupId = "" + data.getMessageEvent().getGroup_id();
} else {
groupId = "-" + data.getMessageEvent().getUser_id();
}
initiativeService.clearGroupDice(groupId);
return CustomText.getText("initiative.clear");
Expand All @@ -90,10 +92,11 @@ public String generateInitiativeDice(DiceMessageDTO data) {
AtomicBoolean isLimit = new AtomicBoolean(false);

String groupId;
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.FRIEND.getName())) {
groupId = "-" + data.getMessageEvent().getUser_id();
} else {
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.NORMAL.getName())) {
groupId = "" + data.getMessageEvent().getGroup_id();
} else {
groupId = "-" + data.getMessageEvent().getUser_id();

}

isLimit.set(initiativeService.diceLimit(groupId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ public String roll(DiceMessageDTO data) {
for (int i = 0; i < repeatedlyValue; i++) {
if (data.getBody().equals("") || data.getBody().equals(" ") ||
data.getBody().equals("d") || data.getBody().equals("D")) {
resultText.append("\n").append(rollBasics.rollRandom("d", data.getSanderId()));
resultText.append(rollBasics.rollRandom("d", data.getSanderId()));
} else {
//正则筛选
String result = RegularExpressionUtils.getMatcher("(([0-9]{0,2}[dD]?[0-9]{0,5}[\\+\\-\\*\\/][0-9]{0,2}[dD]?[0-9]{0,5})+|[0-9]{0,2}[dD]?[0-9]{1,5})", data.getBody());
if (result != null) {
if (result.endsWith("+") || result.endsWith("-") || result.endsWith("*") || result.endsWith("/")) {
result = result.substring(0, result.length() - 1);
}
resultText.append("\n").append(rollBasics.rollRandom(result, data.getSanderId()));
resultText.append(rollBasics.rollRandom(result, data.getSanderId()));
} else {
return CustomText.getText("dice.base.parameter.error");
}
Expand Down Expand Up @@ -212,7 +212,7 @@ public String sanCheck(DiceMessageDTO data) {

@InstructReflex(value = {"rh"}, priority = 3)
public String rollHide(DiceMessageDTO data) {
if (diceConfigMapper.selectById().getPrivate_chat() == 0) {
if (diceConfigMapper.selectOne().getInteger("private_chat") == 0) {
return CustomText.getText("dice.roll.hide.private.chat.disable");
}
shamrockService.sendPrivateMessage(
Expand Down Expand Up @@ -432,16 +432,17 @@ public String dicePoolGen(DiceMessageDTO data) {
returnText.append("b").append(count);
for (int i = 1; i < repeat; i++) {
rollBasics.dicePoolCount(diceNumber, resultText, count, addDiceCheck, count, diceFace, successDiceCheck);
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.FRIEND.getName())) {
shamrockService.sendPrivateMessage(
data.getSanderId(),
CustomText.getText("dice.pool.result", returnText, resultText), data.getWsServerEndpoint());
} else {
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.NORMAL.getName())) {
shamrockService.sendGroupMessage(
data.getSanderId(),
data.getMessageEvent().getGroup_id(),
"[" + data.getMessageEvent().getSender().getNickname() + "]" +
CustomText.getText("dice.pool.result", returnText, resultText), data.getWsServerEndpoint());
} else {
shamrockService.sendPrivateMessage(
data.getSanderId(),
CustomText.getText("dice.pool.result", returnText, resultText), data.getWsServerEndpoint());

}
resultText.delete(0, resultText.length());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,20 @@ public void sendMMImage(DiceMessageDTO data, QueryDataBase result) {
String url = imagesUrl + mmNameFileName;
List<MessageContent> messageContentList = new ArrayList<>();
messageContentList.add(new MessageContent().setTypeByImages(url));
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.FRIEND.getName())) {
shamrockService.sendPrivateMessage(
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.NORMAL.getName())) {
shamrockService.sendGroupMessage(
data.getSanderId(),
data.getMessageEvent().getGroup_id(),
messageContentList,
data.getWsServerEndpoint()
);
} else {
shamrockService.sendGroupMessage(
shamrockService.sendPrivateMessage(
data.getSanderId(),
data.getMessageEvent().getGroup_id(),
messageContentList,
data.getWsServerEndpoint()
);

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ public String urlEncodeAPI(DiceMessageDTO data, String url) {
String serverUrl = address + "/resources/images/" + fileName;
messageContentList.add(new MessageContent().setTypeByImages(serverUrl));

if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.FRIEND.getName())) {
shamrockService.sendPrivateMessage(
if (data.getMessageEvent().getSub_type().equals(EventEnum.MessageSubType.NORMAL.getName())) {
shamrockService.sendGroupMessage(
data.getSanderId(),
data.getMessageEvent().getGroup_id(),
messageContentList,
data.getWsServerEndpoint()
);
} else {
shamrockService.sendGroupMessage(
shamrockService.sendPrivateMessage(
data.getSanderId(),
data.getMessageEvent().getGroup_id(),
messageContentList,
data.getWsServerEndpoint()
);
Expand Down
Loading

0 comments on commit 2e56ed9

Please sign in to comment.