Merge pull request #271 from BigBotNetwork/greg-dev

Merged!
This commit is contained in:
Skidder 2019-12-28 15:27:05 +01:00 committed by GitHub
commit afdbd74165
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 237 additions and 141 deletions

View file

@ -19,7 +19,7 @@
<dependency> <dependency>
<groupId>net.dv8tion</groupId> <groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId> <artifactId>JDA</artifactId>
<version>4.1.0_86</version> <version>4.1.0_87</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>

View file

@ -1,5 +1,6 @@
package com.bbn.hadder; package com.bbn.hadder;
import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.general.*; import com.bbn.hadder.commands.general.*;
import com.bbn.hadder.commands.misc.*; import com.bbn.hadder.commands.misc.*;
import com.bbn.hadder.commands.moderation.*; import com.bbn.hadder.commands.moderation.*;
@ -41,6 +42,7 @@ public class Hadder {
builder.setToken(config.getBotToken()); builder.setToken(config.getBotToken());
HelpCommand helpCommand = new HelpCommand(); HelpCommand helpCommand = new HelpCommand();
AudioManager audioManager = new AudioManager();
CommandHandler commandHandler = new CommandHandler( CommandHandler commandHandler = new CommandHandler(
List.of( List.of(
@ -100,12 +102,13 @@ public class Hadder {
builder.addEventListeners( builder.addEventListeners(
new MentionListener(rethink), new MentionListener(rethink),
new PrivateMessageListener(rethink), new PrivateMessageListener(rethink),
new CommandListener(rethink, commandHandler), new CommandListener(rethink, commandHandler, audioManager),
new GuildListener(rethink, config), new GuildListener(rethink, config),
new ReadyListener(rethink, config), new ReadyListener(rethink, config),
new InviteLinkListener(rethink), new InviteLinkListener(rethink),
new RulesListener(rethink), new RulesListener(rethink),
new StarboardListener(rethink)); new StarboardListener(rethink),
new VoiceLeaveListener(audioManager));
try { try {
shardManager = builder.build(); shardManager = builder.build();

View file

@ -10,7 +10,9 @@ import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import java.util.AbstractMap; import java.util.AbstractMap;
@ -28,11 +30,47 @@ public class AudioManager {
AudioSourceManagers.registerRemoteSources(myManager); AudioSourceManagers.registerRemoteSources(myManager);
} }
public final Map<String, Map.Entry<AudioPlayer, TrackManager>> players = new HashMap<>(); public Map<String, Map.Entry<AudioPlayer, TrackManager>> players = new HashMap<>();
public final AudioPlayerManager myManager = new DefaultAudioPlayerManager(); private final AudioPlayerManager myManager = new DefaultAudioPlayerManager();
public boolean hasPlayer(Guild guild) {
return players.containsKey(guild.getId());
}
public void removePlayer(Guild g) {
System.out.println(players.toString());
players.remove(g.getId());
System.out.println(players.toString());
}
public Map<String, Map.Entry<AudioPlayer, TrackManager>> getPlayers () {
return players;
}
public AudioPlayer getPlayer(Guild guild) {
AudioPlayer p;
if (hasPlayer(guild)) {
p = players.get(guild.getId()).getKey();
} else {
p = createPlayer(guild);
}
return p;
}
public TrackManager getTrackManager(Guild guild) {
return players.get(guild.getId()).getValue();
}
public AudioPlayer createPlayer(Guild guild) {
AudioPlayer nPlayer = myManager.createPlayer();
TrackManager manager = new TrackManager(nPlayer);
nPlayer.addListener(manager);
guild.getAudioManager().setSendingHandler(new AudioPlayerSendHandler(nPlayer));
players.put(guild.getId(), new AbstractMap.SimpleEntry<>(nPlayer, manager));
return nPlayer;
}
public void loadTrack(String identifier, CommandEvent event, Message msg) { public void loadTrack(String identifier, CommandEvent event, Message msg) {
Guild guild = event.getGuild(); Guild guild = event.getGuild();
getPlayer(guild); getPlayer(guild);
@ -60,9 +98,15 @@ public class AudioManager {
} else if (playlist.isSearchResult()) { } else if (playlist.isSearchResult()) {
trackLoaded(playlist.getTracks().get(0)); trackLoaded(playlist.getTracks().get(0));
} else { } else {
for (int i = 0; i < Math.min(playlist.getTracks().size(), 200); i++) { for (int i = 0; i < Math.min(playlist.getTracks().size(), 69); i++) {
getTrackManager(guild).queue(playlist.getTracks().get(i), event.getMember()); getTrackManager(guild).queue(playlist.getTracks().get(i), event.getMember());
} }
msg.editMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.music.play.success.loading.title", "",
"", "")
.addField(event.getMessageEditor().getTerm("commands.music.play.success.title"), playlist.getName(), true)
.addField(event.getMessageEditor().getTerm("commands.music.play.success.tracks"), String.valueOf(playlist.getTracks().size()), true)
.build()).queue();
} }
} }
@ -84,31 +128,25 @@ public class AudioManager {
}); });
} }
public boolean hasPlayer(Guild guild) { public boolean isDj(Member member) {
return players.containsKey(guild.getId()); return member.getRoles().stream().anyMatch(r -> r.getName().equals("DJ"));
} }
public AudioPlayer getPlayer(Guild guild) { public boolean isCurrentDj(Member member) {
AudioPlayer p; return getTrackManager(member.getGuild()).getTrackInfo(getPlayer(member.getGuild()).getPlayingTrack()).getAuthor().equals(member);
if (hasPlayer(guild)) {
p = players.get(guild.getId()).getKey();
} else {
p = createPlayer(guild);
}
return p;
} }
public TrackManager getTrackManager(Guild guild) { public void forceSkipTrack(CommandEvent event) {
return players.get(guild.getId()).getValue(); getPlayer(event.getGuild()).stopTrack();
} }
public AudioPlayer createPlayer(Guild guild) { public String getTimestamp(long milis) {
AudioPlayer nPlayer = myManager.createPlayer(); long seconds = milis / 1000;
TrackManager manager = new TrackManager(nPlayer); long hours = Math.floorDiv(seconds, 3600);
nPlayer.addListener(manager); seconds = seconds - (hours * 3600);
guild.getAudioManager().setSendingHandler(new AudioPlayerSendHandler(nPlayer)); long mins = Math.floorDiv(seconds, 60);
players.put(guild.getId(), new AbstractMap.SimpleEntry<>(nPlayer, manager)); seconds = seconds - (mins * 60);
return nPlayer; return (hours == 0 ? "" : hours + ":") + String.format("%02d", mins) + ":" + String.format("%02d", seconds);
} }
public String getOrNull(String s) { public String getOrNull(String s) {

View file

@ -1,6 +1,7 @@
package com.bbn.hadder.commands; package com.bbn.hadder.commands;
import com.bbn.hadder.Rethink; import com.bbn.hadder.Rethink;
import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.general.HelpCommand; import com.bbn.hadder.commands.general.HelpCommand;
import com.bbn.hadder.core.CommandHandler; import com.bbn.hadder.core.CommandHandler;
import com.bbn.hadder.core.Config; import com.bbn.hadder.core.Config;
@ -8,6 +9,7 @@ import com.bbn.hadder.utils.EventWaiter;
import com.bbn.hadder.utils.MessageEditor; import com.bbn.hadder.utils.MessageEditor;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.events.Event;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -20,8 +22,9 @@ public class CommandEvent extends MessageReceivedEvent {
private HelpCommand helpCommand; private HelpCommand helpCommand;
private MessageEditor messageEditor; private MessageEditor messageEditor;
private EventWaiter eventWaiter; private EventWaiter eventWaiter;
private AudioManager audioManager;
public CommandEvent(@Nonnull JDA api, long responseNumber, @Nonnull Message message, Rethink rethink, Config config, CommandHandler commandHandler, HelpCommand helpCommand, MessageEditor messageEditor, EventWaiter eventWaiter) { public CommandEvent(@Nonnull JDA api, long responseNumber, @Nonnull Message message, Rethink rethink, Config config, CommandHandler commandHandler, HelpCommand helpCommand, MessageEditor messageEditor, EventWaiter eventWaiter, AudioManager audioManager) {
super(api, responseNumber, message); super(api, responseNumber, message);
this.rethink = rethink; this.rethink = rethink;
this.config = config; this.config = config;
@ -29,6 +32,18 @@ public class CommandEvent extends MessageReceivedEvent {
this.helpCommand = helpCommand; this.helpCommand = helpCommand;
this.messageEditor = messageEditor; this.messageEditor = messageEditor;
this.eventWaiter = eventWaiter; this.eventWaiter = eventWaiter;
this.audioManager = audioManager;
}
public CommandEvent(MessageReceivedEvent event, Rethink rethink, Config config, CommandHandler commandHandler, HelpCommand helpCommand, MessageEditor messageEditor, EventWaiter eventWaiter, AudioManager audioManager) {
super(event.getJDA(), event.getResponseNumber(), event.getMessage());
this.rethink = rethink;
this.config = config;
this.commandHandler = commandHandler;
this.helpCommand = helpCommand;
this.messageEditor = messageEditor;
this.eventWaiter = eventWaiter;
this.audioManager = audioManager;
} }
public Rethink getRethink() { public Rethink getRethink() {
@ -54,4 +69,8 @@ public class CommandEvent extends MessageReceivedEvent {
public EventWaiter getEventWaiter() { public EventWaiter getEventWaiter() {
return eventWaiter; return eventWaiter;
} }
public AudioManager getAudioManager() {
return audioManager;
}
} }

View file

@ -26,7 +26,7 @@ public class BanCommand implements Command {
event.getMessageEditor().getMessage( event.getMessageEditor().getMessage(
MessageEditor.MessageType.INFO, MessageEditor.MessageType.INFO,
"commands.moderation.ban.success.title", "commands.moderation.ban.success.title",
"", "",
"commands.moderation.ban.success.description", "commands.moderation.ban.success.description",
victim.getUser().getName() + ".").build()).queue(); victim.getUser().getName() + ".").build()).queue();
} else { } else {
@ -74,7 +74,7 @@ public class BanCommand implements Command {
} }
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.moderation.ban.success.title", "commands.moderation.ban.success.title",
"", "",
"commands.moderation.ban.massban.success.description", "commands.moderation.ban.massban.success.description",
String.valueOf(event.getMessage().getMentionedMembers().size())).build()).queue(); String.valueOf(event.getMessage().getMentionedMembers().size())).build()).queue();
} }

