Skip to content

Commit

Permalink
feat: adding digdin!
Browse files Browse the repository at this point in the history
  • Loading branch information
yaansz committed Oct 25, 2023
1 parent ab9088d commit c0a9fbc
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/main/java/com/softawii/capivara/core/DroneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Component
public class DroneManager {
Expand Down Expand Up @@ -305,7 +307,7 @@ private void createControlPanel(VoiceChannel voiceChannel, GuildMessageChannel t
builder.setTitle("⚙️ Control Panel - " + voiceChannel.getName());
builder.setDescription("Here, you can control your private voiceChannel.");
// Fields to Show
builder.addField("Owner", voiceChannel.getGuild().getMemberById(drone.getOwnerId()).getAsMention(), true);
builder.addField("Owner", voiceChannel.getGuild().getMemberById(drone.getOwnerId()).getNickname(), true);
builder.addField("User Limit", voiceChannel.getUserLimit() == 0 ? "No Limits" : String.valueOf(voiceChannel.getUserLimit()), true);
builder.addField("Visible", isVisible(voiceChannel) ? "Yes" : "No", true);
builder.addField("Connectable", canConnect(voiceChannel) ? "Yes" : "No", true);
Expand Down Expand Up @@ -341,7 +343,7 @@ private void sendControlPanel(GuildMessageChannel channel, VoiceDrone drone, Emb
// We already have a message, so we need to update it
if (drone.getControlPanel() != null) {
Member owner = channel.getGuild().getMemberById(drone.getOwnerId());
channel.editMessageById(drone.getControlPanel(), owner != null ? owner.getAsMention() : "Hello!")
channel.editMessageById(drone.getControlPanel(), "Hello!")
.setEmbeds(builder.build())
.setActionRows(actionRows)
.queue(q -> { /* It's ok! */}, e -> {
Expand All @@ -356,7 +358,7 @@ private void sendControlPanel(GuildMessageChannel channel, VoiceDrone drone, Emb

private void sendNewControlPanel(GuildMessageChannel channel, VoiceDrone drone, EmbedBuilder builder, List<ActionRow> actionRows) {
Member owner = channel.getGuild().getMemberById(drone.getOwnerId());
channel.sendMessage(owner != null ? owner.getAsMention() : "Hello!").setEmbeds(builder.build()).setActionRows(actionRows).queue(q -> {
channel.sendMessage("Hello!").setEmbeds(builder.build()).setActionRows(actionRows).queue(q -> {
drone.setControlPanel(q.getIdLong());
try {
voiceDroneService.update(drone);
Expand All @@ -376,6 +378,18 @@ public void makePermanent(VoiceChannel channel, boolean permanent) throws KeyNot
private String getDroneName(Member member, VoiceHive hive) {
String droneName = VoiceManager.configModal_idle;
String username = member.getNickname() == null ? member.getEffectiveName() : member.getNickname();
String digdin = "";

if(member.getNickname() != null) {
Pattern diginRegex = Pattern.compile("Digdin\\.");
Pattern menteRegex = Pattern.compile("\\b\\w+mente\\b");

Matcher menteMatcher = menteRegex.matcher(username);

if(diginRegex.matcher(username).find() && menteMatcher.find()) {
digdin = menteMatcher.group();
}
}

Optional<Activity> streaming = member.getActivities().stream().filter(activity -> activity.getType() == Activity.ActivityType.STREAMING).findFirst();
Optional<Activity> playing = member.getActivities().stream().filter(activity -> activity.getType() == Activity.ActivityType.PLAYING).findFirst();
Expand All @@ -392,6 +406,7 @@ private String getDroneName(Member member, VoiceHive hive) {
}

droneName = droneName.replaceAll("%OWNER%", username);
droneName = droneName.replaceAll("%DIGDIN%", digdin);

return droneName;
}
Expand Down

0 comments on commit c0a9fbc

Please sign in to comment.