本文整理汇总了Java中net.dv8tion.jda.core.utils.PermissionUtil类的典型用法代码示例。如果您正苦于以下问题:Java PermissionUtil类的具体用法?Java PermissionUtil怎么用?Java PermissionUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PermissionUtil类属于net.dv8tion.jda.core.utils包,在下文中一共展示了PermissionUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onGuildJoin
import net.dv8tion.jda.core.utils.PermissionUtil; //导入依赖的package包/类
@Override
public void onGuildJoin(GuildJoinEvent event) {
Guild guild = event.getGuild();
MessageEmbed embed = createWelcomeMessage(guild);
guild.getOwner().getUser().openPrivateChannel().submit().whenComplete((e, t) -> {
if (e != null) {
e.sendMessage(embed).submit();
return;
}
TextChannel channel = guild.getDefaultChannel();
if (channel != null && PermissionUtil.checkPermission(channel, guild.getSelfMember(), Permission.MESSAGE_WRITE)) {
channel.sendMessage(embed).submit();
} else {
for (TextChannel textChannel : guild.getTextChannels()) {
if (PermissionUtil.checkPermission(textChannel, guild.getSelfMember(), Permission.MESSAGE_WRITE)) {
textChannel.sendMessage(embed).submit();
break;
}
}
}
});
}
示例2: 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);
}
示例3: 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));
}
示例4: 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;
}
示例5: 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();
}
}
示例6: 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();
}
示例7: 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;
}
}
示例8: 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;
}
}
示例9: addDefaultModerators
import net.dv8tion.jda.core.utils.PermissionUtil; //导入依赖的package包/类
public static List<User> addDefaultModerators(Guild guild) {
SettingsManager manager = SettingsManager.getInstance(guild.getId());
// Remove current moderators
List<String> currentMods = manager.getSettings().getModerators();
for (int i = 0; i < currentMods.size(); i++) {
String mod = currentMods.get(i);
manager.getSettings().removeModerator(mod);
}
// Permission required to add as moderator
final Permission PERM = Permission.MANAGE_SERVER;
List<User> us = new ArrayList<User>();
guild.getMembers().parallelStream().forEach(m -> {
if (PermissionUtil.checkPermission(guild, m, PERM)) {
us.add(m.getUser());
}
});
us.stream().forEach(u -> manager.getSettings().addModerator(u.getId()));
manager.saveSettings();
return us;
}
示例10: delete
import net.dv8tion.jda.core.utils.PermissionUtil; //导入依赖的package包/类
@Override
public AuditableRestAction<Void> delete()
{
if (!getGuild().getSelfMember().hasPermission(Permission.MANAGE_ROLES))
throw new InsufficientPermissionException(Permission.MANAGE_ROLES);
if(!PermissionUtil.canInteract(getGuild().getSelfMember(), this))
throw new HierarchyException("Can't delete role >= highest self-role");
if (managed)
throw new UnsupportedOperationException("Cannot delete a Role that is managed. ");
Route.CompiledRoute route = Route.Roles.DELETE_ROLE.compile(guild.getId(), getId());
return new AuditableRestAction<Void>(getJDA(), route)
{
@Override
protected void handleResponse(Response response, Request<Void> request)
{
if (response.isOk())
request.onSuccess(null);
else
request.onFailure(response);
}
};
}
示例11: 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();
}
}
示例12: 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);
}
}
示例13: 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();
}
}
示例14: 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();
}
}
}
示例15: 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);
}
}