Fixed downvote skipping, added usage of command tag.

This commit is contained in:
Andrew Lalis 2017-06-30 13:50:40 +02:00
parent fb430ebf5b
commit e29c3d7701
5 changed files with 19 additions and 8 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.github.andrewlalis</groupId> <groupId>com.github.andrewlalis</groupId>
<artifactId>HandieBot</artifactId> <artifactId>HandieBot</artifactId>
<version>1.3.0</version> <version>1.3.1</version>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>

View File

@ -50,22 +50,24 @@ public class Commands {
for (Command cmd : commands) { for (Command cmd : commands) {
if (cmd.getName().equals(command)){ if (cmd.getName().equals(command)){
if (cmd instanceof StaticCommand){ if (cmd instanceof StaticCommand){
log.log(BotLog.TYPE.COMMAND, command+" has been issued.");
((StaticCommand)cmd).execute(); ((StaticCommand)cmd).execute();
return; return;
} else if (!cmd.canUserExecute(context.getUser(), context.getGuild())){ } else if (!cmd.canUserExecute(context.getUser(), context.getGuild())){
log.log(BotLog.TYPE.ERROR, context.getGuild(), MessageFormat.format(resourceBundle.getString("commands.noPermission.log"), context.getUser().getName(), cmd.getName())); log.log(BotLog.TYPE.COMMAND, context.getGuild(), MessageFormat.format(resourceBundle.getString("commands.noPermission.log"), context.getUser().getName(), cmd.getName()));
context.getChannel().sendMessage(MessageFormat.format(resourceBundle.getString("commands.noPermission.message"), command)); context.getChannel().sendMessage(MessageFormat.format(resourceBundle.getString("commands.noPermission.message"), command));
return; return;
} else if (cmd instanceof ContextCommand){ } else if (cmd instanceof ContextCommand){
log.log(BotLog.TYPE.COMMAND, context.getGuild(), context.getUser().getName()+" has issued the command: "+command);
((ContextCommand)cmd).execute(context); ((ContextCommand)cmd).execute(context);
return; return;
} }
} }
} }
if (context == null){ if (context == null){
log.log(BotLog.TYPE.ERROR, MessageFormat.format(resourceBundle.getString("commands.invalidCommand.noContext"), command)); log.log(BotLog.TYPE.COMMAND, MessageFormat.format(resourceBundle.getString("commands.invalidCommand.noContext"), command));
} else { } else {
log.log(BotLog.TYPE.ERROR, context.getGuild(), MessageFormat.format(resourceBundle.getString("commands.invalidCommand.context"), command, context.getUser().getName())); log.log(BotLog.TYPE.COMMAND, context.getGuild(), MessageFormat.format(resourceBundle.getString("commands.invalidCommand.context"), command, context.getUser().getName()));
} }
} }

View File

