Skip to content

Commit

Permalink
Merge pull request #54 from nano-devs/help-command-detail
Browse files Browse the repository at this point in the history
(Major changes) Help command detail & Guild Settings & other minor fix
  • Loading branch information
madeyoga authored Nov 10, 2020
2 parents 76ab4f2 + 76ad43b commit eaa29ae
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 18 deletions.
11 changes: 11 additions & 0 deletions src/main/java/command/CustomAbstractCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package command;

import com.jagrosh.jdautilities.command.Command;

public abstract class CustomAbstractCommand extends Command {
protected String example;

public String getExample() {
return example;
}
}
8 changes: 4 additions & 4 deletions src/main/java/command/LyricCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import org.json.JSONObject;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import net.dv8tion.jda.api.EmbedBuilder;
import service.music.CustomEmbedBuilder;
import service.music.GuildMusicManager;
import service.music.HelpProcess;

import java.awt.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
Expand All @@ -34,8 +35,7 @@ public LyricCommand(NanoClient client)
@Override
protected void execute(CommandEvent event)
{
EmbedBuilder embed = new EmbedBuilder();
embed.setColor(event.getMember().getColor());
CustomEmbedBuilder embed = new CustomEmbedBuilder();
GuildMusicManager musicManager = this.client.getGuildAudioPlayer(event.getGuild());
String query = "";

Expand Down Expand Up @@ -74,7 +74,7 @@ else if (event.getArgs().trim().equals("") && musicManager.player.getPlayingTrac
{
embed.clear();
embed.setTitle("Failed");
embed.setColor(event.getMember().getColor());
embed.setColor(new Color(211, 0, 137));
embed.addField(
":x:",
"Can't find lyric.",
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/command/RecommendationCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ public RecommendationCommand(NanoClient nanoClient, YoutubeClient youtubeClient)
this.youtubeClient = youtubeClient;

this.name = "recommend";
this.arguments = "<number>";
this.aliases = new String[] {"play_recommendation", "pr", "play_r"};
this.arguments = "<a number in range 1-24>";
this.aliases = new String[] {"play_recommendation", "pr", "play_r", "rec"};
this.category = new Category("Music");
this.cooldown = 2;
this.guildOnly = true;
this.help = "Add song recommendation (based on current playing song) to queue\n" +
":warning: Using `m$recommend` on the same song might result the same recommendation.";
this.help = "Add song recommendation (based on currently playing song) to queue\n" +
":warning: Using this command twice or multiple times on the same song " +
"might result the same recommendation.";
this.help = HelpProcess.getHelp(this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/command/ShowGuildStateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ShowGuildStateCommand(NanoClient nanoClient) {
this.nanoClient = nanoClient;

this.name = "guild_state";
this.help = "Show song queue & current guild voice state";
this.help = "Show current audio player state and top 7 tracks in queue";
this.aliases = new String[]{"show_guild_state", "gs", "state"};
this.guildOnly = true;
this.cooldown = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/command/ShowPaginatedQueueCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ShowPaginatedQueueCommand extends Command {

public ShowPaginatedQueueCommand(NanoClient nanoClient) {
this.name = "queue";
this.help = "Show song queue & current guild voice state";
this.help = "Show paginated song queue";
this.aliases = new String[]{"show_queue", "q", "sq", "pq"};
this.guildOnly = true;
this.nanoClient = nanoClient;
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/command/YoutubeSearchCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public YoutubeSearchCommand(NanoClient nano, YoutubeClient youtubeClient)
this.aliases = new String[]{"yts", "s"};
this.guildOnly = true;
this.cooldown = 2;
this.help = "Search youtube video with specific keyword.";
this.arguments = "<keyword>";
this.help = "Search youtube video with specific keyword & select to playback the audio.";
this.arguments = "<keywords>";
this.category = new Category("Music");
this.help = HelpProcess.getHelp(this);
}
Expand Down Expand Up @@ -100,6 +100,9 @@ protected void execute(CommandEvent event)
"[" + video.getTitle() + "]" +
"(" + video.getUrl() + ")";

if (!video.getDuration().equals(""))
output += "[" + video.getDuration() + "]";

// add video data to embed
embed.appendDescription(output + "\n");
}
Expand Down
37 changes: 34 additions & 3 deletions src/main/java/command/general/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,62 @@
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.MessageEmbed;
import service.music.CustomEmbedBuilder;
import service.music.HelpProcess;

import java.awt.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HelpCommand extends Command {

MessageEmbed messageEmbed;
Map<String, Command> commandMap;

public HelpCommand(CommandClient commandClient, JDA jda) {
this.name = "help";
this.aliases = new String[] { "helps" };
this.help = "Shows help & all commands";
this.cooldown = 2;
this.cooldown = 3;
this.category = new Category("General");
this.guildOnly = false;

this.commandMap = new HashMap<>();
this.messageEmbed = this.createHelpMessageEmbed(commandClient, jda);
}

private MessageEmbed createHelpMessageEmbed(CommandClient commandClient, JDA jda) {
List<Command> commands = commandClient.getCommands();

List<Command> commands = commandClient.getCommands();
EmbedBuilder embedBuilder = new CustomEmbedBuilder();

// Theme Color: RGB(211, 0, 137)
embedBuilder.setTitle("Musicfy Commands");
embedBuilder.setDescription("Prefix: `" + commandClient.getPrefix() +
"` | Alternative prefix: `" + commandClient.getAltPrefix() + "` the bot.");

// Temporary memory
Map<String, String> dictionary = new HashMap<>();

for (Command command : commands) {
String currentCategoryName = "**" + command.getCategory().getName() + "**";
String categoryValue = "`" + command.getName() + "`, ";

// Use memory to access the command in the future.
commandMap.put(command.getName(), command);
for (String alias : command.getAliases()) {
commandMap.put(alias, command);
}

// Use the temporary memory for Main Embed
if (currentCategoryName.equals("Owner"))
continue;

if (!dictionary.containsKey(currentCategoryName)) {
dictionary.put(currentCategoryName, categoryValue);
continue;
}

// Append command name to temporary memory
dictionary.put(currentCategoryName, dictionary.get(currentCategoryName) + categoryValue);
}

Expand All @@ -70,6 +82,25 @@ private MessageEmbed createHelpMessageEmbed(CommandClient commandClient, JDA jda

@Override
protected void execute(CommandEvent event) {
if (!event.getArgs().isEmpty()) {
String commandName = event.getArgs();

if (!commandMap.containsKey(commandName)) {
event.reply(":x: | Command with name `" + commandName +
"` does not exist.. please use `" + event.getClient().getPrefix() +
"help` to get the list of command names");
return;
}

Command requestedCommand = commandMap.get(commandName);

event.reply(HelpProcess.getCommandHelpDetail(
requestedCommand,
event.getClient().getPrefix(),
event.getClient().getAltPrefix()).build());

return;
}
event.reply(this.messageEmbed);
}
}
26 changes: 23 additions & 3 deletions src/main/java/service/music/HelpProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,38 @@ public static String getHelp(Command command)
if (command.getAliases() != null && command.getAliases().length > 0)
{
query.append("Alias(es): ");
query.append("`");

for (String alias : command.getAliases())
{
query.append("`");
query.append(prefix + alias);
query.append(" ");
query.append("` ");
}
query.append("`\n");
query.append("\n\n");
}
query.append("*");
query.append(command.getHelp().trim());
query.append("*");
query.append("\n\n");
return query.toString();
}

public static CustomEmbedBuilder getCommandHelpDetail(Command command, String prefix, String altPrefix) {
CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder();

embedBuilder.setTitle(":bookmark: Help | " + command.getName());

embedBuilder.setDescription(command.getHelp());

String arguments = "";
if (command.getArguments() != null) {
arguments = " " + command.getArguments();
}
embedBuilder.addField("Usage",
"```\n" + prefix + command.getName() + arguments + "\n```", false);

embedBuilder.setFooter("For more detail please checkout wiki!");

return embedBuilder;
}
}

0 comments on commit eaa29ae

Please sign in to comment.