Skip to content

Commit

Permalink
Fixed autotagging nuking old tags
Browse files Browse the repository at this point in the history
  • Loading branch information
htmlcsjs committed May 3, 2024
1 parent 606c398 commit 01e1f55
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import discord4j.core.object.reaction.ReactionEmoji;
import discord4j.core.spec.MessageCreateFields;
import discord4j.core.spec.MessageCreateMono;
import discord4j.discordjson.Id;
import discord4j.discordjson.json.EmojiData;
import discord4j.rest.route.Routes;
import discord4j.rest.util.AllowedMentions;
Expand Down Expand Up @@ -146,9 +147,13 @@ public static Mono<Object> threadCreate(ThreadChannelCreateEvent event) {
Snowflake parentId = thread.getParentId().orElse(null);
if (parentId != null && parentId.equals(Snowflake.of(FloppaTomlConfig.autoTagChannel))) {
// i love APIs
CoffeeFloppa.client.getChannelService();
List<Id> tags = new ArrayList<>();
if (!thread.getData().appliedTags().isAbsent()) {
tags.addAll(thread.getData().appliedTags().get());
}
tags.add(Id.of(FloppaTomlConfig.autoTagId));
return Routes.CHANNEL_MODIFY_PARTIAL.newRequest(thread.getId().asLong())
.body(new AddTagEditRequest(FloppaTomlConfig.autoTagId))
.body(new AddTagEditRequest(tags))
.optionalHeader("X-Audit-Log-Reason", "Floppa Automated")
.exchange(CoffeeFloppa.client.getRestResources().getRouter())
.bodyToMono(Object.class);
Expand Down Expand Up @@ -275,10 +280,10 @@ public static String getCurrentMessageURL() {

private static class AddTagEditRequest {
@JsonProperty("applied_tags")
private final List<Long> appliedTags;
private final List<Id> appliedTags;

protected AddTagEditRequest(Long... tags) {
this.appliedTags = List.of(tags);
protected AddTagEditRequest(List<Id> tags) {
this.appliedTags = tags;
}
}
}

0 comments on commit 01e1f55

Please sign in to comment.