use of sx.blah.discord.handle.obj.Permissions in project DiscordSailv2 by Vaerys-Dawn.
the class SubCommandObject method getHelpDesc.
public String getHelpDesc(CommandObject command) {
StringHandler builder = new StringHandler();
builder.append(description + "\n");
builder.append("**Type: **" + type.toString() + ".");
// display permissions
if (permissions != null && permissions.length != 0) {
builder.append("\n**Perms: **");
ArrayList<String> permList = new ArrayList<>(permissions.length);
for (Permissions p : permissions) {
permList.add(Utility.enumToString(p));
}
builder.append(Utility.listFormatter(permList, true));
}
if (names.length > 1) {
List<String> aliases = Arrays.asList(names).stream().map(s -> command.guild.config.getPrefixCommand() + s).collect(Collectors.toList());
aliases.remove(0);
builder.append("\n**Aliases:** " + Utility.listFormatter(aliases, true));
}
return builder.toString();
}
use of sx.blah.discord.handle.obj.Permissions in project DiscordSailv2 by Vaerys-Dawn.
the class Command method getCommandInfo.
/**
* Creates a message used to fetch the command's documentations
*
* @param command
* @return
*/
public XEmbedBuilder getCommandInfo(CommandObject command) {
XEmbedBuilder infoEmbed = new XEmbedBuilder(command);
// command info
StringBuilder builder = new StringBuilder();
builder.append(description(command) + "\n");
builder.append("**Type: **" + type.toString() + ".");
// display permissions
if (perms != null && perms.length != 0) {
builder.append("\n**Perms: **");
ArrayList<String> permList = new ArrayList<>(perms.length);
for (Permissions p : perms) {
permList.add(Utility.enumToString(p));
}
builder.append(Utility.listFormatter(permList, true));
}
if (names.length > 1) {
List<String> aliases = Arrays.asList(names).stream().map(s -> command.guild.config.getPrefixCommand() + s).collect(Collectors.toList());
aliases.remove(0);
builder.append("\n**Aliases:** " + Utility.listFormatter(aliases, true));
}
List<SubCommandObject> objectList = subCommands.stream().filter(subCommandObject -> GuildHandler.testForPerms(command, subCommandObject.getPermissions())).collect(Collectors.toList());
if (objectList.size() != 0)
builder.append("\n" + Command.spacer);
infoEmbed.withTitle("> Help - " + names()[0]);
infoEmbed.appendField("**" + getUsage(command) + "** " + Command.spacer, builder.toString(), true);
for (SubCommandObject s : objectList) {
infoEmbed.appendField(s.getCommandUsage(command) + " " + Command.spacer, s.getHelpDesc(command), true);
}
// Handle channels
List<IChannel> channels = command.guild.getChannelsByType(channel);
List<String> channelMentions = Utility.getChannelMentions(channels);
// channel
if (channelMentions.size() > 0) {
if (channelMentions.size() == 1) {
infoEmbed.appendField("Channel ", Utility.listFormatter(channelMentions, true), false);
} else {
infoEmbed.appendField("Channels ", Utility.listFormatter(channelMentions, true), false);
}
}
return infoEmbed;
}
use of sx.blah.discord.handle.obj.Permissions in project KaellyBot by Kaysoro.
the class MissingPermissionDiscordException method throwException.
public void throwException(IChannel channel, Language lg, MissingPermissionsException e) {
StringBuilder st = new StringBuilder(Translator.getLabel(lg, "exception.missing_permission").replace("{channel.name}", channel.getName()));
for (Permissions p : e.getMissingPermissions()) st.append(Translator.getLabel(lg, PERMISSION_PREFIX + p.name().toLowerCase())).append(", ");
st.delete(st.length() - 2, st.length()).append(".");
if (channel.getModifiedPermissions(ClientConfig.DISCORD().getOurUser()).contains(Permissions.SEND_MESSAGES))
Message.sendText(channel, st.toString());
else
try {
Message.sendText(channel.getGuild().getOwner().getOrCreatePMChannel(), st.toString());
} catch (sx.blah.discord.util.DiscordException de) {
LOG.warn("throwException", "Impossible de contacter l'administrateur de la guilde [" + channel.getGuild().getName() + "].");
}
}
use of sx.blah.discord.handle.obj.Permissions in project DiscordSailv2 by Vaerys-Dawn.
the class CosmeticRoles method execute.
@Override
public String execute(String args, CommandObject command) {
if (args == null || args.isEmpty()) {
return get(ListRoles.class).execute(args, command);
}
if (EDIT_ROLES.isSubCommand(command)) {
boolean isAdding = args.split(" ")[0].equals("+");
// test the permissions of the user to make sure they can modify the role list.
IRole role = null;
String subArgs = EDIT_ROLES.getArgs(command);
try {
role = command.guild.getRoleByID(Utility.stringLong(subArgs));
} catch (NumberFormatException e) {
// move on.
}
if (role == null)
role = GuildHandler.getRoleFromName(subArgs, command.guild.get());
if (role == null)
return "> **" + subArgs + "** is not a valid Role Name.";
// tests to see if the bot is allowed to mess with a role.
if (!Utility.testUserHierarchy(command.client.bot.get(), role, command.guild.get())) {
return "> I do not have permission to modify the **" + role.getName() + "** role.";
}
// test the user's hierarchy to make sure that the are allowed to mess with that role.
if (Utility.testUserHierarchy(command.user.get(), role, command.guild.get())) {
// do if modifier is true
if (isAdding) {
// check for the role and add if its not a cosmetic role.
if (command.guild.config.isRoleCosmetic(role.getLongID())) {
return "> The **" + role.getName() + "** role is already listed as a cosmetic role.";
} else {
command.guild.config.getCosmeticRoleIDs().add(role.getLongID());
return "> The **" + role.getName() + "** role was added to the cosmetic role list.";
}
// do if modifier is false
} else {
// check for the role and remove if it is a cosmetic role.
if (command.guild.config.isRoleCosmetic(role.getLongID())) {
Iterator iterator = command.guild.config.getCosmeticRoleIDs().listIterator();
while (iterator.hasNext()) {
long id = (long) iterator.next();
if (role.getLongID() == id) {
iterator.remove();
}
}
return "> The **" + role.getName() + "** role was removed from the cosmetic role list.";
} else {
return "> The **" + role.getName() + "** role is not listed as a cosmetic role.";
}
}
} else {
return "> You do not have permission to modify the **" + role.getName() + "** role.";
}
// do user role modification
} else {
// check to make sure that the user isn't including the args brackets or the /remove at the end;
if (command.guild.config.getCosmeticRoleIDs().size() == 0)
return "> No Cosmetic roles are set up right now. Come back later.";
if (args.matches("[(|\\[].*[)|\\]]")) {
return Constants.ERROR_BRACKETS + "\n" + Utility.getCommandInfo(this, command);
}
if (args.matches(".*/remove")) {
return "> Did you mean `" + command.guild.config.getPrefixCommand() + names()[0] + " " + args.replaceAll("(?i)/remove", "") + "`?";
}
List<IRole> userRoles = command.user.roles;
String response;
// check if role is valid
IRole role;
role = GuildHandler.getRoleFromName(args, command.guild.get());
if (role == null && args.length() > 3) {
role = GuildHandler.getRoleFromName(args, command.guild.get(), true);
}
if (role == null && !args.equalsIgnoreCase("remove")) {
RequestHandler.sendEmbedMessage("> **" + args + "** is not a valid Role Name.", ListRoles.getList(command), command.channel.get());
return null;
// if args = remove. remove the user's cosmetic role
} else if (args.equalsIgnoreCase("remove")) {
userRoles = userRoles.stream().filter(r -> !command.guild.config.isRoleCosmetic(r.getLongID())).collect(Collectors.toList());
if (command.user.getCosmeticRoles(command).size() == 0)
return "> You don't have a role to remove...";
else
response = "> You have had your cosmetic role removed.";
} else {
// check if role is cosmetic
if (command.guild.config.isRoleCosmetic(role.getLongID())) {
// check to see if roles are toggles
if (command.guild.config.roleIsToggle) {
// if user has role, remove it.
if (userRoles.contains(role)) {
userRoles.remove(role);
response = "> You have had the **" + role.getName() + "** role removed.";
// else add that role.
} else {
userRoles.add(role);
response = "> You have been granted the **" + role.getName() + "** role.";
}
// if roles arent toggles run this.
} else {
// if they already have that role
if (userRoles.contains(role)) {
return "> You already have the **" + role.getName() + "** role.";
} else {
// remove all cosmetic role and add the new one
userRoles = userRoles.stream().filter(r -> !command.guild.config.isRoleCosmetic(r.getLongID())).collect(Collectors.toList());
userRoles.add(role);
response = "> You have selected the cosmetic role: **" + role.getName() + "**.";
}
}
} else {
RequestHandler.sendEmbedMessage("> **" + args + "** is not a valid cosmetic role.", ListRoles.getList(command), command.channel.get());
return null;
}
}
// push the changes to the user's roles.
if (RequestHandler.roleManagement(command.user.get(), command.guild.get(), userRoles).get()) {
return response;
} else {
return Constants.ERROR_UPDATING_ROLE;
}
}
}
use of sx.blah.discord.handle.obj.Permissions in project DiscordSailv2 by Vaerys-Dawn.
the class Command method isVisibleInType.
public boolean isVisibleInType(CommandObject commandObject, SAILType type) {
if (this.type == type) {
return GuildHandler.testForPerms(commandObject, perms);
} else {
boolean hasPerms = false;
for (SubCommandObject s : subCommands) {
List<Permissions> allPerms = new ArrayList<>(Arrays.asList(perms));
allPerms.addAll(Arrays.asList(s.getPermissions()));
if (GuildHandler.testForPerms(commandObject, allPerms)) {
hasPerms = true;
}
}
return hasPerms;
}
}
Aggregations