Merge pull request #310 from BigBotNetwork/greg-dev

Merged!
This commit is contained in:
Skidder 2020-01-10 19:26:20 +01:00 committed by GitHub
commit 03c49ccd9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 113 additions and 19 deletions

View file

@ -1,2 +1,2 @@
FROM debian:latest
FROM debian:buster
WORKDIR /home/Hadder

16
pom.xml
View file

@ -19,18 +19,18 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.1.0_93</version>
<version>4.1.0_95</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>com.rethinkdb</groupId>
<artifactId>rethinkdb-driver</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>com.rethinkdb</groupId>
<artifactId>rethinkdb-driver</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
@ -39,7 +39,7 @@
<dependency>
<groupId>club.minnced</groupId>
<artifactId>discord-webhooks</artifactId>
<version>0.1.8</version>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>org.kohsuke</groupId>
@ -49,7 +49,7 @@
<dependency>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer</artifactId>
<version>1.3.32</version>
<version>1.3.33</version>
</dependency>
</dependencies>

View file

@ -102,7 +102,8 @@ public class Hadder {
new VolumeCommand(),
new StopCommand(),
new BlacklistCommand(),
new PauseCommand()), config, helpCommand);
new PauseCommand(),
new LoopCommand()), config, helpCommand);
builder.addEventListeners(
new MentionListener(rethink),

View file

@ -70,6 +70,22 @@ public class Rethink {
}
}
public void update(String table, String value, String what, int whatvalue) {
try {
r.table(table).get(value).update(r.hashMap(what, whatvalue)).run(conn);
} catch (ClassCastException e) {
e.printStackTrace();
}
}
public void update(String table, String value, String what, boolean whatvalue) {
try {
r.table(table).get(value).update(r.hashMap(what, whatvalue)).run(conn);
} catch (ClassCastException e) {
e.printStackTrace();
}
}
public void insert(String table, Object object) {
try {
r.table(table).insert(object).run(conn);
@ -122,7 +138,8 @@ public class Rethink {
}
public void insertGuild(String id) {
this.insert("server", r.hashMap("id", id)
this.insert("server", r
.hashMap("id", id)
.with("prefix", "h.")
.with("message_id", "")
.with("role_id", "")
@ -133,7 +150,11 @@ public class Rethink {
}
public void insertUser(String id) {
this.insert("user", r.hashMap("id", id).with("prefix", "h.").with("language", "en").with("blacklisted", "none"));
this.insert("user", r
.hashMap("id", id)
.with("prefix", "h.")
.with("language", "en")
.with("blacklisted", "none"));
}
public void setBlackListed(String id, String commands) {
@ -204,11 +225,7 @@ public class Rethink {
}
public void setInviteDetection(String guild_id, boolean b) {
try {
r.table("server").get(guild_id).update(r.hashMap("invite_detect", b)).run(conn);
} catch (ClassCastException e) {
e.printStackTrace();
}
this.update("server", guild_id, "invite_detect", b);
}
public Boolean getInviteDetection(String guild_id) {

View file

@ -19,6 +19,7 @@ public class TrackManager extends AudioEventAdapter {
private final AudioPlayer player;
private final Queue<AudioInfo> queue;
private boolean loop = false;
public TrackManager(AudioPlayer player) {
this.player = player;
@ -47,8 +48,10 @@ public class TrackManager extends AudioEventAdapter {
@Override
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
Guild g = queue.poll().getAuthor().getGuild();
if (queue.isEmpty()) {
Guild g = queue.element().getAuthor().getGuild();
if (loop) {
player.playTrack(track.makeClone());
} else if (queue.isEmpty()) {
g.getAudioManager().closeAudioConnection();
} else {
player.playTrack(queue.element().getTrack());
@ -67,6 +70,16 @@ public class TrackManager extends AudioEventAdapter {
queue.remove(entry);
}
public boolean isLoop()
{
return loop;
}
public void setLoop(boolean repeating)
{
this.loop = repeating;
}
public AudioInfo getTrackInfo(AudioTrack track) {
return queue.stream().filter(audioInfo -> audioInfo.getTrack().equals(track)).findFirst().orElse(null);
}

View file

@ -0,0 +1,56 @@
package com.bbn.hadder.commands.music;
import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.utils.MessageEditor;
/**
* @author Skidder / GregTCLTK
*/
public class LoopCommand implements Command {
@Override
public void executed(String[] args, CommandEvent event) {
if (event.getAudioManager().hasPlayer(event.getGuild()) && event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack() != null) {
if (event.getMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().getChannel().equals(event.getMember().getVoiceState().getChannel())) {
if (event.getAudioManager().getTrackManager(event.getGuild()).isLoop()) {
event.getAudioManager().getTrackManager(event.getGuild()).setLoop(false);
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, "commands.music.loop.success.unloop.title", "commands.music.loop.success.unloop.description").build()).queue();
} else {
event.getAudioManager().getTrackManager(event.getGuild()).setLoop(true);
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, "commands.music.loop.success.loop.title", "commands.music.loop.success.loop.description").build()).queue();
}
} else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
"commands.music.loop.error.connected.title",
"commands.music.loop.error.connected.description")
.build()).queue();
}
} else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
"commands.music.info.error.title",
"commands.music.info.error.description").build()).queue();
}
}
@Override
public String[] labels() {
return new String[]{"loop", "repeat"};
}
@Override
public String description() {
return "commands.music.loop.help.description";
}
@Override
public String usage() {
return null;
}
@Override
public String example() {
return null;
}
}

View file

@ -237,6 +237,13 @@ commands.music.pause.error.paused.description = The song is already paused.
commands.music.pause.error.connected.title = No channel
commands.music.pause.error.connected.description = You have to be in the same voice channel as the bot to pause the song.
commands.music.pause.help.description = Pause the playing song.
commands.music.loop.success.loop.title = Successfully activated
commands.music.loop.success.loop.description = I will now repeat the currently played song.
commands.music.loop.success.unloop.title = Successfully deactivated
commands.music.loop.success.unloop.description = I will no longer repeat the currently played song.
commands.music.loop.error.connected.title = No channel
commands.music.loop.error.connected.description = You have to be in the same voice channel as the bot to set the repeat status.
commands.music.loop.help.description = Repeats a song/queue.
commands.nsfw.gif.error.title = GIF not showing? Click here
commands.nsfw.img.error.title = Image not showing? Click here