NPE and 2 cmd fix

This commit is contained in:
Norbi Peti 2019-03-14 16:40:58 +01:00
parent b39a571246
commit 2b4034b05f
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
3 changed files with 10 additions and 9 deletions

View file

@ -122,6 +122,7 @@ public final class DPUtils {
public static ConfigData<IRole> roleData(IHaveConfig config, String key, String defName, IGuild guild) { public static ConfigData<IRole> roleData(IHaveConfig config, String key, String defName, IGuild guild) {
return config.getDataPrimDef(key, defName, name -> { return config.getDataPrimDef(key, defName, name -> {
if (!(name instanceof String)) return null;
val roles = guild.getRolesByName((String) name); val roles = guild.getRolesByName((String) name);
return roles.size() > 0 ? roles.get(0) : null; return roles.size() > 0 ? roles.get(0) : null;
}, IIDLinkedObject::getLongID); }, IIDLinkedObject::getLongID);

View file

@ -22,22 +22,22 @@ import java.util.stream.Collectors;
}) })
public class UserinfoCommand extends ICommand2DC { public class UserinfoCommand extends ICommand2DC {
@Command2.Subcommand @Command2.Subcommand
public boolean def(Command2DCSender sender, @Command2.OptionalArg String args) { public boolean def(Command2DCSender sender, @Command2.OptionalArg @Command2.TextArg String user) {
val message = sender.getMessage(); val message = sender.getMessage();
IUser target = null; IUser target = null;
if (args == null || args.length() == 0) if (user == null || user.length() == 0)
target = message.getAuthor(); target = message.getAuthor();
else { else {
final Optional<IUser> firstmention = message.getMentions().stream() final Optional<IUser> firstmention = message.getMentions().stream()
.filter(m -> !m.getStringID().equals(DiscordPlugin.dc.getOurUser().getStringID())).findFirst(); .filter(m -> !m.getStringID().equals(DiscordPlugin.dc.getOurUser().getStringID())).findFirst();
if (firstmention.isPresent()) if (firstmention.isPresent())
target = firstmention.get(); target = firstmention.get();
else if (args.contains("#")) { else if (user.contains("#")) {
String[] targettag = args.split("#"); String[] targettag = user.split("#");
final List<IUser> targets = getUsers(message, targettag[0]); final List<IUser> targets = getUsers(message, targettag[0]);
if (targets.size() == 0) { if (targets.size() == 0) {
DiscordPlugin.sendMessageToChannel(message.getChannel(), DiscordPlugin.sendMessageToChannel(message.getChannel(),
"The user cannot be found (by name): " + args); "The user cannot be found (by name): " + user);
return true; return true;
} }
for (IUser ptarget : targets) { for (IUser ptarget : targets) {
@ -48,15 +48,15 @@ public class UserinfoCommand extends ICommand2DC {
} }
if (target == null) { if (target == null) {
DiscordPlugin.sendMessageToChannel(message.getChannel(), DiscordPlugin.sendMessageToChannel(message.getChannel(),
"The user cannot be found (by discriminator): " + args + "(Found " + targets.size() "The user cannot be found (by discriminator): " + user + "(Found " + targets.size()
+ " users with the name.)"); + " users with the name.)");
return true; return true;
} }
} else { } else {
final List<IUser> targets = getUsers(message, args); final List<IUser> targets = getUsers(message, user);
if (targets.size() == 0) { if (targets.size() == 0) {
DiscordPlugin.sendMessageToChannel(message.getChannel(), DiscordPlugin.sendMessageToChannel(message.getChannel(),
"The user cannot be found on Discord: " + args); "The user cannot be found on Discord: " + user);
return true; return true;
} }
if (targets.size() > 1) { if (targets.size() > 1) {

View file

@ -18,7 +18,7 @@ import lombok.val;
public class MCChatCommand extends ICommand2DC { public class MCChatCommand extends ICommand2DC {
@Command2.Subcommand @Command2.Subcommand
public boolean def(Command2DCSender sender, String args) { public boolean def(Command2DCSender sender) {
val message = sender.getMessage(); val message = sender.getMessage();
if (!message.getChannel().isPrivate()) { if (!message.getChannel().isPrivate()) {
message.reply("this command can only be issued in a direct message with the bot."); message.reply("this command can only be issued in a direct message with the bot.");