Skip to content

Commit

Permalink
Update more exceptions return text (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksgata committed Jun 11, 2021
1 parent 0f36c7e commit ebc3fc2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ public void friend(FriendMessageEvent event) {

@InstructReflex(value = {".atk", "。atk"})
public String generateInitiativeDice(MessageData data) {


String name = null;
String[] tempList;
String diceFace = "d";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public String randomPicture(MessageData data) {
try {
resultJson = HttpRequest.get(url).body();
} catch (Exception e) {
return "请求服务器失败。请联系相关开发人员。";
return "请求云端服务器接口失败。请联系相关开发人员。";
}
ResponseBaseVo<String> response = new Gson().fromJson(
resultJson, new TypeToken<ResponseBaseVo<String>>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public String attributeCheck(MessageData data) {

@InstructReflex(value = {".st", "。st"})
public String setAttribute(MessageData data) {
if (data.getMessage().equals("")) {
return CustomText.getText("dice.set.attribute.error");
}
try {
userTempDataService.updateUserAttribute(data.getQqID(), data.getMessage());
} catch (Exception e) {
Expand All @@ -86,7 +89,6 @@ public String setAttribute(MessageData data) {
public String roll(MessageData data) {
Integer diceFace = userTempDataService.getUserDiceFace(data.getQqID());
data.setMessage(CharacterUtils.operationSymbolProcessing(data.getMessage()));

if (diceFace != null) {
diceSet.setDiceFace(data.getQqID(), diceFace);
}
Expand All @@ -106,8 +108,14 @@ public String roll(MessageData data) {
@InstructReflex(value = {".MessageData", ".set", "。set"})
public String setDiceFace(MessageData data) throws DiceInstructException {
//移除所有的空格
int setDiceFace = 0;
data.setMessage(data.getMessage().replaceAll(" ", ""));
int setDiceFace = Integer.valueOf(data.getMessage());
try {
setDiceFace = Integer.valueOf(data.getMessage());
} catch (Exception e) {
return CustomText.getText("dice.set.face.error");
}

if (setDiceFace > Integer.valueOf(DiceConfig.diceSet.getString("dice.face.max"))) {
throw new DiceInstructException(ExceptionEnum.DICE_SET_FACE_MAX_ERR);
}
Expand Down Expand Up @@ -192,22 +200,16 @@ public String rollBonusDice(MessageData data) {
@InstructReflex(value = {".rp", "。rp", ",rp", ".Rp"}, priority = 3)
public String rollPunishment(MessageData data) {
data.setMessage(data.getMessage().replaceAll(" ", ""));

data.setMessage(CharacterUtils.operationSymbolProcessing(data.getMessage()));
String attribute = userTempDataService.getUserAttribute(data.getQqID());


return rollBasics.rollBonus(data.getMessage(), attribute, false);
}

@InstructReflex(value = {".coc", "。coc", ".Coc"})
public String randomCocRole(MessageData data) {
int createNumber;
if (data.getMessage().equals("")) {
createNumber = 1;
} else {
createNumber = Integer.valueOf(data.getMessage());
}
createNumber = checkCreateRandomRoleNumber(data.getMessage());
if (createNumber == -1) return CustomText.getText("dice.base.parameter.error");
if (createNumber > 20 | createNumber < 1) {
return "参数范围需要在1-20内";
}
Expand All @@ -217,11 +219,8 @@ public String randomCocRole(MessageData data) {
@InstructReflex(value = {".dnd", "。dnd", ".Dnd", "。DND"})
public String randomDndRole(MessageData data) {
int createNumber;
if (data.getMessage().equals("")) {
createNumber = 1;
} else {
createNumber = Integer.valueOf(data.getMessage());
}
createNumber = checkCreateRandomRoleNumber(data.getMessage());
if (createNumber == -1) return CustomText.getText("dice.base.parameter.error");
if (createNumber > 20 | createNumber < 1) {
return "参数范围需要在1-20内";
}
Expand All @@ -237,7 +236,12 @@ public String todayRandom(MessageData data) {
@InstructReflex(value = {".name"})
public String randomName(MessageData data) {
if (StringUtils.isNumeric(data.getMessage())) {
int number = Integer.valueOf(data.getMessage());
int number = 0;
try {
number = Integer.valueOf(data.getMessage());
} catch (Exception e) {
return CustomText.getText("dice.base.parameter.error");
}
if (number > 0 && number <= 20) {
return humanNameService.randomName(Integer.valueOf(data.getMessage()));
}
Expand All @@ -247,5 +251,17 @@ public String randomName(MessageData data) {
}
}

private int checkCreateRandomRoleNumber(String message) {
if (message.equals("")) {
return 1;
} else {
try {
return Integer.valueOf(message);
} catch (Exception e) {
return -1;
}
}
}


}
5 changes: 4 additions & 1 deletion rulateday-server/src/main/resources/custom-text.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ dice.initiative.error=先攻指令出现错误。
dice.initiative.add=成功添加一个先攻骰:{0}
dice.initiative.delete=已经删除先攻骰:{0}

dice.base.parameter.error=指令中的参数不正确。


## dice default return text
dice.set.face.success=设置默认骰子面数为:{0}
dice.set.face.error=骰子面数设置的参数不正确。
dice.set.attribute.success=设置属性成功!
dice.set.attribute.error=设置属性失败!
dice.set.attribute.error=设置属性失败,参数不符合要求!
dice.attribute.error=指令格式错误。.st指令中不包含该属性,或者没有给定属性
dice.sc.instruct.error=sc指令参数不正确
dice.sc.not-found.error=找不到san属性
Expand Down

0 comments on commit ebc3fc2

Please sign in to comment.