Skip to content

Commit 3eb5b9e

Browse files
committed
update watch command formatting and guild chat doing perm test
1 parent 19f103a commit 3eb5b9e

File tree

2 files changed

+52
-42
lines changed

2 files changed

+52
-42
lines changed

src/main/java/vc/commands/WatchCommand.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,8 @@ private Mono<Message> handleChatWatch(final ChatInputInteractionEvent event, fin
9898
return event.createFollowup()
9999
.withEmbeds(EmbedCreateSpec.builder()
100100
.color(Color.SEA_GREEN)
101-
.description("""
102-
Watch added!
103-
104-
You will be DM'd on chats containing `%s`
105-
""".formatted(keyword))
101+
.title("Chat Watch Added")
102+
.description("You will be DM'd on chats containing `%s`".formatted(keyword))
106103
.build());
107104
} else if (option.getOption("delete").isPresent()) {
108105
var deleteOption = option.getOption("delete").get();
@@ -119,12 +116,13 @@ private Mono<Message> handleChatWatch(final ChatInputInteractionEvent event, fin
119116
userChatWatchRepository.delete(watch);
120117
return event.createFollowup()
121118
.withEmbeds(EmbedCreateSpec.builder()
119+
.title("Chat Watch Deleted")
122120
.color(Color.SEA_GREEN)
123-
.description("Watch deleted!")
121+
.description("Chat watch `%s` deleted!".formatted(keyword))
124122
.build());
125123
}
126124
}
127-
return error(event, "No watch found for `" + keyword + "`");
125+
return error(event, "No chat watch found for `%s`".formatted(keyword));
128126
} else if (option.getOption("list").isPresent()) {
129127
var watches = userChatWatchRepository.getByOwnerId(event.getUser().getId().asString());
130128
Collections.sort(watches, (a, b) -> a.keyword().compareToIgnoreCase(b.keyword()));
@@ -148,7 +146,7 @@ private Mono<Message> handleChatWatch(final ChatInputInteractionEvent event, fin
148146
}
149147
return event.createFollowup()
150148
.withEmbeds(EmbedCreateSpec.builder()
151-
.title("Watch List")
149+
.title("Chat Watch List")
152150
.description(description)
153151
.color(Color.CYAN)
154152
.build());
@@ -159,8 +157,12 @@ private Mono<Message> handleChatWatch(final ChatInputInteractionEvent event, fin
159157
}
160158
return event.createFollowup()
161159
.withEmbeds(EmbedCreateSpec.builder()
162-
.title("All Watches Cleared")
163-
.description("Removed " + watches.size() + " watches.")
160+
.title("All Chat Watches Cleared")
161+
.description("Removed " + watches.size() + " watches.\n"
162+
+ watches.stream()
163+
.map(UserChatWatchConfig::keyword)
164+
.map("`%s`"::formatted)
165+
.reduce("", (a, b) -> a + "\n" + b))
164166
.color(Color.CYAN)
165167
.build());
166168
}
@@ -218,11 +220,8 @@ private Mono<Message> handlePlayerWatch(final ChatInputInteractionEvent event, f
218220
return event.createFollowup()
219221
.withEmbeds(populateIdentity(EmbedCreateSpec.builder(), profile)
220222
.color(Color.SEA_GREEN)
221-
.description("""
222-
Watch added!
223-
224-
You will be DM'd on watched events
225-
""")
223+
.title("Player Watch Added")
224+
.description("You will be DM'd on events for `%s`".formatted(profile.name()))
226225
.thumbnail(profile.getAvatarURL())
227226
.build());
228227
} else if (option.getOption("delete").isPresent()) {
@@ -246,13 +245,14 @@ private Mono<Message> handlePlayerWatch(final ChatInputInteractionEvent event, f
246245
userPlayerWatchRepository.delete(watch);
247246
return event.createFollowup()
248247
.withEmbeds(populateIdentity(EmbedCreateSpec.builder(), profile)
248+
.title("Player Watch Deleted")
249249
.color(Color.SEA_GREEN)
250-
.description("Watch deleted!")
250+
.description("Player watch for `%s` deleted!".formatted(profile.name()))
251251
.thumbnail(profile.getAvatarURL())
252252
.build());
253253
}
254254
}
255-
return error(event, "No watch found for " + profile.name() + " (" + profile.uuid() + ")");
255+
return error(event, "No player watch found for `%s` (%s)".formatted(profile.name(), profile.uuid()));
256256
} else if (option.getOption("list").isPresent()) {
257257
var watches = userPlayerWatchRepository.getByOwnerId(event.getUser().getId().asString());
258258
Collections.sort(watches, (a, b) -> a.targetName().compareToIgnoreCase(b.targetName()));
@@ -296,7 +296,7 @@ private Mono<Message> handlePlayerWatch(final ChatInputInteractionEvent event, f
296296
}
297297
return event.createFollowup()
298298
.withEmbeds(EmbedCreateSpec.builder()
299-
.title("Watch List")
299+
.title("Player Watch List")
300300
.description(description)
301301
.color(Color.CYAN)
302302
.build());
@@ -307,8 +307,12 @@ private Mono<Message> handlePlayerWatch(final ChatInputInteractionEvent event, f
307307
}
308308
return event.createFollowup()
309309
.withEmbeds(EmbedCreateSpec.builder()
310-
.title("All Watches Cleared")
311-
.description("Removed " + watches.size() + " watches.")
310+
.title("All Player Watches Cleared")
311+
.description("Removed " + watches.size() + " player watches.\n"
312+
+ watches.stream()
313+
.map(UserPlayerWatchConfig::targetName)
314+
.map("`%s`"::formatted)
315+
.reduce("", (a, b) -> a + "\n" + b))
312316
.color(Color.CYAN)
313317
.build());
314318
}
@@ -328,7 +332,7 @@ private ChatInteractionOptionContext resolveProfileSubOption(final ChatInteracti
328332
}
329333
Optional<ProfileData> playerIdentity = playerLookup.getPlayerIdentity(playerName);
330334
if (playerIdentity.isEmpty()) {
331-
ctx.setError("No player named `" + playerName + "` exists");
335+
ctx.setError("No player named `%s` exists".formatted(playerName));
332336
return ctx;
333337
}
334338
ctx.profileData = playerIdentity.get();

