Skip to content

Commit

Permalink
Merge pull request #16 from brendonmiranda/1.2.0-rc
Browse files Browse the repository at this point in the history
1.2.0 rc
  • Loading branch information
brendonmiranda authored Jul 5, 2020
2 parents e6c6a58 + fe1448e commit 10793dd
Show file tree
Hide file tree
Showing 38 changed files with 951 additions and 445 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dozeapp-preprod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ jobs:
run: ./gradlew dockerPushDockerHub

- name: Docker pull published image
run: docker pull evelynvieira/dozeapp:1.1.1
run: docker pull evelynvieira/dozeapp:1.2.0

- name: Docker Login on Heroku
run: docker login --username=_ --password=${{ secrets.PREPROD_HEROKU_KEY }} registry.heroku.com

- name: Docker tag on Heroku
run: docker tag evelynvieira/dozeapp:1.1.1 registry.heroku.com/dozeapp-heroku-preprod/worker
run: docker tag evelynvieira/dozeapp:1.2.0 registry.heroku.com/dozeapp-heroku-preprod/worker

- name: Docker push on Heroku
run: docker push registry.heroku.com/dozeapp-heroku-preprod/worker
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dozeapp-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ jobs:
run: ./gradlew dockerPushDockerHub

- name: Docker pull published image
run: docker pull evelynvieira/dozeapp:1.1.1
run: docker pull evelynvieira/dozeapp:1.2.0

- name: Docker Login on Heroku
run: docker login --username=_ --password=${{ secrets.HEROKU_KEY }} registry.heroku.com

- name: Docker tag on Heroku
run: docker tag evelynvieira/dozeapp:1.1.1 registry.heroku.com/dozeapp-heroku/worker
run: docker tag evelynvieira/dozeapp:1.2.0 registry.heroku.com/dozeapp-heroku/worker

- name: Docker push on Heroku
run: docker push registry.heroku.com/dozeapp-heroku/worker
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ COPY ${START_SCRIPT} start.sh

ENTRYPOINT ["./start.sh"]

