Skip to content

Commit

Permalink
fix: At silently fails when a player is not in the group
Browse files Browse the repository at this point in the history
  • Loading branch information
xslingcn committed May 11, 2022
1 parent 3622a8c commit 7745eb8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
6 changes: 4 additions & 2 deletions bungee/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ commandHelp=&7&o/phenyl help&3 - Show help message.
commandHelpPlayer=&7&o/phenyl bind &7[YOUR_QQ_ID]&3 - Request to bind your Minecraft id to QQ account.\n\
&7&o/phenyl verify &7[VERIFICATION_CODE]&3 - Verify the binding request from QQ.\n\
&7&o/phenyl say &7[MESSAGE]&3 - Send message to QQ if Phenyl is on command mode.\n\
&7&o/phenyl nomessage &3 - Whether to stop message forwarding to your client.
commandHelpAdmin=&7&o/phenyl mute &7[MINECRAFT_ID]&3 - Mute someone so that their messages will not be forwarded to QQ.\n\
&7&o/phenyl nomessage &3 - Whether to stop message forwarding to your client.\n\
&7&o/phenyl at &7[USERNAME]&3 - @ the specified player in QQ group.
commandHelpAdmin=&7&o/phenyl mute &7[USERNAME]&3 - Mute someone so that their messages will not be forwarded to QQ.\n\
&7&o/phenyl slider &7[ticket]&3 - Submit ticket for slider captcha.\n\
&7&o/phenyl reload&3 - Reload Phenyl.\n\
&7&o/phenyl login&3 - Login to QQ.\n\
Expand Down Expand Up @@ -47,6 +48,7 @@ invalidQQID=&4Invalid QQ ID.
notBoundYet=You haven't bound your username
boundPlayerNotFound=Player record not found
atSent=&3Successfully sent &7&o@{1} &3in &7&o{0}
playerNotFoundInGroup=&4Player &7&o@{1} &4not found in &7&o{0}&3
completeBindInGame=Perform following command in game to confirm
completeBindInGroup=&3Send following command in QQ group to confirm
clickToCopy=Click to copy
Expand Down
6 changes: 4 additions & 2 deletions bungee/src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ commandHelp=&7&o/phenyl help&3 - Show help message.
commandHelpPlayer=&7&o/phenyl bind &7[YOUR_QQ_ID]&3 - Request to bind your Minecraft id to QQ account.\n\
&7&o/phenyl verify &7[VERIFICATION_CODE]&3 - Verify the binding request from QQ.\n\
&7&o/phenyl say &7[MESSAGE]&3 - Send message to QQ if Phenyl is on command mode.\n\
&7&o/phenyl nomessage &3 - Whether to stop message forwarding to your client.
commandHelpAdmin=&7&o/phenyl mute &7[MINECRAFT_ID]&3 - Mute someone so that their messages will not be forwarded to QQ.\n\
&7&o/phenyl nomessage &3 - Whether to stop message forwarding to your client.\n\
&7&o/phenyl at &7[USERNAME]&3 - @ the specified player in QQ group.
commandHelpAdmin=&7&o/phenyl mute &7[USERNAME]&3 - Mute someone so that their messages will not be forwarded to QQ.\n\
&7&o/phenyl slider &7[ticket]&3 - Submit ticket for slider captcha.\n\
&7&o/phenyl reload&3 - Reload Phenyl.\n\
&7&o/phenyl login&3 - Login to QQ.\n\
Expand Down Expand Up @@ -47,6 +48,7 @@ invalidQQID=&4Invalid QQ ID.
notBoundYet=You haven't bound your username
boundPlayerNotFound=Player record not found
atSent=&3Successfully sent &7&o@{1} &3in &7&o{0}
playerNotFoundInGroup=&4Player &7&o@{1} &4not found in &7&o{0}&3
completeBindInGame=Perform following command in game to confirm
completeBindInGroup=&3Send following command in QQ group to confirm
clickToCopy=Click to copy
Expand Down
6 changes: 4 additions & 2 deletions bungee/src/main/resources/messages_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ commandHelp=&7&o/phenyl help&3 - 显示帮助信息。
commandHelpPlayer=&7&o/phenyl bind &7<QQ号>&3 - 进行QQ绑定。\n\
&7&o/phenyl verify &7<验证码>&3 - 对从QQ发起的绑定请求进行验证。\n\
&7&o/phenyl say &7<消息>&3 - 如果Phenyl处于Command模式,你需要使用此指令来将消息发送到QQ。\n\
&7&o/phenyl nomessage &3 - 是否启用消息转发。
commandHelpAdmin=&7&o/phenyl mute &7<MINECRAFT_ID>&3 - 禁言某人,则他的游戏内消息不会被转发到QQ。\n\
&7&o/phenyl nomessage &3 - 是否启用消息转发。\n\
&7&o/phenyl at &7<用户名>&3 - 在QQ群中@指定的玩家。
commandHelpAdmin=&7&o/phenyl mute &7<用户名>&3 - 禁言某人,则他的游戏内消息不会被转发到QQ。\n\
&7&o/phenyl slider &7<TICKET>&3 - 提交滑动验证Ticket。\n\
&7&o/phenyl reload&3 - 重新加载Phenyl。\n\
&7&o/phenyl login&3 - 登录QQ账号。\n\
Expand Down Expand Up @@ -47,6 +48,7 @@ invalidQQID=&4QQ号无效
notBoundYet=您尚未绑定
boundPlayerNotFound=未查询到玩家绑定信息
atSent=&3已在&7&o{0}&3中&7&o@{1}
playerNotFoundInGroup=&4群&7&o{0}&4中不存在玩家&7&o@{1}
completeBindInGame=请在游戏内输入以下指令完成绑定
completeBindInGroup=&3请在QQ群输入以下指令完成绑定
clickToCopy=点击复制
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,22 @@ private void at() throws IllegalArgumentException {
if (playerList.stream().noneMatch(player -> player.mcname().equals(args[1])))
throw new IllegalArgumentException(i18n("boundPlayerNotFound"));
Player targetPlayer = playerList.stream().filter(player -> player.mcname().equals(args[1])).findFirst().get();
String formatText = Config.server_to_qq_format.equals("image") ? "%username%:%message%" : Config.server_to_qq_format;
// get the pattern before and after %message%
String[] format = Config.server_to_qq_format
String[] format = formatText
.replace("%sub_server%", new MessageUtils(phenyl).getServerName(sender.getServerName()))
.replace("%username%", sender.getUsername())
.split("%message%");
for (Long id : Config.enabled_groups) {
Group group;
try {
group = phenyl.getMirai().getBot().getGroupOrFail(id);
} catch (NoSuchElementException e) {
LOGGER.error(i18n("noSuchGroup", String.valueOf(id)));
if (Config.debug) e.printStackTrace();
continue;
}
try {
Group group = phenyl.getMirai().getBot().getGroupOrFail(id);
Member target = group.getOrFail(targetPlayer.qqid());
MessageChain message = new MessageChainBuilder()
.append(format[0])
Expand All @@ -270,7 +278,8 @@ private void at() throws IllegalArgumentException {
.build();
phenyl.getMessenger().sendGroup(group, message);
phenyl.getMessenger().sendPlayer(i18n("atSent", group.getName(), target.getNameCard().isEmpty() ? target.getNick() : target.getNameCard()), sender);
} catch (NoSuchElementException ignored) {
} catch (NoSuchElementException e) {
phenyl.getMessenger().sendPlayer(i18n("playerNotFoundInGroup", group.getName(), targetPlayer.mcname()), sender);
}
}
}
Expand Down

0 comments on commit 7745eb8

Please # to comment.