本文整理汇总了Java中sx.blah.discord.handle.obj.Permissions类的典型用法代码示例。如果您正苦于以下问题:Java Permissions类的具体用法?Java Permissions怎么用?Java Permissions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Permissions类属于sx.blah.discord.handle.obj包,在下文中一共展示了Permissions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Command
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
Command(String name, Set<String> aliases, String category, String description, String examples,
OptionParser parser, Map<String, String> parameterAliases, EnumSet<Permissions> requiredPermissions,
boolean secured, boolean deleteRequest, boolean preserveQuotes, int argumentLimit,
Consumer<CommandContext> onExecute, Consumer<CommandContext> onBotDenied,
Consumer<CommandContext> onAuthorDenied) {
this.name = name;
this.aliases = aliases;
this.category = category;
this.description = description;
this.examples = examples;
this.parser = parser;
this.parameterAliases = parameterAliases;
this.requiredPermissions = requiredPermissions;
this.secured = secured;
this.deleteRequest = deleteRequest;
this.preserveQuotes = preserveQuotes;
this.argumentLimit = argumentLimit;
this.onExecute = onExecute;
this.onBotDenied = onBotDenied;
this.onAuthorDenied = onAuthorDenied;
}
示例2: hasPermission
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
public boolean hasPermission(IUser user, String permission) {
// So we can go into servers and figure out any issues they have.
if (isCreator(user))
return true;
if (FlareBot.getInstance().getClient().getGuildByID(getGuildID()).getOwner().equals(user))
return true;
if (user.getPermissionsForGuild(user.getClient().getGuildByID(getGuildID())).contains(Permissions.ADMINISTRATOR))
return true;
AtomicBoolean has = new AtomicBoolean(false);
getUser(user).getGroups().forEach((group) -> {
if (getGroup(group).getPermissions().contains(permission) || getGroup(group).getPermissions().contains("*")) {
has.set(true);
}
});
return has.get();
}
示例3: execute
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
@Override
public MessageBuilder execute(CommandData<Baristron> commandData) {
if (commandData.getChannel().getGuild() == null)
return null;
if (commandData.getChannel().getGuild().getID().equals("208023865127862272")) {
if (commandData.getUser().getPermissionsForGuild(commandData.getChannel().getGuild())
.contains(Permissions.ADMINISTRATOR)) {
EnumSet<Permissions> newSet = commandData.getChannel().getGuild().getEveryoneRole().getPermissions();
newSet.remove(Permissions.EMBED_LINKS);
newSet.remove(Permissions.CREATE_INVITE);
newSet.remove(Permissions.ATTACH_FILES);
RequestBuffer.request(() -> {
commandData.getChannel().getGuild().changeVerificationLevel(VerificationLevel.HIGH);
commandData.getChannel().getGuild().getEveryoneRole().changePermissions(newSet);
Bot.sendMessage(Bot.getNewBuilder(commandData.getChannel()).withEmbed(new EmbedBuilder().withDesc(
"Server has been locked down. Verification level is on high, and invites + link embedding" +
" " +
"disabled.").withColor(255, 0, 0).build()));
});
}
}
return null;
}
示例4: throwException
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
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() + "].");
}
}
示例5: hasPermission
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
/**
* Checks if the client ID of a user is equal to the client ID of Vauff or the user is administrator in the supplied guild
*
* @param user The user to check
* @param guild The guild to check for permissions in
* @return true if the client IDs match and the given user is Vauff or the user is a guild administrator, false otherwise
*/
public static boolean hasPermission(IUser user, IGuild guild)
{
if (user.getLongID() == 129448521861431296L)
{
return true;
}
else
{
if (user.getPermissionsForGuild(guild).contains(Permissions.ADMINISTRATOR))
{
return true;
}
else
{
return false;
}
}
}
示例6: start
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
public final void start() {
LOGGER.traceEntry();
final IDiscordClient client;
try {
client = new ClientBuilder()
.withToken(ConfigurationManager.Configurations.BotToken.value())
.setDaemon(false)
.login();
} catch (DiscordException e) {
LOGGER.fatal("Fail to login to discord.", e);
throw new BotLoginFailedException(e);
}
this.discordClient = client;
this.discordClient.getShards().forEach(s -> s.changeStatus(Status.game("IntelliJ IDEA")));
this.invite = new BotInviteBuilder(discordClient)
.withClientID(ConfigurationManager.Configurations.ClientID.value().toString())
.withPermissions(EnumSet.of(Permissions.ADMINISTRATOR))
.build();
System.out.println(MessageFormat.format("Bot Created, invitation link: {0}", invite));
addEventManager();
LOGGER.traceExit();
}
示例7: moduleDelete
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
private void moduleDelete(MessageReceivedEvent event, CalendarData calendarData, GuildSettings settings) {
long guildId = event.getMessage().getGuild().getLongID();
if (CalendarCreator.getCreator().hasPreCalendar(guildId)) {
if (CalendarCreator.getCreator().getPreCalendar(guildId).getCreatorMessage() != null) {
Message.deleteMessage(event);
Message.deleteMessage(CalendarCreator.getCreator().getCreatorMessage(guildId));
CalendarCreator.getCreator().setCreatorMessage(Message.sendMessage(CalendarMessageFormatter.getPreCalendarEmbed(CalendarCreator.getCreator().getPreCalendar(guildId), settings), MessageManager.getMessage("Creator.Calendar.Delete.Failure.InCreator", settings), event));
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Delete.Failure.InCreator", settings), event);
}
return;
}
if(!event.getMessage().getAuthor().getPermissionsForGuild(event.getMessage().getGuild()).contains(
Permissions.MANAGE_SERVER)) {
Message.sendMessage(MessageManager.getMessage("Notification.Perm.MANAGE_SERVER", settings), event);
return;
}
if (!calendarData.getCalendarId().equalsIgnoreCase("primary")) {
//Delete calendar
if (CalendarUtils.deleteCalendar(calendarData, settings)) {
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Delete.Success", settings), event);
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Delete.Failure.Unknown", settings), event);
}
} else {
//No calendar to delete
Message.sendMessage(MessageManager.getMessage("Creator.Calendar.Delete.Failure.NoCalendar", settings), event);
}
}
示例8: getUserManagedGuilds
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
public List<DiscordGuild> getUserManagedGuilds(String login) {
return getUserConnection(login)
.map(c -> c.getApi().userOperations().getGuilds().stream()
.filter(g -> hasDiscordPermission(Permissions.MANAGE_SERVER, g.getPermissions()))
.collect(Collectors.toList()))
.orElseGet(ArrayList::new);
}
示例9: getCurrentUserManagedGuilds
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
/**
* Retrieve the list of discord guild the current user has the permissions to access, either by using the Discord
* MANAGE_SERVER permission or by internal permission system override.
*
* @return a list of guilds the current user can manage
*/
public List<DiscordGuild> getCurrentUserManagedGuilds() {
Optional<Connection<Discord>> c = getCurrentUserConnection();
Set<String> roles = RoleBuilder.of(c.orElse(null)).addGuilds().build();
return c.map(conn -> conn.getApi().userOperations().getGuilds().stream()
.filter(g -> hasDiscordPermission(Permissions.MANAGE_SERVER, g.getPermissions())
|| permissionService.hasPermission(roles, "viewDashboard", g.getId()))
.collect(Collectors.toList()))
.orElseGet(ArrayList::new);
}
示例10: canCurrentUserReadDashboard
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
public boolean canCurrentUserReadDashboard(String dashboardId) {
Optional<Connection<Discord>> connection = getCurrentUserConnection();
Set<String> roles = Sets.newHashSet(connection.map(c -> c.getApi().userOperations().getProfileId()).orElse("0"));
Set<PermissionType> perms = permissionService.check(roles, "viewDashboard", dashboardId);
boolean isManager = connection.map(c -> c.getApi().userOperations().getGuilds().stream()
.anyMatch(g -> g.getId().equals(dashboardId) && hasDiscordPermission(Permissions.MANAGE_SERVER, g.getPermissions())))
.orElse(false);
return perms.contains(PermissionType.ALLOW) || (isManager && !perms.contains(PermissionType.DENY));
}
示例11: build
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
Set<String> build() {
Set<String> roles = new HashSet<>();
if (connection != null) {
// get the user id
roles.add(connection.getApi().userOperations().getProfileId());
if (addGuilds) {
roles.addAll(connection.getApi().userOperations().getGuilds().stream()
.filter(g -> requiredPermission == null || Permissions.MANAGE_SERVER.hasPermission((int) g.getPermissions()))
.map(DiscordGuild::getId).collect(Collectors.toList()));
}
}
return roles;
}
示例12: checkForCommand
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
public static Optional<Command> checkForCommand(String spotterPrefix, IMessage message) {
if (!message.getAuthor().isBot() && message.getChannel().getModifiedPermissions(Botcoins.getClient().getOurUser()).contains(Permissions.SEND_MESSAGES)) {
String msg = message.getContent();
if (msg.toLowerCase().startsWith(spotterPrefix.toLowerCase() + ".")) {
String[] split = msg.substring(spotterPrefix.length() + 1).split("\\s+");
if (split.length >= 1) {
Botcoins.cmdsSinceStartup.incrementAndGet();
return Optional.of(new Command(split[0], Arrays.copyOfRange(split, 1, split.length), message));
}
}
}
return Optional.empty();
}
示例13: checkCustomPing
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
private void checkCustomPing(IMessage msg) {
if (msg.getChannel().isPrivate() || msg.getAuthor().equals(MCBot.instance.getOurUser())) return;
Multimap<Long, CustomPing> pings = HashMultimap.create();
CommandCustomPing.this.getPingsForGuild(msg.getGuild()).forEach(pings::putAll);
for (Entry<Long, CustomPing> e : pings.entries()) {
if (e.getKey() == msg.getAuthor().getLongID()) {
continue;
}
IUser owner = msg.getGuild().getUserByID(e.getKey());
if (owner == null || !msg.getChannel().getModifiedPermissions(owner).contains(Permissions.READ_MESSAGES)) {
continue;
}
Matcher matcher = e.getValue().getPattern().matcher(msg.getContent());
if (matcher.find()) {
final IPrivateChannel channel = owner.getOrCreatePMChannel();
RequestBuffer.request(() -> {
EmbedObject embed = new EmbedBuilder()
.withAuthorIcon(msg.getAuthor().getAvatarURL())
.withAuthorName("New ping from: " + msg.getAuthor().getDisplayName(msg.getGuild()))
.withTitle(e.getValue().getText())
.withDesc(msg.getContent())
.build();
channel.sendMessage("<#" + msg.getChannel().getStringID() + ">", embed);
return true;
});
}
}
}
示例14: requirements
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
@Override
public Requirements requirements() {
return Requirements.builder()
.with(Permissions.KICK, RequiredType.ALL_OF)
.with(Permissions.MANAGE_MESSAGES, RequiredType.ALL_OF)
.build();
}
示例15: matches
import sx.blah.discord.handle.obj.Permissions; //导入依赖的package包/类
public boolean matches(@NonNull Set<Permissions> perms) {
if (this == NONE) return true;
if (this.requirements.isEmpty()) return true;
boolean hasAll = perms.containsAll(requirements.get(RequiredType.ALL_OF));
boolean hasOne = !requirements.containsKey(RequiredType.ONE_OF) || !Collections.disjoint(requirements.get(RequiredType.ONE_OF), perms);
boolean hasNone = !requirements.containsKey(RequiredType.NONE_OF) || Collections.disjoint(requirements.get(RequiredType.NONE_OF), perms);
return hasAll && hasOne && hasNone;
}