Remove ModCommand

This commit is contained in:
Anya 2022-05-21 20:21:03 -07:00
parent ab72638a94
commit ff626019b0

View file

@ -1,111 +0,0 @@
package moe.oko.Kiafumi.command.moderation;
import moe.oko.Kiafumi.Kiafumi;
import moe.oko.Kiafumi.command.CommandClass;
import moe.oko.Kiafumi.model.Server;
import moe.oko.Kiafumi.util.CommandInfo;
import moe.oko.Kiafumi.util.CommandType;
import moe.oko.Kiafumi.util.EmbedUI;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import java.util.ArrayList;
import java.util.List;
import static moe.oko.Kiafumi.Kiafumi.slashLog;
/**
* For use on Guilds that tend to get TOS'd with ease. Also just basic server protection
* @author Kay
* (Requires Permission.ADMINISTRATOR to function properly)
*/
@Deprecated
public class ModCommand extends CommandClass {
@Override
public boolean isEnabled() {
return true;
}
@Override
public String getName() {
return "Moderation";
}
@Override
public void newCommand(String name, SlashCommandInteractionEvent e) {
if(e.getGuild() == null) { return; }
var server = Kiafumi.instance.getServerManager().getOrCreateServer(e.getGuild());
switch (name) {
case "mod":
slashLog(e);
e.deferReply(true).queue();
if(server.isServerProtected()) {
// Start check.
if(server.getModRole() != null) {
if(e.getMember().isOwner()) {
e.getHook().sendMessage("*Owners cannot run this command.*").queue();
return;
}
if(hasModRole(e.getMember(), server)) {
if(isAdmin(e.getMember())) {
// They already have the admin role... So we try removing our mod role in case thats it
removeModRole(e.getMember());
e.getHook().sendMessage("**Admin Mode Disabled.**").queue();
} else {
if(applyModRole(e.getMember())) {
e.getHook().sendMessage("**Admin Mode Enabled.**").queue();
}
}
}
return;
} else {
e.getHook().sendMessage("*This server does not have a moderator role set.*").queue();
return;
}
} else {
e.getHook().sendMessage("*This server does not have protection enabled. This command will not function.*").queue();
return;
}
}
}
public boolean isAdmin(Member member) {
return member.hasPermission(Permission.ADMINISTRATOR);
}
public boolean hasModRole(Member member, Server server) {
return member.getRoles().contains(Kiafumi.JDA.getRoleById(server.getModRole()));
}
public boolean applyModRole(Member member) {
if(member.getGuild().getRolesByName("senior citizen", true).get(0) != null) {
member.getGuild().addRoleToMember(member, member.getGuild().getRolesByName("senior citizen", true).get(0)).queue();
return true;
} else {
// Create, role doesn't exist
member.getGuild().createRole()
.setColor(EmbedUI.INFO)
.setName("senior citizen")
.setPermissions(Permission.ADMINISTRATOR)
.setMentionable(false)
.setHoisted(true)
.complete();
// should be created so rerun
return applyModRole(member);
}
}
public void removeModRole(Member member) {
if(member.getGuild().getRolesByName("senior citizen", true).get(0) != null) {
member.getGuild().removeRoleFromMember(member, member.getGuild().getRolesByName("senior citizen", true).get(0)).queue();
} // Role must've been deleted otherwise, :thinking:
}
@Override
public List<CommandInfo> getSlashCommandInfo() {
List<CommandInfo> cil = new ArrayList<>();
cil.add(new CommandInfo("mod", "Toggles administrative permissions you.", CommandType.COMMAND));
return cil;
}
}