src/main/java/vc/commands/WatchGuildCommand.java

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ private Mono<Message> handleChatWatch(final ChatInputInteractionEvent event, fin
8686
return error(event, "Channel option is required to add a watch");
8787
}
8888
var channel = channelOption.get();
89+
if (!testPermissions(event.getInteraction().getGuildId().get().asString(), channel)) {
90+
return error(event, "Bot must have permissions to send messages in: " + channel.getMention());
91+
}
8992
String keyword = addOption.getOption("keyword")
9093
.flatMap(ApplicationCommandInteractionOption::getValue)
9194
.map(ApplicationCommandInteractionOptionValue::asString)
@@ -153,11 +156,8 @@ private Mono<Message> handleChatWatch(final ChatInputInteractionEvent event, fin
153156
return event.createFollowup()
154157
.withEmbeds(EmbedCreateSpec.builder()
155158
.color(Color.SEA_GREEN)
156-
.description("""
157-
Watch added!
158-
159-
Notifications on watched events will be sent to: %s
160-
""".formatted(channel.getMention()))
159+
.title("Chat Watch Added")
160+
.description("Notifications on chats containing `%s` will be sent to: %s".formatted(keyword, channel.getMention()))
161161
.build());
162162
} else if (option.getOption("delete").isPresent()) {
163163
var deleteOption = option.getOption("delete").get();
@@ -174,12 +174,13 @@ private Mono<Message> handleChatWatch(final ChatInputInteractionEvent event, fin
174174
guildChatWatchRepository.delete(watch);
175175
return event.createFollowup()
176176
.withEmbeds(EmbedCreateSpec.builder()
177+
.title("Chat Watch Deleted")
177178
.color(Color.SEA_GREEN)
178-
.description("Watch deleted!")
179+
.description("Chat Watch for `%s` deleted!".formatted(keyword))
179180
.build());
180181
}
181182
}
182-
return error(event, "No watch found for `" + keyword + "`");
183+
return error(event, "No chat watch found for `%s`".formatted(keyword));
183184
} else if (option.getOption("list").isPresent()) {
184185
var watches = guildChatWatchRepository.getByGuildId(event.getInteraction().getGuildId().get().asString());
185186
Collections.sort(watches, (a, b) -> {
@@ -207,7 +208,7 @@ private Mono<Message> handleChatWatch(final ChatInputInteractionEvent event, fin
207208
}
208209
return event.createFollowup()
209210
.withEmbeds(EmbedCreateSpec.builder()
210-
.title("Watch List")
211+
.title("Chat Watch List")
211212
.description(description)
212213
.color(Color.CYAN)
213214
.build());
@@ -218,8 +219,12 @@ private Mono<Message> handleChatWatch(final ChatInputInteractionEvent event, fin
218219
}
219220
return event.createFollowup()
220221
.withEmbeds(EmbedCreateSpec.builder()
221-
.title("All Watches Cleared")
222-
.description("Removed " + watches.size() + " watches.")
222+
.title("All Chat Watches Cleared")
223+
.description("Removed %d watches.\n".formatted(watches.size())
224+
+ watches.stream()
225+
.map(GuildChatWatchConfig::keyword)
226+
.map("`%s`"::formatted)
227+
.reduce("", (a, b) -> a + "\n" + b))
223228
.color(Color.CYAN)
224229
.build());
225230
}
@@ -325,11 +330,8 @@ private Mono<Message> handlePlayerWatch(final ChatInputInteractionEvent event, f
325330
return event.createFollowup()
326331
.withEmbeds(populateIdentity(EmbedCreateSpec.builder(), profile)
327332
.color(Color.SEA_GREEN)
328-
.description("""
329-
Watch added!
330-
331-
Notifications on watched events will be sent to: %s
332-
""".formatted(channel.getMention()))
333+
.title("Player Watch Added")
334+
.description("Notifications on watched events for `%s` will be sent to: %s".formatted(profile.name(), channel.getMention()))
333335
.thumbnail(profile.getAvatarURL())
334336
.build());
335337
} else if (option.getOption("delete").isPresent()) {
@@ -353,13 +355,14 @@ private Mono<Message> handlePlayerWatch(final ChatInputInteractionEvent event, f
353355
guildPlayerWatchRepository.delete(watch);
354356
return event.createFollowup()
355357
.withEmbeds(populateIdentity(EmbedCreateSpec.builder(), profile)
358+
.title("Player Watch Deleted")
356359
.color(Color.SEA_GREEN)
357-
.description("Watch deleted!")
360+
.description("Player watch for `%s` deleted!".formatted(profile.name()))
358361
.thumbnail(profile.getAvatarURL())
359362
.build());
360363
}
361364
}
362-
return error(event, "No watch found for " + profile.name() + " (" + profile.uuid() + ")");
365+
return error(event, "No player watch found for `%s` (%s)".formatted(profile.name(), profile.uuid()));
363366
} else if (option.getOption("list").isPresent()) {
364367
var watches = guildPlayerWatchRepository.getByGuildId(event.getInteraction().getGuildId().get().asString());
365368
Collections.sort(watches, (a, b) -> {
@@ -410,7 +413,7 @@ private Mono<Message> handlePlayerWatch(final ChatInputInteractionEvent event, f
410413
}
411414
return event.createFollowup()
412415
.withEmbeds(EmbedCreateSpec.builder()
413-
.title("Watch List")
416+
.title("Player Watch List")
414417
.description(description)
415418
.color(Color.CYAN)
416419
.build());
@@ -421,8 +424,11 @@ private Mono<Message> handlePlayerWatch(final ChatInputInteractionEvent event, f
421424
}
422425
return event.createFollowup()
423426
.withEmbeds(EmbedCreateSpec.builder()
424-
.title("All Watches Cleared")
425-
.description("Removed " + watches.size() + " watches.")
427+
.title("All Player Watches Cleared")
428+
.description("Removed %d watches.\n".formatted(watches.size())
429+
+ watches.stream()
430+
.map(GuildPlayerWatchConfig::targetName)
431+
.reduce("", (a, b) -> a + "\n" + b))
426432
.color(Color.CYAN)
427433
.build());
428434
}
@@ -442,7 +448,7 @@ private ChatInteractionOptionContext resolveProfileSubOption(final ChatInteracti
442448
}
443449
Optional<ProfileData> playerIdentity = playerLookup.getPlayerIdentity(playerName);
444450
if (playerIdentity.isEmpty()) {
445-
ctx.setError("No player named `" + playerName + "` exists");
451+
ctx.setError("No player named `%s` exists".formatted(playerName));
446452
return ctx;
447453
}
448454
ctx.profileData = playerIdentity.get();

0 commit comments

Comments
 (0)