|
2 | 2 |
|
3 | 3 | import lombok.RequiredArgsConstructor; |
4 | 4 | import lombok.extern.slf4j.Slf4j; |
5 | | -import net.dv8tion.jda.api.entities.*; |
| 5 | +import net.dv8tion.jda.api.entities.Message; |
| 6 | +import net.dv8tion.jda.api.entities.Webhook; |
6 | 7 | import net.dv8tion.jda.api.entities.channel.ChannelType; |
7 | 8 | import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; |
8 | 9 | import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildChannel; |
@@ -34,12 +35,25 @@ private static String processFuck(String str) { |
34 | 35 | String suffix = Objects.requireNonNullElse(matchResult.group(2), ""); |
35 | 36 | String processedSuffix = switch(suffix.toLowerCase()) { |
36 | 37 | case "er", "ing" -> copyCase(suffix, 0, 'g') + suffix; |
37 | | - default -> suffix.startsWith("k") ? "g".repeat(suffix.length()) : ""; |
| 38 | + default -> suffix.toLowerCase().startsWith("k") ? copyCase(suffix, "g".repeat(suffix.length())) : ""; |
38 | 39 | }; |
39 | 40 | return processHug(theFuck) + processedSuffix; |
40 | 41 | }); |
41 | 42 | } |
42 | 43 |
|
| 44 | + private static String copyCase(String source, String toChange) { |
| 45 | + if (source.length() != toChange.length()) throw new IllegalArgumentException("lengths differ"); |
| 46 | + StringBuilder sb = new StringBuilder(); |
| 47 | + for (int i = 0; i < source.length(); i++) { |
| 48 | + char a = source.charAt(i); |
| 49 | + char b = toChange.charAt(i); |
| 50 | + if (Character.isUpperCase(a)) b = Character.toUpperCase(b); |
| 51 | + else b = Character.toLowerCase(b); |
| 52 | + sb.append(b); |
| 53 | + } |
| 54 | + return sb.toString(); |
| 55 | + } |
| 56 | + |
43 | 57 | @Override |
44 | 58 | public void onMessageReceived(@Nonnull MessageReceivedEvent event) { |
45 | 59 | if (!event.isFromGuild()) { |
|
0 commit comments