Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to allow forceremove on users that have left a channel #1354

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added JMusicBot-0.3.9.jar
Binary file not shown.
Empty file modified scripts/run_jmusicbot.sh
100644 → 100755
Empty file.
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/main/.DS_Store
Binary file not shown.
68 changes: 36 additions & 32 deletions src/main/java/com/jagrosh/jmusicbot/commands/dj/ForceRemoveCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@

import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.commons.utils.FinderUtil;
import com.jagrosh.jdautilities.menu.OrderedMenu;
import com.jagrosh.jmusicbot.Bot;
import com.jagrosh.jmusicbot.audio.AudioHandler;
import com.jagrosh.jmusicbot.commands.DJCommand;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;

import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;

/**
*
Expand Down Expand Up @@ -63,45 +60,52 @@ public void doCommand(CommandEvent event)
}


User target;
List<Member> found = FinderUtil.findMembers(event.getArgs(), event.getGuild());
User target = findUser(event.getArgs());

if(found.isEmpty())
if (target == null)
{
event.replyError("Unable to find the user!");
return;
}
else if(found.size()>1)
{
OrderedMenu.Builder builder = new OrderedMenu.Builder();
for(int i=0; i<found.size() && i<4; i++)
{
Member member = found.get(i);
builder.addChoice("**"+member.getUser().getName()+"**#"+member.getUser().getDiscriminator());
}

builder
.setSelection((msg, i) -> removeAllEntries(found.get(i-1).getUser(), event))
.setText("Found multiple users:")
.setColor(event.getSelfMember().getColor())
.useNumbers()
.setUsers(event.getAuthor())
.useCancelButton(true)
.setCancel((msg) -> {})
.setEventWaiter(bot.getWaiter())
.setTimeout(1, TimeUnit.MINUTES)
removeAllEntries(target, event);

.build().display(event.getChannel());
}

return;
private User findUser(String query)
{
Matcher userMention = FinderUtil.USER_MENTION.matcher(query);
Matcher fullRefMatch = FinderUtil.FULL_USER_REF.matcher(query);
Matcher discordIdMatch = FinderUtil.DISCORD_ID.matcher(query);
if(userMention.matches() || discordIdMatch.matches())
{
String stringId;
if (userMention.matches())
{
stringId = query.replaceAll("[^0-9]", "");
}
else
{
stringId = query;
}
long userId;
try
{
userId = Long.parseLong(stringId);
}
catch (NumberFormatException e)
{
return null;
}
return bot.getJDA().retrieveUserById(userId).complete();
}
else
else if(fullRefMatch.matches())
{
target = found.get(0).getUser();
String username = fullRefMatch.group(1).toLowerCase() + "#" + fullRefMatch.group(2);

return bot.getJDA().getUserByTag(username);
}

removeAllEntries(target, event);

return null;
}

private void removeAllEntries(User target, CommandEvent event)
Expand Down
Binary file added src/test/.DS_Store
Binary file not shown.