Skip to content

Commit

Permalink
feat: applying new name to discord channel
Browse files Browse the repository at this point in the history
  • Loading branch information
yaansz committed Aug 11, 2024
1 parent c433d3d commit 72668d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
17 changes: 11 additions & 6 deletions src/main/java/com/softawii/capivara/core/DroneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion;
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
import net.dv8tion.jda.api.interactions.components.ActionRow;
Expand Down Expand Up @@ -563,17 +564,21 @@ public boolean isUserOwner(Member member, AudioChannelUnion channel) {
}
}

public void renameDrone(Member member, AudioChannelUnion channel) {
long snowflakeId = channel.getParentCategoryIdLong();

public void tryRenameDrone(Member member, AudioChannelUnion channel) {
try {
if(!isUserOwner(member, channel)) return; // not the owner or not a dynamic channel

// Checking if the current category is a dynamic category
VoiceDrone drone = voiceDroneService.find(snowflakeId);
String name = getDroneName(member, drone)
// getting drone hive settings
long parentCategoryIdLong = channel.getParentCategoryIdLong();
VoiceHive hive = voiceHiveService.find(parentCategoryIdLong);
String name = getDroneName(member, hive);

LOGGER.info("Renaming channel: {}, New: {}", channel.getIdLong(), name);

// TODO: Check if the name is different

// renaming the channel
channel.getManager().setName(name).queue();
} catch (KeyNotFoundException e) {
LOGGER.debug("Key not found, ignoring...");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,7 @@ public void onUserUpdateActivities(UserUpdateActivitiesEvent event) {
if(channel == null) return;

// 3. Rename the voice channel

if(droneManager.isUserOwner(member, channel)) {
// String name = droneManager.get
}
droneManager.tryRenameDrone(member, channel);
}

private void handleException(Exception exception, Event event) {
Expand Down

0 comments on commit 72668d4

Please sign in to comment.