@ -1,6 +1,7 @@
package handiebot.command; package handiebot.command;
import handiebot.HandieBot; import handiebot.HandieBot;
import handiebot.view.BotLog;
import sx.blah.discord.handle.impl.events.guild.channel.message.reaction.ReactionEvent; import sx.blah.discord.handle.impl.events.guild.channel.message.reaction.ReactionEvent;
import sx.blah.discord.handle.obj.IMessage; import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IReaction; import sx.blah.discord.handle.obj.IReaction;
@ -8,12 +9,14 @@ import sx.blah.discord.handle.obj.IUser;
import java.util.List; import java.util.List;
import static handiebot.HandieBot.log;
/** /**
* @author Andrew Lalis * @author Andrew Lalis
* Class which handles user reactions to songs and performs necessary actions. * Class which handles user reactions to songs and performs necessary actions.
*/ */
public class ReactionHandler { public class ReactionHandler {
//TODO: Fix so only reactions on the most recent song count!
public static final String thumbsUp = "\uD83D\uDC4D"; public static final String thumbsUp = "\uD83D\uDC4D";
public static final String thumbsDown = "\uD83D\uDC4E"; public static final String thumbsDown = "\uD83D\uDC4E";
@ -38,7 +41,12 @@ public class ReactionHandler {
* @param message The messages that received a reaction. * @param message The messages that received a reaction.
*/ */
private static void onDownvote(CommandContext context, IMessage message){ private static void onDownvote(CommandContext context, IMessage message){
//Filter out reactions to previous messages.
if (!message.getContent().contains(HandieBot.musicPlayer.getMusicManager(context.getGuild()).scheduler.getPlayingTrack().getTitle())){
return;
}
List<IUser> usersHere = HandieBot.musicPlayer.getVoiceChannel(context.getGuild()).getConnectedUsers(); List<IUser> usersHere = HandieBot.musicPlayer.getVoiceChannel(context.getGuild()).getConnectedUsers();
//Remove the bot from the list of users in the voice channel.
usersHere.removeIf(user -> user.getLongID() == HandieBot.client.getOurUser().getLongID()); usersHere.removeIf(user -> user.getLongID() == HandieBot.client.getOurUser().getLongID());
int userCount = usersHere.size(); int userCount = usersHere.size();
int userDownvotes = 0; int userDownvotes = 0;
@ -48,8 +56,8 @@ public class ReactionHandler {
userDownvotes++; userDownvotes++;
} }
} }
System.out.println("Valid downvotes: "+userDownvotes+" out of "+userCount+" people present.");
if (userDownvotes > (userCount/2)){ if (userDownvotes > (userCount/2)){
log.log(BotLog.TYPE.MUSIC, context.getGuild(), "Users voted to skip the current song.");
HandieBot.musicPlayer.skipTrack(context.getGuild()); HandieBot.musicPlayer.skipTrack(context.getGuild());
} else if (userDownvotes > 0) { } else if (userDownvotes > 0) {
context.getChannel().sendMessage((((userCount/2)+1) - userDownvotes)+" more people must downvote before the track is skipped."); context.getChannel().sendMessage((((userCount/2)+1) - userDownvotes)+" more people must downvote before the track is skipped.");

View File

@ -9,6 +9,7 @@ import handiebot.lavaplayer.playlist.UnloadedTrack;
import handiebot.utils.DisappearingMessage; import handiebot.utils.DisappearingMessage;
import handiebot.view.BotLog; import handiebot.view.BotLog;
import sx.blah.discord.handle.obj.IChannel; import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.util.RequestBuffer;
import java.io.File; import java.io.File;
import java.text.MessageFormat; import java.text.MessageFormat;
@ -159,7 +160,7 @@ public class PlaylistCommand extends ContextCommand {
playlist.load(); playlist.load();
for (int i = 2; i < context.getArgs().length; i++){ for (int i = 2; i < context.getArgs().length; i++){
playlist.loadTrack(context.getArgs()[i]); playlist.loadTrack(context.getArgs()[i]);
context.getChannel().sendMessage(MessageFormat.format(resourceBundle.getString("commands.command.playlist.add.message"), playlist.getName())); RequestBuffer.request(() -> context.getChannel().sendMessage(MessageFormat.format(resourceBundle.getString("commands.command.playlist.add.message"), playlist.getName()))).get();
} }
playlist.save(); playlist.save();
context.getChannel().sendMessage(playlist.toString()); context.getChannel().sendMessage(playlist.toString());

View File

@ -159,7 +159,7 @@ public class Playlist {
*/ */
public void load(){ public void load(){
String path = System.getProperty("user.home")+"/.handiebot/playlist/"+name.replace(" ", "_")+".txt"; String path = System.getProperty("user.home")+"/.handiebot/playlist/"+name.replace(" ", "_")+".txt";
log.log(BotLog.TYPE.INFO, "Loading playlist from: "+path); log.log(BotLog.TYPE.MUSIC, "Loading playlist from: "+path);
File playlistFile = new File(path); File playlistFile = new File(path);
if (playlistFile.exists()){ if (playlistFile.exists()){
try { try {