82 lines
3.2 KiB
Java
Executable File
82 lines
3.2 KiB
Java
Executable File
package de.sheepstar.globalWrapper.commands;
|
|
|
|
import de.sheepstar.globalWrapper.api.SheepPermission;
|
|
import de.sheepstar.globalWrapper.api.SheepstarGuildCommand;
|
|
import de.sheepstar.globalWrapper.core.Main;
|
|
import net.dv8tion.jda.api.Permission;
|
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
/********************************
|
|
* @author Mathias Wagner
|
|
* Created 12.12.20
|
|
********************************/
|
|
|
|
public class BanUserCommand extends SheepstarGuildCommand {
|
|
@Override
|
|
public List<String> getAlias() {
|
|
return Arrays.asList("banuser", "bu", "userban");
|
|
}
|
|
|
|
@Override
|
|
public SheepPermission getPermission() {
|
|
return SheepPermission.UNKNOWN;
|
|
}
|
|
|
|
@Override
|
|
public void executeCommand(String[] args, GuildMessageReceivedEvent e) {
|
|
if (args.length != 1) return;
|
|
args[0] = replaceUserMention(args[0]);
|
|
int logic=0;
|
|
if (e.getMember().getRoles().contains(Main.getSheepManager().supporterRole) || Main.getSheepManager().botOwners.contains(e.getAuthor().getId())) {
|
|
logic=1;
|
|
} else if (e.getMember().hasPermission(Permission.ADMINISTRATOR)) {
|
|
logic=2;
|
|
}
|
|
|
|
try {
|
|
int finalLogic = logic;
|
|
Main.getInstance().retrieveUserById(args[0]).queue(user -> {
|
|
String userName = user.getAsTag();
|
|
|
|
if (finalLogic == 1) {
|
|
if (!getGlobalManager().isGlobalUserBanned(args[0])) {
|
|
getGlobalManager().banUserGlobal(args[0]);
|
|
sendMessage()
|
|
.setTitle("Sheepstar Ban")
|
|
.setDescription("The User `" + userName + "` got banned.")
|
|
.send(e.getChannel());
|
|
} else {
|
|
sendErrorMessage()
|
|
.setDescription("This User is already banned. Unban with `s!unbanuser <clientID/mention>`")
|
|
.send(e.getChannel());
|
|
}
|
|
} else if (finalLogic == 2) {
|
|
if (!getGlobalManager().isGuildUserBanned(e.getGuild(), args[0])) {
|
|
getGlobalManager().banUserGuild(e.getGuild(), args[0]);
|
|
sendMessage()
|
|
.setTitle("Sheepstar Ban")
|
|
.setDescription("The User `" + userName + "` got banned from the serverchat.")
|
|
.send(e.getChannel());
|
|
} else {
|
|
sendErrorMessage()
|
|
.setDescription("This User is already banned. Unban with `s!unbanuser <clientID/mention>`")
|
|
.send(e.getChannel());
|
|
}
|
|
} else {
|
|
sendErrorMessage()
|
|
.setDescription("`You dont have the permission to do this.`")
|
|
.send(e.getChannel());
|
|
}
|
|
|
|
});
|
|
} catch (Exception err) {
|
|
sendErrorMessage()
|
|
.setDescription("This User does not exist")
|
|
.send(e.getChannel());
|
|
}
|
|
}
|
|
}
|