View file

@ -1,8 +1,8 @@
package com.bbn.hadder.commands.music; package com.bbn.hadder.commands.music;
import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.utils.MessageEditor;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
/** /**
@ -11,46 +11,31 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
public class InfoCommand implements Command { public class InfoCommand implements Command {
private static final String CD = "\uD83D\uDCBF";
private static final String MIC = "\uD83C\uDFA4";
private static final String QUEUE_DESCRIPTION = "%s **|>** %s\n%s\n%s %s\n%s";
@Override @Override
public void executed(String[] args, CommandEvent event) { public void executed(String[] args, CommandEvent event) {
if (new AudioManager().hasPlayer(event.getGuild())) { if (event.getAudioManager().hasPlayer(event.getGuild()) && event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack() != null) {
event.getTextChannel().sendMessage("Ja Player is auch wieder da"); AudioTrack track = event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack();
} event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
if (new AudioManager().getPlayer(event.getGuild()).getPlayingTrack() == null) { "commands.music.info.success.title", "")
event.getTextChannel().sendMessage("Joo playing track net anwesend^^").queue(); .setAuthor(track.getInfo().author)
} .addField("Title", track.getInfo().title, true)
if (!new AudioManager().hasPlayer(event.getGuild()) || new AudioManager().getPlayer(event.getGuild()).getPlayingTrack() == null) { .addField("Progress", "`[ " + event.getAudioManager().getTimestamp(track.getPosition()) + " / " + event.getAudioManager().getTimestamp(track.getInfo().length) + " ]`", false)
event.getTextChannel().sendMessage("Shut up eyyyy du kek").queue(); .build()).queue();
} else { } else {
AudioTrack track = new AudioManager().getPlayer(event.getGuild()).getPlayingTrack(); event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
event.getTextChannel().sendMessage("Track Info" + String.format(QUEUE_DESCRIPTION, CD, new AudioManager().getOrNull(track.getInfo().title), "commands.music.info.error.title",
"\n\u23F1 **|>** `[ " + getTimestamp(track.getPosition()) + " / " + getTimestamp(track.getInfo().length) + " ]`", "commands.music.info.error.description").build()).queue();
"\n" + MIC, new AudioManager().getOrNull(track.getInfo().author),
"\n\uD83C\uDFA7 **|>** " + "")).queue();
} }
} }
private String getTimestamp(long milis) {
long seconds = milis / 1000;
long hours = Math.floorDiv(seconds, 3600);
seconds = seconds - (hours * 3600);
long mins = Math.floorDiv(seconds, 60);
seconds = seconds - (mins * 60);
return (hours == 0 ? "" : hours + ":") + String.format("%02d", mins) + ":" + String.format("%02d", seconds);
}
@Override @Override
public String[] labels() { public String[] labels() {
return new String[]{"info"}; return new String[]{"info", "songinfo"};
} }
@Override @Override
public String description() { public String description() {
return "Shows information about the playing song"; return "commands.music.info.help.description";
} }
@Override @Override

View file

@ -33,32 +33,30 @@ public class JoinCommand implements Command {
} else { } else {
event.getTextChannel().sendMessage( event.getTextChannel().sendMessage(
event.getMessageEditor().getMessage( event.getMessageEditor().getMessage(
MessageEditor.MessageType.WARNING, MessageEditor.MessageType.WARNING,
"commands.music.join.error.connecting.already.title", "commands.music.join.error.connecting.already.title",
"commands.music.join.error.connecting.already.description") "commands.music.join.error.connecting.already.description")
.build()).queue(); .build()).queue();
} }
} else { } else {
event.getGuild().getAudioManager().openAudioConnection(vc); event.getGuild().getAudioManager().openAudioConnection(vc);
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
MessageEditor.MessageType.INFO, MessageEditor.MessageType.INFO,
"commands.music.join.success.title", "commands.music.join.success.title", "",
"", "commands.music.join.success.description", vc.getName())
"commands.music.join.success.description",
vc.getName())
.build()).queue(); .build()).queue();
} }
} else { } else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
MessageEditor.MessageType.WARNING, MessageEditor.MessageType.WARNING,
"commands.music.join.error.connecting.trying.title", "commands.music.join.error.connecting.trying.title",
"commands.music.join.error.connecting.trying.description") "commands.music.join.error.connecting.trying.description")
.build()).queue(); .build()).queue();
} }
} else { } else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
MessageEditor.MessageType.WARNING, MessageEditor.MessageType.WARNING,
"commands.music.join.error.channel.title", "commands.music.join.error.channel.title",
"commands.music.join.error.channel.description") "commands.music.join.error.channel.description")
.build()).queue(); .build()).queue();
} }

View file

@ -15,14 +15,14 @@ public class LeaveCommand implements Command {
if (event.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) { if (event.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) {
event.getGuild().getAudioManager().closeAudioConnection(); event.getGuild().getAudioManager().closeAudioConnection();
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
MessageEditor.MessageType.INFO, MessageEditor.MessageType.INFO,
"commands.music.leave.success.title", "commands.music.leave.success.title",
"commands.music.leave.success.description") "commands.music.leave.success.description")
.build()).queue(); .build()).queue();
} else { } else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
MessageEditor.MessageType.WARNING, MessageEditor.MessageType.WARNING,
"commands.music.leave.error.tile", "commands.music.leave.error.tile",
"commands.music.leave.error.description") "commands.music.leave.error.description")
.build()).queue(); .build()).queue();
} }
@ -30,7 +30,7 @@ public class LeaveCommand implements Command {
@Override @Override
public String[] labels() { public String[] labels() {
return new String[]{"leave"}; return new String[]{"leave", "quit"};
} }
@Override @Override

View file

@ -1,6 +1,5 @@
package com.bbn.hadder.commands.music; package com.bbn.hadder.commands.music;
import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.utils.MessageEditor; import com.bbn.hadder.utils.MessageEditor;
@ -24,12 +23,12 @@ public class PlayCommand implements Command {
Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.music.play.load.title", "", "commands.music.play.load.title", "",
"commands.music.play.load.description", "").build()).complete(); "commands.music.play.load.description", "").build()).complete();
new AudioManager().loadTrack(input, event, msg); event.getAudioManager().loadTrack(input, event, msg);
} catch (Exception ignore) { } catch (Exception ignore) {
Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, Message msg = event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.music.play.load.title", "", "commands.music.play.load.title", "",
"commands.music.play.load.description", "").build()).complete(); "commands.music.play.load.description", "").build()).complete();
new AudioManager().loadTrack("ytsearch: " + input, event, msg); event.getAudioManager().loadTrack("ytsearch: " + input, event, msg);
} }
} else { } else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(

View file

@ -1,11 +1,9 @@
package com.bbn.hadder.commands.music; package com.bbn.hadder.commands.music;
import com.bbn.hadder.audio.AudioInfo; import com.bbn.hadder.audio.AudioInfo;
import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.utils.MessageEditor; import com.bbn.hadder.utils.MessageEditor;
import net.dv8tion.jda.api.EmbedBuilder;
import java.util.Set; import java.util.Set;
@ -17,21 +15,20 @@ public class QueueCommand implements Command {
@Override @Override
public void executed(String[] args, CommandEvent event) { public void executed(String[] args, CommandEvent event) {
if (!new AudioManager().hasPlayer(event.getGuild()) || new AudioManager().getTrackManager(event.getGuild()).getQueuedTracks().isEmpty()) { if (!event.getAudioManager().hasPlayer(event.getGuild()) || event.getAudioManager().getTrackManager(event.getGuild()).getQueuedTracks().isEmpty()) {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.WARNING, event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.WARNING,
"commands.music.queue.error.title", "commands.music.queue.error.title",
"commands.music.queue.error.description" "commands.music.queue.error.description"
).build()).queue(); ).build()).queue();
} else { } else {
Set<AudioInfo> queue = new AudioManager().getTrackManager(event.getGuild()).getQueuedTracks(); Set<AudioInfo> queue = event.getAudioManager().getTrackManager(event.getGuild()).getQueuedTracks();
EmbedBuilder b = event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, StringBuilder builder = new StringBuilder();
"commands.music.queue.success.title",
"commands.music.queue.success.description")
.addField("Queued songs", String.valueOf(queue.size()), true);
for (AudioInfo g : queue) { for (AudioInfo g : queue) {
b.addField(g.getTrack().getInfo().author, g.getTrack().getInfo().title, true); builder.append("**").append(g.getTrack().getInfo().author).append("**: `").append(g.getTrack().getInfo().title).append("` \n");
} }
event.getTextChannel().sendMessage(b.build()).queue(); event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.music.queue.success.title", "",
"commands.music.queue.success.description", builder.toString()).build()).queue();
} }
} }
@ -42,7 +39,7 @@ public class QueueCommand implements Command {
@Override @Override
public String description() { public String description() {
return "Shows the music queue."; return "commands.music.queue.help.description";
} }
@Override @Override

View file

@ -1,9 +1,8 @@
package com.bbn.hadder.commands.music; package com.bbn.hadder.commands.music;
import com.bbn.hadder.audio.AudioInfo;
import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.utils.MessageEditor;
/** /**
* @author Skidder / GregTCLTK * @author Skidder / GregTCLTK
@ -13,7 +12,16 @@ public class SkipCommand implements Command {
@Override @Override
public void executed(String[] args, CommandEvent event) { public void executed(String[] args, CommandEvent event) {
if (event.getAudioManager().hasPlayer(event.getGuild()) && !event.getAudioManager().getTrackManager(event.getGuild()).getQueuedTracks().isEmpty()) {
event.getAudioManager().forceSkipTrack(event);
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.music.skip.success.title",
"commands.music.skip.success.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 @Override
@ -23,7 +31,7 @@ public class SkipCommand implements Command {
@Override @Override
public String description() { public String description() {
return "Skips the song"; return "commands.music.skip.help.description";
} }
@Override @Override

View file

@ -1,6 +1,5 @@
package com.bbn.hadder.commands.music; package com.bbn.hadder.commands.music;
import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.utils.MessageEditor; import com.bbn.hadder.utils.MessageEditor;
@ -13,13 +12,19 @@ public class StopCommand implements Command {
@Override @Override
public void executed(String[] args, CommandEvent event) { public void executed(String[] args, CommandEvent event) {
new AudioManager().players.remove(event.getGuild().getId()); if (event.getAudioManager().hasPlayer(event.getGuild()) && event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack() != null) {
new AudioManager().getPlayer(event.getGuild()).destroy(); event.getAudioManager().players.remove(event.getGuild().getId());
new AudioManager().getTrackManager(event.getGuild()).purgeQueue(); event.getAudioManager().getPlayer(event.getGuild()).destroy();
event.getGuild().getAudioManager().closeAudioConnection(); event.getAudioManager().getTrackManager(event.getGuild()).purgeQueue();
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, event.getGuild().getAudioManager().closeAudioConnection();
"commands.music.stop.success.title", event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.music.stop.success.description").build()).queue(); "commands.music.stop.success.title",
"commands.music.stop.success.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 @Override

View file

@ -5,6 +5,7 @@ package com.bbn.hadder.commands.owner;
*/ */
import com.bbn.hadder.Hadder; import com.bbn.hadder.Hadder;
import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.core.Perm; import com.bbn.hadder.core.Perm;
@ -43,6 +44,8 @@ public class EvalCommand implements Command {
engine.put("author", event.getAuthor()); engine.put("author", event.getAuthor());
engine.put("member", event.getMember()); engine.put("member", event.getMember());
engine.put("self", event.getGuild().getSelfMember()); engine.put("self", event.getGuild().getSelfMember());
engine.put("audio", event.getAudioManager());
engine.put("out", System.out);
ScheduledExecutorService service = Executors.newScheduledThreadPool(1); ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
@ -52,12 +55,12 @@ public class EvalCommand implements Command {
Object out; Object out;
try { try {
String script = ""; StringBuilder script = new StringBuilder();
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
args[i] = args[i].replace("```java", "").replace("```", ""); args[i] = args[i].replace("```java", "").replace("```", "");
script += i == args.length - 1 ? args[i] : args[i] + " "; script.append(i == args.length - 1 ? args[i] : args[i] + " ");
} }
out = engine.eval(script); out = engine.eval(script.toString());
event.getTextChannel().sendMessage(event.getMessageEditor() event.getTextChannel().sendMessage(event.getMessageEditor()
.getMessage(MessageEditor.MessageType.INFO, "commands.owner.eval.success.title", "") .getMessage(MessageEditor.MessageType.INFO, "commands.owner.eval.success.title", "")

View file

@ -1,6 +1,7 @@
package com.bbn.hadder.core; package com.bbn.hadder.core;
import com.bbn.hadder.Rethink; import com.bbn.hadder.Rethink;
import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.commands.general.HelpCommand; import com.bbn.hadder.commands.general.HelpCommand;
@ -23,7 +24,7 @@ public class CommandHandler {
this.helpCommand = helpCommand; this.helpCommand = helpCommand;
} }
public void handle(MessageReceivedEvent event, Rethink rethink, String prefix) { public void handle(MessageReceivedEvent event, Rethink rethink, String prefix, AudioManager audioManager) {
String invoke = event.getMessage().getContentRaw().replaceFirst(prefix, "").split(" ")[0]; String invoke = event.getMessage().getContentRaw().replaceFirst(prefix, "").split(" ")[0];
for (Command cmd : commandList) { for (Command cmd : commandList) {
for (String label : cmd.labels()) { for (String label : cmd.labels()) {
@ -35,7 +36,7 @@ public class CommandHandler {
if (args.length > 0 && args[0].equals("")) args = new String[0]; if (args.length > 0 && args[0].equals("")) args = new String[0];
CommandEvent commandEvent = new CommandEvent(event.getJDA(), event.getResponseNumber(), event.getMessage(), rethink, CommandEvent commandEvent = new CommandEvent(event.getJDA(), event.getResponseNumber(), event.getMessage(), rethink,
config, this, helpCommand, new MessageEditor(rethink, event.getAuthor()), new EventWaiter()); config, this, helpCommand, new MessageEditor(rethink, event.getAuthor()), new EventWaiter(), audioManager);
if (cmd.getClass().getAnnotations().length > 0 && !Arrays.asList(cmd.getClass().getAnnotations()).contains(Perms.class)) { if (cmd.getClass().getAnnotations().length > 0 && !Arrays.asList(cmd.getClass().getAnnotations()).contains(Perms.class)) {
for (Perm perm : cmd.getClass().getAnnotation(Perms.class).value()) { for (Perm perm : cmd.getClass().getAnnotation(Perms.class).value()) {
if (!perm.check(commandEvent)) { if (!perm.check(commandEvent)) {

View file

@ -1,6 +1,7 @@
package com.bbn.hadder.listener; package com.bbn.hadder.listener;
import com.bbn.hadder.Rethink; import com.bbn.hadder.Rethink;
import com.bbn.hadder.audio.AudioManager;
import com.bbn.hadder.core.CommandHandler; import com.bbn.hadder.core.CommandHandler;
import net.dv8tion.jda.api.entities.ChannelType; import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -14,10 +15,12 @@ public class CommandListener extends ListenerAdapter {
private Rethink rethink; private Rethink rethink;
private CommandHandler handler; private CommandHandler handler;
private AudioManager audioManager;
public CommandListener(Rethink rethink, CommandHandler handler) { public CommandListener(Rethink rethink, CommandHandler handler, AudioManager audioManager) {
this.rethink = rethink; this.rethink = rethink;
this.handler = handler; this.handler = handler;
this.audioManager = audioManager;
} }
@Override @Override
@ -31,7 +34,7 @@ public class CommandListener extends ListenerAdapter {
}; };
for (String prefix : prefixes) { for (String prefix : prefixes) {
if (event.getMessage().getContentRaw().startsWith(prefix)) { if (event.getMessage().getContentRaw().startsWith(prefix)) {
handler.handle(event, rethink, prefix); handler.handle(event, rethink, prefix, audioManager);
return; return;
} }
} }

View file

@ -0,0 +1,28 @@
package com.bbn.hadder.listener;
import com.bbn.hadder.audio.AudioManager;
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
/**
* @author Skidder / GregTCLTK
*/
public class VoiceLeaveListener extends ListenerAdapter {
private AudioManager audioManager;
public VoiceLeaveListener(AudioManager audioManager) {
this.audioManager = audioManager;
}
@Override
public void onGuildVoiceLeave(GuildVoiceLeaveEvent event) {
if (new AudioManager().hasPlayer(event.getGuild()) && event.getChannelLeft().getMembers().equals(event.getGuild().getSelfMember())) {
audioManager.players.remove(event.getGuild().getId());
audioManager.getPlayer(event.getGuild()).destroy();
audioManager.getTrackManager(event.getGuild()).purgeQueue();
event.getGuild().getAudioManager().closeAudioConnection();
}
}
}

View file

@ -24,21 +24,21 @@ public class MessageEditor {
return this.getMessage(type, "", "", "", "", "", ""); return this.getMessage(type, "", "", "", "", "", "");
} }
public EmbedBuilder getMessage(MessageType type, String title_language_string, String description_language_string) { public EmbedBuilder getMessage(MessageType type, String title, String description) {
return this.getMessage(type, title_language_string, "", "", description_language_string, "", ""); return this.getMessage(type, title, "", "", description, "", "");
} }
public EmbedBuilder getMessage(MessageType type, String title_language_string, String title_extra, public EmbedBuilder getMessage(MessageType type, String title, String title_extra,
String description_language_string, String description_extra) { String description, String description_extra) {
return this.getMessage(type, title_language_string, title_extra, "", description_language_string, description_extra, ""); return this.getMessage(type, title, title_extra, "", description, description_extra, "");
} }
public EmbedBuilder getMessage(MessageType type, String title_language_string, String title_extra, String title_extra_two, public EmbedBuilder getMessage(MessageType type, String title, String title_extra, String title_extra_two,
String description_language_string, String description_extra, String description_extra_two) { String description, String description_extra, String description_extra_two) {
String language = (this.user!=null) ? rethink.getLanguage(this.user.getId()) : null; String language = (this.user!=null) ? rethink.getLanguage(this.user.getId()) : null;
EmbedBuilder eb = this.getDefaultSettings(type); EmbedBuilder eb = this.getDefaultSettings(type);
if (!title_language_string.equals("")) eb.setTitle(this.handle(language, title_language_string, title_extra, title_extra_two)); if (!title.equals("")) eb.setTitle(this.handle(language, title, title_extra, title_extra_two));
if (!description_language_string.equals("")) eb.setDescription(this.handle(language, description_language_string, description_extra, description_extra_two)); if (!description.equals("")) eb.setDescription(this.handle(language, description, description_extra, description_extra_two));
return eb; return eb;
} }
@ -122,7 +122,7 @@ public class MessageEditor {
Locale locale = new Locale(language_code); Locale locale = new Locale(language_code);
ResourceBundle resourceBundle = ResourceBundle.getBundle("Translations/Translations", locale); ResourceBundle resourceBundle = ResourceBundle.getBundle("Translations/Translations", locale);
if (resourceBundle.containsKey(string)) if (resourceBundle.containsKey(string))
return resourceBundle.getString(string).replaceAll("%prefix%", "h.").replaceAll("%extra%", extra).replaceAll("%extra_two%", extra_two); return resourceBundle.getString(string).replaceAll("%extra%", extra).replaceAll("%extra_two%", extra_two);
else return "This key doesn't exist. Please report this to the Bot Developers. Key: "+string+" Language_code: "+language_code; else return "This key doesn't exist. Please report this to the Bot Developers. Key: " + string + " Language_code: " + language_code;
} }
} }

View file

@ -84,7 +84,7 @@ commands.misc.screenshare.channel.existing.error = Hol' up
commands.misc.screenshare.channel.existing.description = There is no Voice Channel named like this. \n\nNote\: Make sure the Voice Channel is in this Guild. commands.misc.screenshare.channel.existing.description = There is no Voice Channel named like this. \n\nNote\: Make sure the Voice Channel is in this Guild.
commands.misc.screenshare.help.description = Shows you the link to share your screen. commands.misc.screenshare.help.description = Shows you the link to share your screen.
commands.moderation.ban.success.title = %extra% Successfully banned %extra% commands.moderation.ban.success.title = Successfully banned
commands.moderation.ban.success.description = I successfully baned %extra% commands.moderation.ban.success.description = I successfully baned %extra%
commands.moderation.ban.error.title = Not possible commands.moderation.ban.error.title = Not possible
commands.moderation.ban.myself.error.description = I can not ban myself\! commands.moderation.ban.myself.error.description = I can not ban myself\!
@ -179,9 +179,9 @@ commands.moderation.editrules.help.description = Edits the rules message.
commands.music.join.success.title = Successfully connected commands.music.join.success.title = Successfully connected
commands.music.join.success.description = I successfully connected to %extra%. commands.music.join.success.description = I successfully connected to %extra%.
commands.music.join.error.connecting.already.title = Already connected commands.music.join.error.connecting.already.title = Already connected
commands.music.join.error.connecting.already.description = I am already connected to your voice channel. commands.music.join.error.connecting.already.description = I am already connected to your voice channel
commands.music.join.error.connecting.trying.title = Already trying to connect commands.music.join.error.connecting.trying.title = Already trying to connect
commands.music.join.error.connecting.trying.description = Hadder is already trying to connect. Please wait a moment. commands.music.join.error.connecting.trying.description = Hadder is already trying to connect. Please wait a moment
commands.music.join.error.channel.title = No Voice Channel commands.music.join.error.channel.title = No Voice Channel
commands.music.join.error.channel.description = You aren't in a Voice Channel. commands.music.join.error.channel.description = You aren't in a Voice Channel.
commands.music.join.help.description = Joins your voice channel commands.music.join.help.description = Joins your voice channel
@ -193,39 +193,48 @@ commands.music.leave.help.description = Leaves a voice channel
commands.music.play.load.title = %extra% Now loading %extra% commands.music.play.load.title = %extra% Now loading %extra%
commands.music.play.load.description = Trying to load the song... commands.music.play.load.description = Trying to load the song...
commands.music.play.success.loading.title = %extra% Now playing %extra% commands.music.play.success.loading.title = %extra% Now playing %extra%
commands.music.play.error.load.title = %extra% Load failed %extra%
commands.music.play.error.load.description = Unfortunately I can not load the given song.
commands.music.play.error.match.title = %extra% No matches %extra%
commands.music.play.error.match.description = I can not find a song named this on YouTube.
commands.music.play.success.title = Title commands.music.play.success.title = Title
commands.music.play.success.author = Author commands.music.play.success.author = Author
commands.music.play.success.length = Length commands.music.play.success.length = Length
commands.music.play.success.tracks = Tracks
commands.music.play.error.load.title = %extra% Load failed %extra%
commands.music.play.error.load.description = Unfortunately I can not load the given song
commands.music.play.error.match.title = %extra% No matches %extra%
commands.music.play.error.match.description = I can not find a song named this on YouTube
commands.music.play.help.description = Plays a song commands.music.play.help.description = Plays a song
commands.music.stop.success.title = Successfully stopped commands.music.stop.success.title = Successfully stopped
commands.music.stop.success.description = I successfully stopped the song. commands.music.stop.success.description = I successfully stopped the song.
commands.music.info.success.title = Track info
commands.music.info.error.title = No playing track
commands.music.info.error.description = I am not playing anything at the moment
commands.music.info.help.description = Shows information about the playing song
commands.music.stop.help.description = Stops the song commands.music.stop.help.description = Stops the song
commands.music.queue.error.title = No queue commands.music.queue.error.title = No queue
commands.music.queue.error.description = There are no queued songs at the moment commands.music.queue.error.description = There are no queued songs at the moment
commands.music.queue.success.title = Queue commands.music.queue.success.title = Queue
commands.music.queue.success.description = This is the queue\: %extra% commands.music.queue.success.description = This is the queue\: \n %extra%
commands.music.queue.help.description = Shows the music queue
commands.music.skip.success.title = Successfully skipped
commands.music.skip.success.description = I successfully skipped to the next song
commands.music.skip.help.description = Skips the currently playing song
commands.nsfw.gif.error.title = GIF not showing? Click here commands.nsfw.gif.error.title = GIF not showing? Click here
commands.nsfw.img.error.title = Image not showing? Click here commands.nsfw.img.error.title = Image not showing? Click here
commands.nsfw.anal.help.description = Shows a random anal gif. commands.nsfw.anal.help.description = Shows a random anal gif
commands.nsfw.bdsm.help.description = Shows a random BDSM picture. commands.nsfw.bdsm.help.description = Shows a random BDSM picture
commands.nsfw.blowjob.help.description = Shows a random Blowjob picture. commands.nsfw.blowjob.help.description = Shows a random Blowjob picture
commands.nsfw.boobs.help.description = Shows a random boob gif. commands.nsfw.boobs.help.description = Shows a random boob gif
commands.nsfw.cum.help.description = Shows a random cum gif. commands.nsfw.cum.help.description = Shows a random cum gif
commands.nsfw.erotic.help.description = Shows a random erotic picture. commands.nsfw.erotic.help.description = Shows a random erotic picture
commands.nsfw.feet.help.description = Shows a random feet gif. commands.nsfw.feet.help.description = Shows a random feet gif
commands.nsfw.fingering.help.description = Shows a random fingering gif. commands.nsfw.fingering.help.description = Shows a random fingering gif
commands.nsfw.linking.help.description = Shows a random licking gif. commands.nsfw.linking.help.description = Shows a random licking gif
commands.nsfw.porn.help.description = Shows a random porn gif. commands.nsfw.porn.help.description = Shows a random porn gif
commands.nsfw.pussy.help.description = Shows a random pussy gif. commands.nsfw.pussy.help.description = Shows a random pussy gif
commands.nsfw.randomporn.help.description = Shows a completely random porn gif. commands.nsfw.randomporn.help.description = Shows a completely random porn gif
commands.nsfw.solo.help.description = Shows a random solo gif. commands.nsfw.solo.help.description = Shows a random solo gif
commands.nsfw.spank.help.description = Shows a random spank gif. commands.nsfw.spank.help.description = Shows a random spank gif
commands.nsfw.trans.help.description = Shows a random trans picture. commands.nsfw.trans.help.description = Shows a random trans picture
commands.owner.eval.success.title = Eval Command commands.owner.eval.success.title = Eval Command
commands.owner.eval.success.input = Input commands.owner.eval.success.input = Input