ColorRole commands logical implementation
This commit is contained in:
parent
43b1570b9d
commit
3bca668a97
@ -5,10 +5,15 @@
|
||||
|
||||
package dev.salmonllama.fsbot.commands.general;
|
||||
|
||||
import dev.salmonllama.fsbot.config.BotConfig;
|
||||
import dev.salmonllama.fsbot.database.controllers.ColorRoleController;
|
||||
import dev.salmonllama.fsbot.guthix.Command;
|
||||
import dev.salmonllama.fsbot.guthix.CommandContext;
|
||||
import dev.salmonllama.fsbot.guthix.CommandPermission;
|
||||
import dev.salmonllama.fsbot.guthix.PermissionType;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.javacord.api.entity.server.Server;
|
||||
import org.javacord.api.entity.user.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -24,6 +29,43 @@ public class ColorCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandContext ctx) {
|
||||
ctx.reply("This command is a WIP and will be available soon");
|
||||
// The color given will be the args.
|
||||
// Check if args[0] is reset. If so, remove all color roles.
|
||||
// Check if the given string is a current color role.
|
||||
// Remove any color roles that the user has.
|
||||
// Give the user the color role they specified
|
||||
ctx.getServer().ifPresentOrElse(server -> {
|
||||
String[] args = ctx.getArgs();
|
||||
if (server.getIdAsString().equals(BotConfig.HOME_SERVER)) {
|
||||
if (args[0].equals("reset")) {
|
||||
// Remove all color roles
|
||||
removeColorRoles(ctx.getUser(), server);
|
||||
}
|
||||
|
||||
String color = Strings.join(Arrays.asList(args), ' ');
|
||||
ColorRoleController.get(color).thenAcceptAsync(possibleColorRole -> possibleColorRole.ifPresentOrElse(colorRole -> {
|
||||
// Remove all color roles
|
||||
removeColorRoles(ctx.getUser(), server);
|
||||
// Give the user the one they specified
|
||||
addColorRole(ctx.getUser(), server, colorRole.getRoleId());
|
||||
}, () -> ctx.reply("That color does not exist")));
|
||||
}
|
||||
}, () -> ctx.reply("This command can only be used in the fashionscape server"));
|
||||
}
|
||||
|
||||
private static void removeColorRoles(User user, Server server) {
|
||||
ColorRoleController.getAll().thenAcceptAsync(
|
||||
possibleRoles -> possibleRoles.ifPresent(
|
||||
colorRoles -> colorRoles.forEach(
|
||||
colorRole -> server.getRoleById(colorRole.getRoleId()).ifPresent(
|
||||
role -> user.removeRole(role, "Removed color role")
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static void addColorRole(User user, Server server, long roleId) {
|
||||
server.getRoleById(roleId).ifPresent(role -> user.addRole(role, "Added color role"));
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,13 @@
|
||||
|
||||
package dev.salmonllama.fsbot.commands.general;
|
||||
|
||||
import dev.salmonllama.fsbot.config.BotConfig;
|
||||
import dev.salmonllama.fsbot.database.controllers.ColorRoleController;
|
||||
import dev.salmonllama.fsbot.guthix.Command;
|
||||
import dev.salmonllama.fsbot.guthix.CommandContext;
|
||||
import dev.salmonllama.fsbot.guthix.CommandPermission;
|
||||
import dev.salmonllama.fsbot.guthix.PermissionType;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -24,6 +27,26 @@ public class ColorsCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandContext ctx) {
|
||||
ctx.reply("This command is a WIP and will be available soon.");
|
||||
// List available color roles
|
||||
ctx.getServer().ifPresentOrElse(server -> {
|
||||
if (server.getIdAsString().equals(BotConfig.HOME_SERVER)) {
|
||||
ColorRoleController.getAll().thenAcceptAsync(
|
||||
possibleColorRoles -> possibleColorRoles.ifPresentOrElse(colorRoles -> {
|
||||
EmbedBuilder response = new EmbedBuilder()
|
||||
.setTitle("Color roles")
|
||||
.setFooter(String.format("Found %d roles", colorRoles.size()));
|
||||
|
||||
colorRoles.forEach(
|
||||
colorRole -> server.getRoleById(colorRole.getRoleId()).ifPresent(
|
||||
role -> response.addField(colorRole.getColor(), role.getMentionTag(), true)
|
||||
)
|
||||
);
|
||||
|
||||
ctx.reply(response);
|
||||
}, () -> ctx.reply("No color roles have been found")));
|
||||
} else {
|
||||
ctx.reply("This command can only be used in the fashionscape server");
|
||||
}
|
||||
}, () -> ctx.reply("This command can only be used in the fashionscape server"));
|
||||
}
|
||||
}
|
||||
|
@ -6,14 +6,18 @@
|
||||
package dev.salmonllama.fsbot.commands.staff;
|
||||
|
||||
import dev.salmonllama.fsbot.config.BotConfig;
|
||||
import dev.salmonllama.fsbot.database.controllers.ColorRoleController;
|
||||
import dev.salmonllama.fsbot.database.models.ColorRole;
|
||||
import dev.salmonllama.fsbot.guthix.Command;
|
||||
import dev.salmonllama.fsbot.guthix.CommandContext;
|
||||
import dev.salmonllama.fsbot.guthix.CommandPermission;
|
||||
import dev.salmonllama.fsbot.guthix.PermissionType;
|
||||
import org.javacord.api.entity.permission.Role;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class AddColorCommand extends Command {
|
||||
@Override public String name() { return "Add Color"; }
|
||||
@ -25,6 +29,22 @@ public class AddColorCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandContext ctx) {
|
||||
ctx.reply("This command is a WIP and will be available soon.");
|
||||
// Command takes only a role mention.
|
||||
ctx.getServer().ifPresentOrElse(server -> {
|
||||
if (server.getIdAsString().equals(BotConfig.HOME_SERVER)) {
|
||||
List<Role> roles = ctx.getMessage().getMentionedRoles();
|
||||
roles.forEach(role -> {
|
||||
ColorRole colorRole = new ColorRole.ColorRoleBuilder(role.getId())
|
||||
.setColor(role.getName())
|
||||
.setServerId(server.getId())
|
||||
.build();
|
||||
|
||||
ColorRoleController.insert(colorRole);
|
||||
ctx.reply("Added color role:" + colorRole.toString());
|
||||
});
|
||||
} else {
|
||||
ctx.reply("This command can only be used in the fashionscape server");
|
||||
}
|
||||
}, () -> ctx.reply("This command can only be used in the fashionscape server"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user