Skip to content
This repository has been archived by the owner on Jun 18, 2020. It is now read-only.

Commit

Permalink
Fix NPE on private messages
Browse files Browse the repository at this point in the history
  • Loading branch information
darichey committed May 24, 2018
1 parent 09da7a8 commit 427f5e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/darichey/discord/CommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public CommandListener(CommandRegistry registry) {
@Override
public void handle(MessageReceivedEvent event) {
String content = event.getMessage().getContent();
String prefix = registry.getEffectivePrefix(event.getGuild().getLongID());
String prefix = registry.getEffectivePrefix(event.getGuild());

if (content.startsWith(prefix)) {
String prefixRemoved = content.substring(prefix.length());
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/darichey/discord/CommandRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,17 @@ public Optional<String> getPrefixForGuild(long id) {
/**
* Gets the prefix for the given guild. This is either the guild-specific prefix or the default prefix if one is not set.
* @param guild The guild to look up.
* @return The guild-specific prefix for this guild or
* @return The guild-specific prefix for this guild or the default prefix.
*/
public String getEffectivePrefix(IGuild guild) {
return getEffectivePrefix(guild.getLongID());
if (guild == null) return defaultPrefix;
else return getEffectivePrefix(guild.getLongID());
}

/**
* Gets the prefix for the given guild. This is either the guild-specific prefix or the default prefix if one is not set.
* @param id The id of the guild to look up.
* @return The guild-specific prefix for this guild or
* @return The guild-specific prefix for this guild or the default prefix.
*/
public String getEffectivePrefix(long id) {
return getPrefixForGuild(id).orElse(defaultPrefix);
Expand Down

0 comments on commit 427f5e4

Please # to comment.