CMD ["${BOT_OWNER}", "${BOT_TOKEN}", "${BOT_PREFIX}", "${BOT_INACTIVITY_TIME}"]
CMD ["${BOT_OWNER}", "${BOT_TOKEN}", "${BOT_PREFIX}", "${BOT_INACTIVE_THRESHOLD}", "${BOT_TASK_INACTIVE_FIXED_DELAY}", "${BOT_RABBIT_HOSTNAME}", "${BOT_RABBIT_USERNAME}", "${BOT_RABBIT_PASSWORD}", "${BOT_RABBIT_VIRTUALHOST}", "${BOT_RABBIT_CONNECTION_TIMEOUT}", "${BOT_RABBIT_REQUEST_HEARTBEAT}", "${BOT_RABBIT_QUEUE_TTL}"]
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {
apply plugin: 'io.spring.javaformat'

group = 'io.github.brendonmiranda'
version = '1.1.1'
version = '1.2.0'
sourceCompatibility = '13'

configurations {
Expand All @@ -41,10 +41,12 @@ dependencies {
implementation 'net.dv8tion:JDA:4.1.1_137'
implementation 'com.jagrosh:jda-utilities:3.0.3'
implementation 'com.sedmelluq:lavaplayer:1.3.50'
implementation 'org.springframework.boot:spring-boot-starter-amqp'

testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.amqp:spring-rabbit-test'
}

docker {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class JavaBotApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
package io.github.brendonmiranda.javabot.listener.cmd.music;
package io.github.brendonmiranda.javabot.command;

import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import io.github.brendonmiranda.javabot.service.LifeCycleService;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.managers.AudioManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
* @author brendonmiranda
*/
@Component
public class JoinCmd extends MusicCmd {

private static final Logger logger = LoggerFactory.getLogger(JoinCmd.class);

private final LifeCycleService lifeCycleService;

public JoinCmd(LifeCycleService lifeCycleService) {
public JoinCmd() {
this.name = "join";
this.help = "joins you on the channel";
this.lifeCycleService = lifeCycleService; // todo: inject it
}

/**
* It was overrode in order to avoid validations from MusicCmd which must not be
* applied to JoinCmd.
* applied to Join Command.
* @param event
*/
@Override
Expand All @@ -45,11 +42,10 @@ public void execute(CommandEvent event) {
@Override
public void command(CommandEvent event) {
VoiceChannel memberVoiceChannel = event.getEvent().getMember().getVoiceState().getChannel();
Guild guild = event.getGuild();
AudioManager audioManager = guild.getAudioManager();
Guild guild = getGuild(event);
AudioManager audioManager = getAudioManager(guild);

audioManager.openAudioConnection(memberVoiceChannel);
lifeCycleService.scheduleDisconnectByInactivityTask(guild);
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.brendonmiranda.javabot.listener.cmd.music;
package io.github.brendonmiranda.javabot.command;

import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import io.github.brendonmiranda.javabot.service.LifeCycleService;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import io.github.brendonmiranda.javabot.listener.AudioSendHandlerImpl;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.managers.AudioManager;

import static io.github.brendonmiranda.javabot.service.LifeCycleService.*;

/**
* @author brendonmiranda
*/
Expand Down Expand Up @@ -41,15 +41,25 @@ protected void execute(CommandEvent event) {
return;
}

/*
* Cancel any disconnectByInactivityTask scheduled previously given that a command
* has been triggered
*/
timerTasksQueue.forEach(task -> task.cancel());

command(event);
}

protected AudioSendHandlerImpl getAudioSendHandler(Guild guild) {
return (AudioSendHandlerImpl) guild.getAudioManager().getSendingHandler();
}

protected AudioPlayer getAudioPlayer(AudioSendHandlerImpl audioSendHandler) {
return audioSendHandler.getAudioPlayer();
}

protected Guild getGuild(CommandEvent event) {
return event.getGuild();
}

protected AudioManager getAudioManager(Guild guild) {
return guild.getAudioManager();
}

public abstract void command(CommandEvent event);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.github.brendonmiranda.javabot.command;

import com.jagrosh.jdautilities.command.CommandEvent;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import io.github.brendonmiranda.javabot.listener.AudioSendHandlerImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
* @author evelynvieira
*/
@Component
public class NowPlayingCmd extends MusicCmd {

private static final Logger logger = LoggerFactory.getLogger(NowPlayingCmd.class);

public NowPlayingCmd() {
this.name = "now";
this.help = "shows the song which is playing in the moment";
}

@Override
public void command(CommandEvent event) {
AudioSendHandlerImpl audioSendHandler = getAudioSendHandler(event.getGuild());

if (audioSendHandler == null) {
event.replyError("There is no track playing");
return;
}

AudioPlayer audioPlayer = getAudioPlayer(audioSendHandler);

if (audioPlayer.getPlayingTrack() != null) {
AudioTrack audioTrack = audioPlayer.getPlayingTrack();
event.replySuccess("Now playing the track **" + audioTrack.getInfo().title + "**.");
}
else {
event.replyWarning("There is no track playing");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.github.brendonmiranda.javabot.command;

import com.jagrosh.jdautilities.command.CommandEvent;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import io.github.brendonmiranda.javabot.listener.AudioSendHandlerImpl;
import org.springframework.stereotype.Component;

/**
* @author evelynvieira
*/
@Component
public class PauseCmd extends MusicCmd {

public PauseCmd() {
this.name = "pause";
this.help = "pauses the current song";
}

public void command(CommandEvent event) {
AudioSendHandlerImpl audioSendHandler = getAudioSendHandler(event.getGuild());

if (audioSendHandler == null) {
event.replyError("There is no track playing to pause.");
return;
}

AudioPlayer audioPlayer = getAudioPlayer(audioSendHandler);

if (audioPlayer.isPaused()) {
// todo: instantiate ResumeCmd and use it instead
audioPlayer.setPaused(false);
event.replySuccess("Resumed **" + audioPlayer.getPlayingTrack().getInfo().title + "**.");
return;
}

if (audioPlayer.getPlayingTrack() != null) {
audioPlayer.setPaused(true);
event.replySuccess("Paused **" + audioPlayer.getPlayingTrack().getInfo().title + "**. Type `"
+ event.getClient().getPrefix() + " resume` to unpause!");
}
}

}
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
package io.github.brendonmiranda.javabot.listener.cmd.music;
package io.github.brendonmiranda.javabot.command;

import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import io.github.brendonmiranda.javabot.listener.audio.AudioEventListener;
import io.github.brendonmiranda.javabot.listener.audio.AudioLoadResultHandlerImpl;
import io.github.brendonmiranda.javabot.listener.AudioEventListener;
import io.github.brendonmiranda.javabot.listener.PlayResultHandler;
import io.github.brendonmiranda.javabot.service.AudioQueueService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
* @author brendonmiranda
*/
@Component
public class PlayCmd extends MusicCmd {

private static final Logger logger = LoggerFactory.getLogger(PlayCmd.class);

private final AudioPlayerManager audioPlayerManager;
@Autowired
private AudioQueueService audioQueueService;

private final AudioEventListener audioListener; // todo remove it. Instantiate in
// command method
@Autowired
private AudioPlayerManager audioPlayerManager;

private final EventWaiter eventWaiter;
@Autowired
private EventWaiter eventWaiter;

public PlayCmd(AudioPlayerManager audioPlayerManager, AudioEventListener audioListener, EventWaiter eventWaiter) {
this.audioPlayerManager = audioPlayerManager;
this.audioListener = audioListener;
this.eventWaiter = eventWaiter;
@Autowired
private AudioEventListener audioEventListener;

public PlayCmd() {
this.name = "play";
this.help = "plays or queue a song";
}
Expand All @@ -36,11 +42,11 @@ public void command(CommandEvent event) {
logger.debug("PlayCmd loading track: {}", event.getArgs());

AudioPlayer audioPlayer = audioPlayerManager.createPlayer();
audioPlayer.addListener(audioListener);
audioPlayer.addListener(audioEventListener);

event.reply("Searching...", (message) -> {
audioPlayerManager.loadItemOrdered(event.getGuild(), event.getArgs(), new AudioLoadResultHandlerImpl(
audioPlayer, event, audioPlayerManager, eventWaiter, message, false));
audioPlayerManager.loadItemOrdered(event.getGuild(), event.getArgs(), new PlayResultHandler(audioPlayer,
event, audioPlayerManager, eventWaiter, message, false, audioQueueService));
});

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.github.brendonmiranda.javabot.command;

import com.jagrosh.jdautilities.command.CommandEvent;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import io.github.brendonmiranda.javabot.listener.AudioSendHandlerImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
* @author evelynvieira
*/
@Component
public class ResumeCmd extends MusicCmd {

private static final Logger logger = LoggerFactory.getLogger(ResumeCmd.class);

public ResumeCmd() {
this.name = "resume";
this.help = "resumes the current song";
}

public void command(CommandEvent event) {
AudioSendHandlerImpl audioSendHandler = getAudioSendHandler(event.getGuild());

if (audioSendHandler == null) {
event.replyError("There is no track to resume.");
return;
}

AudioPlayer audioPlayer = getAudioPlayer(audioSendHandler);

if (audioPlayer.getPlayingTrack() != null && audioPlayer.isPaused()) {
audioPlayer.setPaused(false);
event.replySuccess("Resumed **" + audioPlayer.getPlayingTrack().getInfo().title + "**.");
}

}

}
Loading

0 comments on commit 10793dd

Please sign in to comment.