Skip to content

Commit

Permalink
fix: setup spring components and set static fields
Browse files Browse the repository at this point in the history
  • Loading branch information
FerroEduardo committed Oct 26, 2023
1 parent e2e8366 commit 8eab2c0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
19 changes: 4 additions & 15 deletions src/main/java/com/softawii/capivara/Main.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package com.softawii.capivara;

import com.softawii.capivara.core.DroneManager;
import com.softawii.capivara.core.EmbedManager;
import com.softawii.capivara.core.VoiceManager;
import com.softawii.capivara.listeners.EchoGroup;
import com.softawii.capivara.listeners.VoiceGroup.Dynamic;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Activity;
import org.apache.logging.log4j.LogManager;
Expand All @@ -17,19 +12,13 @@
@SpringBootApplication
public class Main {

private static final Logger LOGGER = LogManager.getLogger(Main.class);
public static ConfigurableApplicationContext context;
private static final Logger LOGGER = LogManager.getLogger(Main.class);

public static void main(String[] args) {
context = SpringApplication.run(Main.class, args);
JDA jda = context.getBean(JDA.class);
BuildProperties buildProperties = context.getBean(BuildProperties.class);
ConfigurableApplicationContext context = SpringApplication.run(Main.class, args);
JDA jda = context.getBean(JDA.class);
BuildProperties buildProperties = context.getBean(BuildProperties.class);
jda.getPresence().setPresence(Activity.of(Activity.ActivityType.PLAYING, buildProperties.getVersion()), true);
LOGGER.info(buildProperties.getVersion() + " Bot is ready as " + jda.getSelfUser().getName());

// Beans
EchoGroup.embedManager = context.getBean(EmbedManager.class);
Dynamic.voiceManager = context.getBean(VoiceManager.class);
Dynamic.droneManager = context.getBean(DroneManager.class);
}
}
5 changes: 1 addition & 4 deletions src/main/java/com/softawii/capivara/core/DroneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class DroneManager {
private final Logger LOGGER = LogManager.getLogger(VoiceManager.class);
private final VoiceDroneService voiceDroneService;
private final VoiceHiveService voiceHiveService;
private final VoiceManager voiceManager;

private final String renameDrone = "drone-manager-rename";
private final String limitDrone = "drone-manager-limit";
Expand All @@ -54,11 +53,9 @@ public class DroneManager {

private final Pattern digdinRegex;


public DroneManager(VoiceDroneService voiceDroneService, VoiceHiveService voiceHiveService, VoiceManager voiceManager) {
public DroneManager(VoiceDroneService voiceDroneService, VoiceHiveService voiceHiveService) {
this.voiceDroneService = voiceDroneService;
this.voiceHiveService = voiceHiveService;
this.voiceManager = voiceManager;
this.digdinRegex = Pattern.compile("(?<nome>\\w+mente).+(Digdin)");
}

Expand Down
22 changes: 15 additions & 7 deletions src/main/java/com/softawii/capivara/listeners/EchoGroup.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.softawii.capivara.listeners;


import com.softawii.capivara.Main;
import com.softawii.capivara.core.EmbedManager;
import com.softawii.capivara.exceptions.FieldLengthException;
import com.softawii.capivara.exceptions.KeyNotFoundException;
Expand Down Expand Up @@ -30,13 +29,16 @@
import net.dv8tion.jda.api.requests.restaction.MessageCreateAction;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@IGroup(name = "echo", description = "Echo Group")
@Component
public class EchoGroup {

public static final String buttonEditMessage = "echo-edit-message";
Expand Down Expand Up @@ -68,7 +70,18 @@ public class EchoGroup {
//endregion
private static final Logger LOGGER = LogManager.getLogger(EchoGroup.class);

public static EmbedManager embedManager;
private static EmbedManager embedManager;
private static Curupira curupira;

@Autowired
public void setCurupira(Curupira curupira) {
EchoGroup.curupira = curupira;
}

@Autowired
public void setEmbedManager(EmbedManager embedManager) {
EchoGroup.embedManager = embedManager;
}

@ICommand(name = "echo",
description = "Quer enviar uma mensagem para o canal como se fosse o bot? Um anúncio? Pode me usar!",
Expand Down Expand Up @@ -182,7 +195,6 @@ public static void title(ButtonInteractionEvent event) {
}

// Generating Embed Model
Curupira curupira = Main.context.getBean(Curupira.class);
Modal.Builder modal = curupira.getModal(modalTitle);
modal.setId(modal.getId() + ":" + id);

Expand Down Expand Up @@ -247,7 +259,6 @@ public static void image(ButtonInteractionEvent event) {
}

// Generating Embed Model
Curupira curupira = Main.context.getBean(Curupira.class);
Modal.Builder modal = curupira.getModal(modalImage);
modal.setId(modal.getId() + ":" + id);

Expand Down Expand Up @@ -304,7 +315,6 @@ public static void newField(ButtonInteractionEvent event) {
}

// Generating Embed Model
Curupira curupira = Main.context.getBean(Curupira.class);
Modal.Builder modal = curupira.getModal(modalNewField);
modal.setId(modal.getId() + ":" + id);

Expand Down Expand Up @@ -386,7 +396,6 @@ public static void editFieldMenu(StringSelectInteractionEvent event) {
return;
}

Curupira curupira = Main.context.getBean(Curupira.class);
Modal.Builder modal = curupira.getModal(modalEditField);
modal.setId(modal.getId() + ":" + id + ":" + index);

Expand Down Expand Up @@ -481,7 +490,6 @@ public static void removeFieldMenu(StringSelectInteractionEvent event) {
@IButton(id = buttonEditMessage)
public static void editMessage(ButtonInteractionEvent event) {
String id = event.getComponentId().split(":")[1];
Curupira curupira = Main.context.getBean(Curupira.class);
Modal.Builder builder = curupira.getModal(modalEditMessage).setId(modalEditMessage + ":" + id);
event.replyModal(builder.build()).queue();
}
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/com/softawii/capivara/listeners/VoiceGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.awt.*;
import java.util.Collections;
Expand Down Expand Up @@ -139,6 +141,7 @@ public static void permanent(SlashCommandInteractionEvent event) {
}

@ISubGroup(name = "Dynamic", description = "Dynamic")
@Component
public static class Dynamic extends ListenerAdapter {

public static final long inviteDeadline = 1000L * 10L * 60L; // 600000 ms = 10 minutes
Expand All @@ -150,8 +153,18 @@ public static class Dynamic extends ListenerAdapter {
public static final String dronePublicPrivate = "voice-dynamic-drone-public-private";
public static final String dronePermTemp = "voice-dynamic-drone-permanent-temporary";
public static final String droneClaim = "voice-dynamic-drone-claim";
public static VoiceManager voiceManager;
public static DroneManager droneManager;
private static VoiceManager voiceManager;
private static DroneManager droneManager;

@Autowired
public void setVoiceManager(VoiceManager voiceManager) {
Dynamic.voiceManager = voiceManager;
}

@Autowired
public void setDroneManager(DroneManager droneManager) {
Dynamic.droneManager = droneManager;
}

// endregion

Expand Down

0 comments on commit 8eab2c0

Please sign in to comment.