Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Role commands #23

Open
wants to merge 2 commits 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
2 changes: 2 additions & 0 deletions src/main/java/org/moss/discord/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class Constants {
public static final String ROLE_MODERATOR = "390944427071242240";
public static final String ROLE_ADMIN = "390970629261623296";
public static final String ROLE_PROJECT_LEAD = " 390943316335788034";
public static final String ROLE_CONTRIBUTOR = "395277849877151767";
public static final String ROLE_SUPPORTER = "391029845225766912";

public static final String ROLE_PURCHASER = "401686955336663041";
public static final String ROLE_PURCHASER_PVX = "401687126242230274";
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/moss/discord/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.javacord.api.DiscordApiBuilder;
import org.moss.discord.commands.AvatarCommand;
import org.moss.discord.commands.BStatsCommand;
import org.moss.discord.commands.RoleCommand;
import org.moss.discord.commands.EmbedCommand;

import org.moss.discord.commands.SayCommand;
import org.moss.discord.listeners.StarboardListener;
import org.moss.discord.commands.GithubCommand;
Expand Down Expand Up @@ -60,6 +60,7 @@ public static void main(String[] args) {
commandHandler.registerCommand(new NicknameCommand());
commandHandler.registerCommand(new AvatarCommand());
commandHandler.registerCommand(new SpigetCommand());
commandHandler.registerCommand(new RoleCommand());
commandHandler.registerCommand(new EmbedCommand());
commandHandler.registerCommand(new SayCommand());

Expand Down
13 changes: 11 additions & 2 deletions src/main/java/org/moss/discord/commands/RoleCheckCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import org.javacord.api.entity.server.Server;
import org.javacord.api.entity.user.User;

import java.awt.*;
import java.util.stream.Collectors;

public class RoleCheckCommand implements CommandExecutor {

@Command(aliases = {"!rolecheck", ".rolecheck"}, usage = "!rolecheck <User>", description = "Checks users' role")
public void onCommand(TextChannel channel, String[] args, Message message, Server server) {
public void onCheck(TextChannel channel, String[] args, Message message, Server server) {
if (args.length >= 1) {
String string = "User Roles```";
if (message.getMentionedUsers().size() >= 1) {
for (User user : message.getMentionedUsers()) {
channel.sendMessage("User Roles for " + user.getName() + String.format("```%s```", user.getRoles(server).stream().map(Role::getName).collect(Collectors.joining(", "))));
Expand All @@ -31,4 +31,13 @@ public void onCommand(TextChannel channel, String[] args, Message message, Serve
}
}
}

@Command(aliases = {"!rolelist"}, usage = "Role List", description = "Role List")
public void onList(TextChannel channel, User user, Server server) {
if (server.canBanUsers(user)) {
String roles = server.getRoles().stream().map(role -> role.getName() + " = " + role.getId()).collect(Collectors.joining("\n"));
channel.sendMessage(new EmbedBuilder().setTitle("Roles").setColor(Color.GREEN).addField("Name | ID", roles));
}
}

}
73 changes: 73 additions & 0 deletions src/main/java/org/moss/discord/commands/RoleCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.moss.discord.commands;

import de.btobastian.sdcf4j.Command;
import de.btobastian.sdcf4j.CommandExecutor;
import org.javacord.api.entity.channel.TextChannel;
import org.javacord.api.entity.message.Message;
import org.javacord.api.entity.message.embed.EmbedBuilder;
import org.javacord.api.entity.permission.Role;
import org.javacord.api.entity.server.Server;
import org.javacord.api.entity.user.User;
import org.moss.discord.Constants;

import java.awt.*;
import java.util.List;

public class RoleCommand implements CommandExecutor {

@Command(aliases = {"!role", ".role"}, usage = "!role <give/take> <role> <user>", description = "Give user a role")
public void onRole(TextChannel channel, User user, Server server, Message message, String[] args) {
if (args.length >= 3 && server.isAdmin(user)) {
User target = message.getMentionedUsers().get(0);
Role role = server.getRolesByNameIgnoreCase(args[1]).get(0);
if (target != null && role != null) {
if (args[0].equalsIgnoreCase("give")) {
target.addRole(role, "Role given by " + user.getName());
channel.sendMessage(new EmbedBuilder().setColor(Color.GREEN).setTitle("Role given"));
}
if (args[0].equalsIgnoreCase("take")) {
target.removeRole(role, "Role taken by " + user.getName());
channel.sendMessage(new EmbedBuilder().setColor(Color.GREEN).setTitle("Role Taken"));
}
} else {
channel.sendMessage(new EmbedBuilder().setColor(Color.RED).setTitle("No user/role found"));
}
}
}

@Command(aliases = {"!contributor", ".contributor"}, usage = ".contributor <user>", description = "Allows project leads to give contributor roles.")
public void onContributor(TextChannel channel, User user, Server server, Message message, String[] args) {
if (args.length >= 1 && hasRole(user.getRoles(server), "Project Lead")) {
User target = message.getMentionedUsers().get(0);
if (target != null) {
target.addRole(server.getRoleById(Constants.ROLE_CONTRIBUTOR).get(), "Role given by " + user.getName());
channel.sendMessage(new EmbedBuilder().setColor(Color.GREEN).setTitle("Role given"));
} else {
channel.sendMessage(new EmbedBuilder().setColor(Color.RED).setTitle("No user found"));
}
}
}

@Command(aliases = {"!supporter", "!donor"}, usage = "!supporter <user>", description = "Allows project leads to give donor roles.")
public void onSupporter(TextChannel channel, User user, Server server, Message message, String[] args) {
if (args.length >= 1 && hasRole(user.getRoles(server), "Project Lead")) {
User target = message.getMentionedUsers().get(0);
if (target != null) {
target.addRole(server.getRoleById(Constants.ROLE_SUPPORTER).get(), "Role given by " + user.getName());
channel.sendMessage(new EmbedBuilder().setColor(Color.GREEN).setTitle("Role given"));
} else {
channel.sendMessage(new EmbedBuilder().setColor(Color.RED).setTitle("No user found"));
}
}
}

public Boolean hasRole(List<Role> roles, String role) { //TODO 1 class
for (Role roll : roles) {
if (roll.getName().equalsIgnoreCase(role)) {
return true;
}
}
return false;
}

}