Skip to content

Commit

Permalink
use dependency injection
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Nov 4, 2023
1 parent 68f4b97 commit 3c0095f
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/main/java/vc/commands/ChatsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
@Component
public class ChatsCommand implements SlashCommand {
private static final Logger LOGGER = getLogger(ChatsCommand.class);
private final ChatsApi chatsApi = new ChatsApi();
private final ChatsApi chatsApi;
private final PlayerLookup playerLookup;

public ChatsCommand(final PlayerLookup playerLookup) {
public ChatsCommand(final ChatsApi chatsApi, final PlayerLookup playerLookup) {
this.chatsApi = chatsApi;
this.playerLookup = playerLookup;
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/vc/commands/ConnectionsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
@Component
public class ConnectionsCommand implements SlashCommand {
private static final Logger LOGGER = getLogger(ConnectionsCommand.class);
private final ConnectionsApi connectionsApi = new ConnectionsApi();
private final ConnectionsApi connectionsApi;
private final PlayerLookup playerLookup;

public ConnectionsCommand(final PlayerLookup playerLookup) {
public ConnectionsCommand(final ConnectionsApi connectionsApi, final PlayerLookup playerLookup) {
this.connectionsApi = connectionsApi;
this.playerLookup = playerLookup;
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/vc/commands/DeathsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
@Component
public class DeathsCommand implements SlashCommand {
private static final Logger LOGGER = getLogger(DeathsCommand.class);
private final DeathsApi deathsApi = new DeathsApi();
private final DeathsApi deathsApi;
private final PlayerLookup playerLookup;

public DeathsCommand(final PlayerLookup playerLookup) {
public DeathsCommand(final DeathsApi deathsApi, final PlayerLookup playerLookup) {
this.deathsApi = deathsApi;
this.playerLookup = playerLookup;
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/vc/commands/KillsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
@Component
public class KillsCommand implements SlashCommand {
private static final Logger LOGGER = getLogger(KillsCommand.class);
private final DeathsApi deathsApi = new DeathsApi();
private final DeathsApi deathsApi;
private final PlayerLookup playerLookup;

public KillsCommand(final PlayerLookup playerLookup) {
public KillsCommand(final DeathsApi deathsApi, final PlayerLookup playerLookup) {
this.deathsApi = deathsApi;
this.playerLookup = playerLookup;
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/vc/commands/NamesCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@

@Component
public class NamesCommand implements SlashCommand {
private final NamesApi namesApi = new NamesApi();
private final NamesApi namesApi;
private final PlayerLookup playerLookup;

public NamesCommand(final PlayerLookup playerLookup) {
public NamesCommand(final NamesApi namesApi, final PlayerLookup playerLookup) {
this.namesApi = namesApi;
this.playerLookup = playerLookup;
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/vc/commands/PlaytimeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
@Component
public class PlaytimeCommand implements SlashCommand {

private final PlaytimeApi playtimeApi = new PlaytimeApi();
private final PlaytimeApi playtimeApi;
private final PlayerLookup playerLookup;

public PlaytimeCommand(final PlayerLookup playerLookup) {
public PlaytimeCommand(final PlaytimeApi playtimeApi, final PlayerLookup playerLookup) {
this.playtimeApi = playtimeApi;
this.playerLookup = playerLookup;
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/vc/commands/PlaytimeTopMonthCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
@Component
public class PlaytimeTopMonthCommand implements SlashCommand {

private final PlaytimeApi playtimeApi = new PlaytimeApi();
private final PlaytimeApi playtimeApi;
private static final DecimalFormat df = new DecimalFormat("0.00");

public PlaytimeTopMonthCommand(final PlaytimeApi playtimeApi) {
this.playtimeApi = playtimeApi;
}

@Override
public String getName() {
return "playtimemonth";
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/vc/commands/SeenCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
@Component
public class SeenCommand implements SlashCommand {

private final SeenApi seenApi = new SeenApi();
private final SeenApi seenApi;
private final PlayerLookup playerLookup;

public SeenCommand(final PlayerLookup playerLookup) {
public SeenCommand(final SeenApi seenApi, final PlayerLookup playerLookup) {
this.seenApi = seenApi;
this.playerLookup = playerLookup;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static vc.commands.QueueCommand.getQueueWaitInSeconds;

@Component
public class LivePresence {
public class DiscordPresenceUpdater {
private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger("LivePresence");
private final ScheduledExecutorService scheduledExecutorService;
private final GatewayDiscordClient discordClient;
Expand All @@ -37,7 +37,7 @@ public class LivePresence {
"2b2t is full"
);

public LivePresence(final ScheduledExecutorService scheduledExecutorService, final GatewayDiscordClient discordClient, final QueueApi queueApi, final TabListApi tabListApi) {
public DiscordPresenceUpdater(final ScheduledExecutorService scheduledExecutorService, final GatewayDiscordClient discordClient, final QueueApi queueApi, final TabListApi tabListApi) {
this.scheduledExecutorService = scheduledExecutorService;
this.discordClient = discordClient;
this.queueApi = queueApi;
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/vc/util/PlayerLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@

@Component
public class PlayerLookup {
private final UuidApi uuidApi = new UuidApi();
private final UuidApi uuidApi;
private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger("PlayerLookup");

public PlayerLookup(final UuidApi uuidApi) {
this.uuidApi = uuidApi;
}

public record PlayerIdentity(UUID uuid, String playerName) { }

public Optional<PlayerIdentity> getPlayerIdentity(final String playerName) {
Expand Down

0 comments on commit 3c0095f

Please sign in to comment.