Skip to content

Commit

Permalink
修复另外一些翻译文本问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed Jan 9, 2025
1 parent 62ff6c9 commit eb26641
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ private CheckResult checkPortRule(BtnRuleParsed rule, Torrent torrent, Peer peer
for (String category : rule.getPortRules().keySet()) {
RuleMatchResult matchResult = RuleParser.matchRule(rule.getPortRules().get(category), Integer.toString(peer.getPeerAddress().getPort()));
if (matchResult.hit()) {
return new CheckResult(getClass(), PeerAction.BAN, banDuration, new TranslationComponent(Lang.BTN_BTN_RULE, category, matchResult.rule().matcherIdentifier()), new TranslationComponent(Lang.MODULE_BTN_BAN, "Port", category, matchResult.rule().toString()));
return new CheckResult(getClass(), PeerAction.BAN, banDuration,
new TranslationComponent(Lang.BTN_BTN_RULE, category, matchResult.rule().matcherName()),
new TranslationComponent(Lang.MODULE_BTN_BAN, "Port", category, matchResult.rule().matcherName()));
}
}
return null;
Expand All @@ -346,7 +348,9 @@ private CheckResult checkPortRuleException(BtnExceptionRuleParsed rule, Torrent
for (String category : rule.getPortRules().keySet()) {
RuleMatchResult matchResult = RuleParser.matchRule(rule.getPortRules().get(category), Integer.toString(peer.getPeerAddress().getPort()));
if (matchResult.hit()) {
return new CheckResult(getClass(), PeerAction.SKIP, banDuration, new TranslationComponent(Lang.BTN_BTN_RULE, category, matchResult.rule().matcherIdentifier()), new TranslationComponent(Lang.MODULE_BTN_BAN, "Port", category, matchResult.rule().toString()));
return new CheckResult(getClass(), PeerAction.SKIP, banDuration,
new TranslationComponent(Lang.BTN_BTN_RULE, category, matchResult.rule().matcherName()),
new TranslationComponent(Lang.MODULE_BTN_BAN, "Port", category, matchResult.rule().matcherName()));
}
}
return null;
Expand All @@ -358,7 +362,9 @@ private CheckResult checkClientNameRule(BtnRuleParsed rule, Torrent torrent, Pee
List<Rule> rules = rule.getClientNameRules().get(category);
RuleMatchResult matchResult = RuleParser.matchRule(rules, peer.getClientName());
if (matchResult.hit()) {
return new CheckResult(getClass(), PeerAction.BAN, banDuration, new TranslationComponent(Lang.BTN_BTN_RULE, category, matchResult.rule().matcherIdentifier()), new TranslationComponent(Lang.MODULE_BTN_BAN, "ClientName", category, matchResult.rule().toString()));
return new CheckResult(getClass(), PeerAction.BAN, banDuration,
new TranslationComponent(Lang.BTN_BTN_RULE, category, matchResult.rule().matcherName()),
new TranslationComponent(Lang.MODULE_BTN_BAN, "ClientName", category, matchResult.rule().matcherName()));
}
}
return null;
Expand All @@ -370,7 +376,9 @@ private CheckResult checkClientNameRuleException(BtnExceptionRuleParsed rule, To
List<Rule> rules = rule.getClientNameRules().get(category);
RuleMatchResult matchResult = RuleParser.matchRule(rules, peer.getClientName());
if (matchResult.hit()) {
return new CheckResult(getClass(), PeerAction.SKIP, banDuration, new TranslationComponent(Lang.BTN_BTN_RULE, category, matchResult.rule().matcherIdentifier()), new TranslationComponent(Lang.MODULE_BTN_BAN, "ClientName", category, matchResult.rule().toString()));
return new CheckResult(getClass(), PeerAction.SKIP, banDuration,
new TranslationComponent(Lang.BTN_BTN_RULE, category, matchResult.rule().matcherName()),
new TranslationComponent(Lang.MODULE_BTN_BAN, "ClientName", category, matchResult.rule().matcherName()));
}
}
return null;
Expand All @@ -382,7 +390,9 @@ private CheckResult checkPeerIdRule(BtnRuleParsed rule, Torrent torrent, Peer pe
List<Rule> rules = rule.getPeerIdRules().get(category);
RuleMatchResult matchResult = RuleParser.matchRule(rules, peer.getPeerId());
if (matchResult.hit()) {
return new CheckResult(getClass(), PeerAction.BAN, banDuration, new TranslationComponent(Lang.BTN_BTN_RULE, category, matchResult.rule().matcherIdentifier()), new TranslationComponent(Lang.MODULE_BTN_BAN, "PeerId", category, matchResult.rule().toString()));
return new CheckResult(getClass(), PeerAction.BAN, banDuration,
new TranslationComponent(Lang.BTN_BTN_RULE, category, matchResult.rule().matcherName()),
new TranslationComponent(Lang.MODULE_BTN_BAN, "PeerId", category, matchResult.rule().matcherName()));
}
}
return null;
Expand All @@ -394,7 +404,9 @@ private CheckResult checkPeerIdRuleException(BtnExceptionRuleParsed rule, Torren
List<Rule> rules = rule.getPeerIdRules().get(category);
RuleMatchResult matchResult = RuleParser.matchRule(rules, peer.getPeerId());
if (matchResult.hit()) {
return new CheckResult(getClass(), PeerAction.SKIP, banDuration, new TranslationComponent(Lang.BTN_BTN_RULE, category, matchResult.rule().matcherIdentifier()), new TranslationComponent(Lang.MODULE_BTN_BAN, "PeerId", category, matchResult.rule().toString()));
return new CheckResult(getClass(), PeerAction.SKIP, banDuration,
new TranslationComponent(Lang.BTN_BTN_RULE, category, matchResult.rule().matcherName()),
new TranslationComponent(Lang.MODULE_BTN_BAN, "PeerId", category, matchResult.rule().matcherName()));
}
}
return null;
Expand All @@ -411,7 +423,9 @@ private CheckResult checkIpRule(BtnRuleParsed rule, @NotNull Torrent torrent, @N
var ipMatcher = rule.getIpRules().get(category);
MatchResult matchResult = ipMatcher.match(pa.toString());
if (matchResult.result() == MatchResultEnum.TRUE) {
return new CheckResult(getClass(), PeerAction.BAN, banDuration, new TranslationComponent(Lang.BTN_BTN_RULE, category, category), new TranslationComponent(Lang.MODULE_BTN_BAN, "IP", category, pa.toString()));
return new CheckResult(getClass(), PeerAction.BAN, banDuration,
new TranslationComponent(Lang.BTN_BTN_RULE, category, category),
new TranslationComponent(Lang.MODULE_BTN_BAN, "IP", category, pa.toString()));
}
}
return null;
Expand All @@ -427,7 +441,9 @@ private CheckResult checkIpRuleException(BtnExceptionRuleParsed rule, @NotNull T
for (String category : rule.getIpRules().keySet()) {
RuleMatchResult matchResult = RuleParser.matchRule(rule.getIpRules().get(category), pa.toString());
if (matchResult.hit()) {
return new CheckResult(getClass(), PeerAction.SKIP, banDuration, new TranslationComponent(Lang.BTN_BTN_RULE, category, matchResult.rule().matcherIdentifier()), new TranslationComponent(Lang.MODULE_BTN_BAN, "IP", category, pa.toString()));
return new CheckResult(getClass(), PeerAction.SKIP, banDuration,
new TranslationComponent(Lang.BTN_BTN_RULE, category, matchResult.rule().matcherIdentifier()),
new TranslationComponent(Lang.MODULE_BTN_BAN, "IP", category, pa.toString()));
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public void reloadConfig() {
if (ptr.isPresent()) {
RuleMatchResult matchResult = RuleParser.matchRule(ptrRules, ptr.get());
if (matchResult.hit()) {
return new CheckResult(getClass(), PeerAction.BAN, banDuration, new TranslationComponent(matchResult.rule().toString()),
new TranslationComponent(Lang.MODULE_PTR_MATCH_PTR_RULE, matchResult.rule().toString()));
return new CheckResult(getClass(), PeerAction.BAN, banDuration, matchResult.rule().matcherName(),
new TranslationComponent(Lang.MODULE_PTR_MATCH_PTR_RULE, matchResult.rule().matcherName()));
}
}
return pass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static RuleMatchResult matchRule(List<Rule> rules, String content) {
return new RuleMatchResult(false, rule, result.comment());
}
if (result.result() == MatchResultEnum.TRUE) { // 其次,可被覆盖
matchResult = new RuleMatchResult(true, rule,result.comment());
matchResult = new RuleMatchResult(true, rule, result.comment());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public StringContainsMatcher(JsonObject syntax) {

@Override
public TranslationComponent matcherName() {
return nameComponent;
return new TranslationComponent(Lang.MATCH_STRING_CONTAINS, rule);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public StringEndsWithMatcher(JsonObject syntax) {

@Override
public TranslationComponent matcherName() {
return nameComponent;
return new TranslationComponent(Lang.MATCH_STRING_ENDS_WITH, rule);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public StringEqualsMatcher(JsonObject syntax) {

@Override
public TranslationComponent matcherName() {
return nameComponent;
return new TranslationComponent(Lang.MATCH_STRING_EQUALS, rule);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public StringLengthMatcher(JsonObject syntax) {

@Override
public TranslationComponent matcherName() {
return nameComponent;
return new TranslationComponent(Lang.MATCH_STRING_LENGTH, "Min-" + min + ", Max-" + max);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String matcherIdentifier() {

@Override
public TranslationComponent matcherName() {
return nameComponent;
return new TranslationComponent(Lang.MATCH_STRING_REGEX, rule);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,20 @@ public String matcherIdentifier() {

@Override
public TranslationComponent matcherName() {
return nameComponent;
return new TranslationComponent(Lang.MATCH_STRING_STARTS_WITH, rule);
}

@Override
public String metadata() {
return rule;
}

@Override
public String toString() {
return "StringStartsWithMatcher{" +
"rule='" + rule + '\'' +
", hit=" + hit +
", miss=" + miss +
'}';
}
}

0 comments on commit eb26641

Please sign in to comment.