本文整理汇总了Java中net.dv8tion.jda.core.utils.PermissionUtil.checkPermission方法的典型用法代码示例。如果您正苦于以下问题:Java PermissionUtil.checkPermission方法的具体用法?Java PermissionUtil.checkPermission怎么用?Java PermissionUtil.checkPermission使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.dv8tion.jda.core.utils.PermissionUtil
的用法示例。
在下文中一共展示了PermissionUtil.checkPermission方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: joinChannel
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
public void joinChannel(VoiceChannel targetChannel) throws MessagingException {
if (targetChannel == null) {
throw new MessagingException(I18n.get(getGuild()).getString("playerUserNotInChannel"));
}
if (!PermissionUtil.checkPermission(targetChannel, targetChannel.getGuild().getSelfMember(), Permission.VOICE_CONNECT)
&& !targetChannel.getMembers().contains(getGuild().getSelfMember())) {
throw new MessagingException(I18n.get(getGuild()).getString("playerJoinConnectDenied"));
}
if (!PermissionUtil.checkPermission(targetChannel, targetChannel.getGuild().getSelfMember(), Permission.VOICE_SPEAK)) {
throw new MessagingException(I18n.get(getGuild()).getString("playerJoinSpeakDenied"));
}
AudioManager manager = getGuild().getAudioManager();
manager.openAudioConnection(targetChannel);
log.info("Connected to voice channel " + targetChannel);
}
示例2: handleMessages
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
private void handleMessages(MessageReceivedEvent event) {
String channelName = event.getChannel().getName();
String username = event.getAuthor().getName();
String message = event.getMessage().getContent();
String messageId = event.getMessage().getId();
Channel channel = event.getTextChannel();
User sender = event.getAuthor();
Boolean isAdmin = PermissionUtil.checkPermission(channel, event.getMember(), Permission.ADMINISTRATOR);
com.gmt2001.Console.out.println("[DISCORD] [#" + channelName + "] " + username.toLowerCase() + ": " + message);
// Be sure that this is commented out before a release back into the master branch!
/*
if (message.equals("!testjoin") && isAdmin) {
EventBus.instance().post(new DiscordJoinEvent(event.getMember()));
}
*/
if (message.startsWith("!")) {
commandEvent(sender, channel, message, isAdmin);
}
EventBus.instance().postAsync(new DiscordMessageEvent(sender, channel, message, messageId, isAdmin));
}
示例3: getChannel
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
private TextChannel getChannel(NewYearNotification notification, Guild guild) {
Member self = guild.getSelfMember();
TextChannel channel = null;
if (notification != null && StringUtils.isNotEmpty(notification.getChannelId())) {
channel = guild.getTextChannelById(notification.getChannelId());
}
if (channel != null && PermissionUtil.checkPermission(channel, self, Permission.MESSAGE_WRITE)) {
return channel;
}
for (TextChannel textChannel : guild.getTextChannels()) {
if (PermissionUtil.checkPermission(textChannel, self, Permission.MESSAGE_WRITE)) {
return textChannel;
}
}
return null;
}
示例4: updateRewards
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
private void updateRewards(RankingConfig config, Member member, Ranking ranking) {
Member self = member.getGuild().getSelfMember();
if (!discordService.isConnected()
|| CollectionUtils.isEmpty(config.getRewards())
|| !PermissionUtil.checkPermission(self, Permission.MANAGE_ROLES)) {
return;
}
int newLevel = RankingUtils.getLevelFromExp(ranking.getExp());
Set<Role> rolesToGive = config.getRewards().stream()
.filter(e -> e.getRoleId() != null && e.getLevel() <= newLevel) // filter by level
.map(Reward::getRoleId) // map by id
.filter(roleId -> member.getRoles().stream().noneMatch(role -> roleId.equals(role.getId()))) // filter by non-existent
.map(roleId -> member.getGuild().getRoleById(roleId)) // find actual role object
.filter(role -> role != null && self.canInteract(role)) // check that we can assign that role
.collect(Collectors.toSet());
if (!rolesToGive.isEmpty()) {
member.getGuild().getController().addRolesToMember(member, rolesToGive).submit();
}
}
示例5: TempChannel
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
public TempChannel(MessageReceivedEvent e) {
if (e.isFromType(ChannelType.PRIVATE)) {
e.getAuthor().getPrivateChannel()
.sendMessage("Error: !temp may not be used in a private channel.");
return;
}
this.event = e;
messageChannel = e.getTextChannel();
if(!PermissionUtil.checkPermission(e.getGuild(), e.getGuild().getSelfMember(), Permission.MANAGE_CHANNEL)) {
return;
}
if (TEMP_NUMBER >= TEMP_MAX) {
messageChannel.sendMessage("The maximum number of temporary voice channels is already reached.");
return;
}
this.voiceChannel = createChannel();
startTimer();
}
示例6: setDedicatedChannel
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
public boolean setDedicatedChannel(int dedicatedChannel, MessageReceivedEvent e) {
if (dedicatedChannel < 0 || dedicatedChannel > 3) {
return false;
}
boolean hasPermission = PermissionUtil.checkPermission(e.getGuild(), e.getGuild().getSelfMember(), Permission.MANAGE_CHANNEL);
if (!hasPermission) {
this.dedicatedChannel = 0;
return false;
}
else {
this.dedicatedChannel = dedicatedChannel;
return true;
}
}
示例7: findTopWriteChannel
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
public static TextChannel findTopWriteChannel(Guild guild) {
// Prefer public channel
if (PermissionUtil.checkPermission(guild.getPublicChannel(), guild.getSelfMember(), Permission.MESSAGE_WRITE)) {
return guild.getPublicChannel();
}
Optional<TextChannel> first = guild.getTextChannels().parallelStream().filter(
c -> PermissionUtil.checkPermission(c, guild.getSelfMember(), Permission.MESSAGE_WRITE))
.sorted((c1, c2) -> Integer.compare(c1.getPosition(), c2.getPosition())).findFirst();
if (first.isPresent()) {
return first.get();
}
else {
return null;
}
}
示例8: remove
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
public void remove(boolean soft) {
if (soft) {
cancelled = true;
if (PermissionUtil.checkPermission(message.getTextChannel(), message.getGuild().getSelfMember(), Permission.MESSAGE_MANAGE)) {
reactionFutures.forEach(e -> e.cancel(false));
message.clearReactions().complete();
}
} else {
message.delete().complete();
}
}
示例9: sendEmotion
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
private void sendEmotion(MessageReceivedEvent message, String emoji, String messageCode, Object... args) {
try {
if (message.getGuild() == null || PermissionUtil.checkPermission(message.getTextChannel(),
message.getMember(), Permission.MESSAGE_ADD_REACTION)) {
message.getMessage().addReaction(emoji).submit();
} else if (StringUtils.isNotEmpty(messageCode)) {
String text = messageService.getMessage(messageCode, args);
messageService.sendMessageSilent(message.getChannel()::sendMessage, text);
}
} catch (Exception e) {
LOGGER.error("Add emotion error", e);
}
}
示例10: linkChannel
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
private void linkChannel(VoiceChannel c) {
Set<Member> membersInChannel = new HashSet<Member>();
membersInChannel.addAll(c.getMembers());
channelsAndMembers.put(c, membersInChannel);
Guild g = Bot.getJDA().getGuildById(guildId);
membersInChannel.stream().forEach(m -> g.getController().moveVoiceMember(m, linkChannel).queue());
// If bot has manage channel permission in the guild to edit channel name
if (PermissionUtil.checkPermission(g, g.getSelfMember(), Permission.MANAGE_CHANNEL)) {
c.getManager().setName(PREFIX + c.getName()).queue();
}
}
示例11: unlinkChannel
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
private void unlinkChannel(VoiceChannel c, Set<Member> members, boolean unlinkingAll) {
Guild g = Bot.getJDA().getGuildById(guildId);
if (!unlinkingAll) {
if (channelsToLink.size() == 2) {
unlinkChannels();
return;
}
linkChannel = channelsToLink.get(channelsToLink.lastIndexOf(c) != 0 ? 0 : 1);
members.forEach(m -> {
if (!c.getMembers().contains(m)) {
g.getController().moveVoiceMember(m, linkChannel);
}
});
}
else {
members.forEach(m -> {
if (linkChannel.getMembers().contains(m)) {
g.getController().moveVoiceMember(m, c);
}
});
}
String name = c.getName();
if (name.startsWith(PREFIX)) {
// If bot has manage channel permission in the guild to edit channel name
if (PermissionUtil.checkPermission(g, g.getSelfMember(), Permission.MANAGE_CHANNEL)) {
c.getManager().setName(name.substring(PREFIX.length())).queue();
}
}
}
示例12: sendMessage
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
public static void sendMessage(TextChannel c, Message message) {
if (PermissionUtil.checkPermission(c, c.getGuild().getSelfMember(), Permission.MESSAGE_WRITE)) {
c.sendMessage(message).queue();
MessageLogger.sendGuildMessage(c, message);
}
else {
MessageLogger.failedSendGuildMessage(c, message);
}
}
示例13: display
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
/**
* Shows the OrderedMenu as a new {@link net.dv8tion.jda.core.entities.Message Message}
* in the provided {@link net.dv8tion.jda.core.entities.MessageChannel MessageChannel}.
*
* @param channel
* The MessageChannel to send the new Message to
*/
@Override
public void display(MessageChannel channel) {
if(channel.getType()==ChannelType.TEXT
&& !allowTypedInput
&& !PermissionUtil.checkPermission((TextChannel)channel, ((TextChannel)channel).getGuild().getSelfMember(), Permission.MESSAGE_ADD_REACTION))
throw new PermissionException("Must be able to add reactions if not allowing typed input!");
initialize(channel.sendMessage(getMessage()));
}
示例14: doInternal
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
@Override
protected boolean doInternal(MessageReceivedEvent message, BotContext context, String content) throws DiscordException {
Member member = message.getMember();
if (CollectionUtils.isNotEmpty(message.getMessage().getMentionedUsers())) {
member = message.getGuild().getMember(message.getMessage().getMentionedUsers().get(0));
}
RankingInfo info = rankingService.getRankingInfo(member);
if (info == null) {
messageService.sendMessageSilent(message.getTextChannel()::sendMessage, messageService.getMessage(
"discord.command.rank.unavailable"));
return false;
}
if (PermissionUtil.checkPermission(message.getTextChannel(), message.getGuild().getSelfMember(),
Permission.MESSAGE_EMBED_LINKS)) {
EmbedBuilder builder = messageService.getBaseEmbed(true);
addFields(builder, info);
builder.setAuthor(member.getEffectiveName(), null, member.getUser().getAvatarUrl());
messageService.sendMessageSilent(message.getTextChannel()::sendMessage, builder.build());
} else {
String response;
if (message.getMember().equals(member)) {
response = messageService.getMessage("discord.command.rank.info.message.self",
member.getAsMention(),
info.getRank(),
info.getLevel(),
info.getRemainingExp(),
info.getLevelExp(),
info.getTotalExp());
} else {
response = messageService.getMessage("discord.command.rank.info.message.member",
message.getMember().getAsMention(),
member.getAsMention(),
info.getRank(),
info.getLevel(),
info.getRemainingExp(),
info.getLevelExp(),
info.getTotalExp());
}
messageService.sendMessageSilent(message.getTextChannel()::sendMessage, response);
}
return true;
}
示例15: process
import net.dv8tion.jda.core.utils.PermissionUtil; //导入方法依赖的package包/类
public void process(GuildMessageReceivedEvent event) {
if(GabrielBot.DEBUG && event.getJDA().getSelfUser().getName().equals("Gabriel") && !CommandPermission.OWNER.test(event.getMember())) return;
String guildid = event.getGuild().getId(),
authorid = event.getAuthor().getId();
JedisDataManager blacklist = GabrielData.blacklist();
if(blacklist.get(guildid) != null || blacklist.get(authorid) != null) return;
String first = event.getMessage().getRawContent().split(" ")[0];
String prefix = GabrielData.config().prefix;
GabrielData.GuildData data = GabrielData.guilds().getObject(event.getGuild().getId());
String guildPrefix = data == null ? null : data.prefix;
String usedPrefix;
if(first.startsWith(usedPrefix = prefix) || (guildPrefix != null && first.startsWith(usedPrefix = guildPrefix))) {
String cmdname = first.substring(usedPrefix.length());
Map<String, Object> map = new HashMap<>();
CommandReference ref = findCommand(cmdname, map);
if(ref == null) {
handleCustom(event, cmdname);
return;
}
if(!PermissionUtil.checkPermission(event.getChannel(), event.getGuild().getSelfMember(), Permission.MESSAGE_EMBED_LINKS)) {
event.getChannel().sendMessage("I need the Embed Links permission").queue();
return;
}
Command cmd = ref.command;
if(!cmd.permission().test(event.getMember())) {
if(cmd.permission() == CommandPermission.PREMIUM) {
event.getChannel().sendMessage("This feature is premium only.\nConsider donating on https://www.patreon.com/gabrielbot to support the bot development").queue();
return;
}
event.getChannel().sendMessage("You don't have permission to do this").queue();
return;
}
SessionStats.command();
map.putAll(Utils.map(
"event", event,
"message", event.getMessage(),
"member", event.getMember(),
"author", event.getAuthor(),
"guild", event.getGuild(),
"channel", event.getChannel(),
"selfmember", event.getGuild().getSelfMember(),
"selfuser", event.getJDA().getSelfUser(),
"jda", event.getJDA(),
"guildid", guildid,
"prefix", guildPrefix,
"this", ref,
"prefix", usedPrefix,
"context", new Context(event)
));
try {
ref.invoker.run(event, ref.command.advancedSplit(), map);
} catch(Throwable t) {
LOGGER.error("Error running command " + cmdname, t);
event.getChannel().sendMessage("There was an unexpected error running the command, don't worry, it's already been reported and will be fixed as soon as possible").queue();
}
}
}