Merge pull request #303 from BigBotNetwork/greg-dev

Merged!
This commit is contained in:
Skidder 2020-01-04 14:42:57 +01:00 committed by GitHub
commit 0e77468d6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 111 additions and 51 deletions

View file

@ -11,6 +11,7 @@ import com.bbn.hadder.commands.settings.*;
import com.bbn.hadder.commands.music.*; import com.bbn.hadder.commands.music.*;
import com.bbn.hadder.core.*; import com.bbn.hadder.core.*;
import com.bbn.hadder.listener.*; import com.bbn.hadder.listener.*;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder; import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder;
import net.dv8tion.jda.api.sharding.ShardManager; import net.dv8tion.jda.api.sharding.ShardManager;
@ -39,6 +40,7 @@ public class Hadder {
builder.setAutoReconnect(true); builder.setAutoReconnect(true);
builder.setShardsTotal(1); builder.setShardsTotal(1);
builder.setActivity(Activity.streaming("on the BigBotNetwork", "https://twitch.tv/BigBotNetwork")); builder.setActivity(Activity.streaming("on the BigBotNetwork", "https://twitch.tv/BigBotNetwork"));
builder.setStatus(OnlineStatus.DO_NOT_DISTURB);
builder.setToken(config.getBotToken()); builder.setToken(config.getBotToken());
HelpCommand helpCommand = new HelpCommand(); HelpCommand helpCommand = new HelpCommand();

View file

@ -4,6 +4,7 @@ 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.entities.VoiceChannel; import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
/* /*
@ -20,15 +21,22 @@ public class JoinCommand implements Command {
VoiceChannel vc = event.getMember().getVoiceState().getChannel(); VoiceChannel vc = event.getMember().getVoiceState().getChannel();
if (event.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) { if (event.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) {
if (!event.getGuild().getSelfMember().getVoiceState().getChannel().getId().equals(vc.getId())) { if (!event.getGuild().getSelfMember().getVoiceState().getChannel().getId().equals(vc.getId())) {
event.getGuild().getAudioManager().openAudioConnection(vc); try {
event.getTextChannel().sendMessage( event.getGuild().getAudioManager().openAudioConnection(vc);
event.getMessageEditor().getMessage( event.getTextChannel().sendMessage(
MessageEditor.MessageType.INFO, event.getMessageEditor().getMessage(
"commands.music.join.success.title", MessageEditor.MessageType.INFO,
"", "commands.music.join.success.title",
"commands.music.join.success.description", "",
vc.getName()) "commands.music.join.success.description",
.build()).queue(); vc.getName())
.build()).queue();
} catch (InsufficientPermissionException e) {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
"commands.music.join.error.permission.title",
"commands.music.join.error.permission.description")
.build()).queue();
}
} else { } else {
event.getTextChannel().sendMessage( event.getTextChannel().sendMessage(
event.getMessageEditor().getMessage( event.getMessageEditor().getMessage(
@ -38,12 +46,19 @@ public class JoinCommand implements Command {
.build()).queue(); .build()).queue();
} }
} else { } else {
event.getGuild().getAudioManager().openAudioConnection(vc); try {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( event.getGuild().getAudioManager().openAudioConnection(vc);
MessageEditor.MessageType.INFO, event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
"commands.music.join.success.title", "", MessageEditor.MessageType.INFO,
"commands.music.join.success.description", vc.getName()) "commands.music.join.success.title", "",
.build()).queue(); "commands.music.join.success.description", vc.getName())
.build()).queue();
} catch (InsufficientPermissionException e) {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
"commands.music.join.error.permission.title",
"commands.music.join.error.permission.description")
.build()).queue();
}
} }
} else { } else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(

View file

@ -13,17 +13,24 @@ public class LeaveCommand implements Command {
@Override @Override
public void executed(String[] args, CommandEvent event) { public void executed(String[] args, CommandEvent event) {
if (event.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) { if (event.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) {
event.getGuild().getAudioManager().closeAudioConnection(); if (event.getMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().getChannel().equals(event.getMember().getVoiceState().getChannel())) {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( event.getGuild().getAudioManager().closeAudioConnection();
MessageEditor.MessageType.INFO, event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
"commands.music.leave.success.title", MessageEditor.MessageType.INFO,
"commands.music.leave.success.description") "commands.music.leave.success.title",
.build()).queue(); "commands.music.leave.success.description")
.build()).queue();
} else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
"commands.music.leave.error.channel.title",
"commands.music.leave.error.channel.description")
.build()).queue();
}
} else { } else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(
MessageEditor.MessageType.ERROR, MessageEditor.MessageType.ERROR,
"commands.music.leave.error.tile", "commands.music.leave.error.connected.tile",
"commands.music.leave.error.description") "commands.music.leave.error.connected.description")
.build()).queue(); .build()).queue();
} }
} }

View file

@ -4,6 +4,7 @@ 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.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import java.net.URL; import java.net.URL;
@ -24,6 +25,11 @@ public class PlayCommand implements Command {
"commands.music.play.load.title", "", "commands.music.play.load.title", "",
"commands.music.play.load.description", "").build()).complete(); "commands.music.play.load.description", "").build()).complete();
event.getAudioManager().loadTrack(input, event, msg); event.getAudioManager().loadTrack(input, event, msg);
} catch (InsufficientPermissionException e) {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
"commands.music.join.error.permission.title",
"commands.music.join.error.permission.description")
.build()).queue();
} 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", "",

View file

@ -13,10 +13,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()) { if (event.getAudioManager().hasPlayer(event.getGuild()) && !event.getAudioManager().getTrackManager(event.getGuild()).getQueuedTracks().isEmpty()) {
event.getAudioManager().forceSkipTrack(event); if (event.getMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().getChannel().equals(event.getMember().getVoiceState().getChannel())) {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, event.getAudioManager().forceSkipTrack(event);
"commands.music.skip.success.title", event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.music.skip.success.description").build()).queue(); "commands.music.skip.success.title",
"commands.music.skip.success.description").build()).queue();
} else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
"commands.music.skip.error.connected.title",
"commands.music.skip.error.connected.description ").build()).queue();
}
} else { } else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
"commands.music.info.error.title", "commands.music.info.error.title",

View file

@ -13,13 +13,20 @@ public class StopCommand 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().getPlayer(event.getGuild()).getPlayingTrack() != null) { if (event.getAudioManager().hasPlayer(event.getGuild()) && event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack() != null) {
event.getAudioManager().players.remove(event.getGuild().getId()); if (event.getMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().getChannel().equals(event.getMember().getVoiceState().getChannel())) {
event.getAudioManager().getPlayer(event.getGuild()).destroy(); event.getAudioManager().players.remove(event.getGuild().getId());
event.getAudioManager().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.stop.error.connected.title",
"commands.music.stop.error.connected.description")
.build()).queue();
}
} else { } else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
"commands.music.info.error.title", "commands.music.info.error.title",

View file

@ -14,22 +14,29 @@ public class VolumeCommand implements Command {
public void executed(String[] args, CommandEvent event) { public void executed(String[] args, CommandEvent event) {
if (args.length > 0) { if (args.length > 0) {
if (event.getAudioManager().hasPlayer(event.getGuild()) && event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack() != null) { if (event.getAudioManager().hasPlayer(event.getGuild()) && event.getAudioManager().getPlayer(event.getGuild()).getPlayingTrack() != null) {
try { if (event.getMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().inVoiceChannel() && event.getGuild().getSelfMember().getVoiceState().getChannel().equals(event.getMember().getVoiceState().getChannel())) {
int volume = Integer.parseInt(args[0]); try {
if (volume < 201 && volume > 0 || event.getConfig().getOwners().contains(event.getAuthor().getIdLong())) { int volume = Integer.parseInt(args[0]);
event.getAudioManager().getPlayer(event.getGuild()).setVolume(volume); if (volume < 201 && volume > 0 || event.getConfig().getOwners().contains(event.getAuthor().getIdLong())) {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, event.getAudioManager().getPlayer(event.getGuild()).setVolume(volume);
"commands.music.volume.success.title", "", event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.music.volume.success.description", String.valueOf(volume)).build()).queue(); "commands.music.volume.success.title", "",
} else { "commands.music.volume.success.description", String.valueOf(volume)).build()).queue();
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, } else {
"commands.music.volume.error.int.title", event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
"commands.music.volume.error.int.description").build()).queue(); "commands.music.volume.error.int.title",
"commands.music.volume.error.int.description").build()).queue();
}
} catch (NumberFormatException e) {
event.getHelpCommand().sendHelp(this, event);
} catch (Exception e) {
e.printStackTrace();
} }
} catch (NumberFormatException e) { } else {
event.getHelpCommand().sendHelp(this, event); event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
} catch (Exception e) { "commands.music.volume.error.connected.title",
e.printStackTrace(); "commands.volume.stop.error.connected.description")
.build()).queue();
} }
} else { } else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,

View file

@ -178,11 +178,15 @@ 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.error.permission.title = No permission
commands.music.join.error.permission.description = I am not allowed to join your voice channel.
commands.music.join.help.description = Joins your voice channel. commands.music.join.help.description = Joins your voice channel.
commands.music.leave.success.title = Successfully disconnected commands.music.leave.success.title = Successfully disconnected
commands.music.leave.success.description = I successfully disconnected from the Voice Channel commands.music.leave.success.description = I successfully disconnected from the Voice Channel
commands.music.leave.error.tile = Not connected commands.music.leave.error.channel.title = No channel
commands.music.leave.error.description = I'm currently in no Voice Channel on this Guild commands.music.leave.error.channel.description = You have to be in the same voice channel as the bot.
commands.music.leave.error.connected.tile = Not connected
commands.music.leave.error.connected.description = I'm currently in no Voice Channel on this Guild
commands.music.leave.help.description = Leaves your voice channel. commands.music.leave.help.description = Leaves your 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...
@ -198,6 +202,8 @@ commands.music.play.error.match.description = I can not find a song named this o
commands.music.play.help.description = Plays the specified song. commands.music.play.help.description = Plays the specified 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.stop.error.connected.title = No channel
commands.music.stop.error.connected.description = You have to be in the same voice channel as the bot to stop the song.
commands.music.stop.help.description = Stops the song. commands.music.stop.help.description = Stops the song.
commands.music.info.success.title = Track info commands.music.info.success.title = Track info
commands.music.info.error.title = No playing track commands.music.info.error.title = No playing track
@ -210,11 +216,15 @@ commands.music.queue.success.description = This is the queue\: \n %extra%
commands.music.queue.help.description = Shows the music queue. commands.music.queue.help.description = Shows the music queue.
commands.music.skip.success.title = Successfully skipped commands.music.skip.success.title = Successfully skipped
commands.music.skip.success.description = I successfully skipped to the next song commands.music.skip.success.description = I successfully skipped to the next song
commands.music.skip.error.connected.title = No channel
commands.music.skip.error.connected.description = You have to be in the same voice channel as the bot to skip the song.
commands.music.skip.help.description = Skips the currently playing song. commands.music.skip.help.description = Skips the currently playing song.
commands.music.volume.success.title = Successfully set commands.music.volume.success.title = Successfully set
commands.music.volume.success.description = I successfully set the new volume to %extra% commands.music.volume.success.description = I successfully set the new volume to %extra%
commands.music.volume.error.int.title = Invalid number commands.music.volume.error.int.title = Invalid number
commands.music.volume.error.int.description = The volume have to be between 1 and 200 commands.music.volume.error.int.description = The volume have to be between 1 and 200
commands.music.volume.error.connected.title = No channel
commands.music.volume.error.connected.description = You have to be in the same voice channel as the bot to change the volume.
commands.music.volume.help.description = Change the volume of the music. commands.music.volume.help.description = Change the volume of the music.
commands.nsfw.gif.error.title = GIF not showing? Click here commands.nsfw.gif.error.title = GIF not showing? Click here