本文整理汇总了Java中net.dv8tion.jda.entities.TextChannel.checkPermission方法的典型用法代码示例。如果您正苦于以下问题:Java TextChannel.checkPermission方法的具体用法?Java TextChannel.checkPermission怎么用?Java TextChannel.checkPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.dv8tion.jda.entities.TextChannel
的用法示例。
在下文中一共展示了TextChannel.checkPermission方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import net.dv8tion.jda.entities.TextChannel; //导入方法依赖的package包/类
@Override
protected boolean execute(Object[] args, MessageReceivedEvent event) {
TextChannel tc = (TextChannel)args[0];
Role role = (Role)args[1];
String content = (String)args[2];
if(!tc.checkPermission(event.getJDA().getSelfInfo(), Permission.MESSAGE_READ, Permission.MESSAGE_WRITE))
{
Sender.sendResponse(String.format(SpConst.NEED_PERMISSION,Permission.MESSAGE_READ+", "+Permission.MESSAGE_WRITE), event);
return false;
}
boolean mentionable = role.isMentionable();
if(!mentionable)
{
if(!PermissionUtil.canInteract(event.getJDA().getSelfInfo(), role))
{
Sender.sendResponse(SpConst.ERROR+"I cannot make the role *"+role.getName()+"* mentionable because I cannot edit it. Make sure it is listed below my highest role.", event);
return false;
}
role.getManager().setMentionable(true).update();
}
if(content.contains("{role}"))
content = content.replace("{role}", role.getAsMention());
else
content = role.getAsMention()+": "+content;
Sender.sendMsg(content, tc, m -> {
if(!mentionable)
role.getManager().setMentionable(false).update();
Sender.sendResponse(SpConst.SUCCESS+"Announcement sent to <#"+tc.getId()+">!", event);
});
return true;
}
示例2: execute
import net.dv8tion.jda.entities.TextChannel; //导入方法依赖的package包/类
@Override
protected boolean execute(Object[] args, MessageReceivedEvent event) {
String id = type==Argument.Type.SHORTSTRING ? (String)args[0] : ((User)args[0]).getId();
String[] feed = feeds.feedForGuild(event.getGuild(), Feeds.Type.MODLOG);
if(feed==null)
{
Sender.sendResponse(SpConst.ERROR+"The modlog feed has not been set up on this server!",event);
return false;
}
TextChannel tc = event.getJDA().getTextChannelById(feed[Feeds.CHANNELID]);
if(tc == null || !tc.checkPermission(event.getJDA().getSelfInfo(), Permission.MESSAGE_READ, Permission.MESSAGE_HISTORY))
{
Sender.sendResponse(SpConst.ERROR+"The modlog feed channel has been deleted or cannot be accessed.",event);
return false;
}
event.getChannel().sendTyping();
List<Message> logs = tc.getHistory().retrieve(500).stream().filter(m -> m.getRawContent().contains(id)).collect(Collectors.toList());
if(logs.isEmpty())
{
Sender.sendResponse(SpConst.WARNING+"Could not find anything in the modlog for ID `"+id+"` in the past 500 messages!",event);
return true;
}
StringBuilder builder = new StringBuilder(SpConst.SUCCESS+"`"+logs.size()+"` actions found for ID `"+id+"`:");
Collections.reverse(logs);
logs.stream().forEach(m -> {
builder.append("\n`[").append(m.getTime().format(DateTimeFormatter.ofPattern("d MMM uuuu"))).append("]` ").append(FormatUtil.appendAttachmentUrls(m).replaceAll("^`\\[[\\d:]+\\]`\\s+", ""));
});
Sender.sendResponse(builder.toString(), event);
return true;
}
示例3: onPlayerDeathImage
import net.dv8tion.jda.entities.TextChannel; //导入方法依赖的package包/类
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onPlayerDeathImage(GuiOpenEvent e)
{
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (!(e.getGui() instanceof GuiGameOver)
|| !Config.demiseImage
|| player == null
|| player.getHealth() <= 0F)
return;
// Getting discord and minecraft user
try
{
User me = DiscordCE.client.getUserById(DiscordCE.client.getSelfInfo().getId());
Minecraft mc = Minecraft.getMinecraft();
ITextComponent t = ScreenShotHelper.saveScreenshot(mc.mcDataDir,
mc.displayWidth,
mc.displayHeight,
mc.getFramebuffer());
String fileName = new JSONObject(TextComponentBase.Serializer.componentToJson(t)).getJSONArray("with")
.getJSONObject(0).getJSONObject("clickEvent").getString("value");
File file = new File(fileName);
TextChannel c = DiscordCE.client.getTextChannelById(Preferences.i.usingChannel);
// Doing checks
if (c == null || !c.checkPermission(me, Permission.MESSAGE_ATTACH_FILES))
return;
//Sending file
c.sendFileAsync(file, null, m -> file.delete());
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
示例4: configure
import net.dv8tion.jda.entities.TextChannel; //导入方法依赖的package包/类
@Override
public void configure(String cfgString, MessageEvent event, ServerConfig cfg) {
if(cfgString == null) {
MessageUtil.reply(event, cfg, "**Config:** `channel channelname` to set the channel where the dodo-list should be built");
} else {
if(cfgString.startsWith("channel ")) {
if(event.getMessage().getMentionedChannels().size() > 0) {
TextChannel channel = event.getMessage().getMentionedChannels().get(0);
if(!channel.checkPermission(api.getSelfInfo(), Permission.MESSAGE_WRITE)) {
MessageUtil.reply(event, cfg, "I do not have WRITE-Permission for that channel!");
return;
}
changeChannel(channel.getId());
MessageUtil.reply(event, cfg, "Set todo channel to " + channel.getName());
return;
}
Optional<TextChannel> any = event.getGuild().getTextChannels().parallelStream().filter(c -> c.getName().equals(cfgString.substring(8))).findAny();
if(any.isPresent()) {
if(!any.get().checkPermission(api.getSelfInfo(), Permission.MESSAGE_WRITE)) {
MessageUtil.reply(event, cfg, "I do not have WRITE-Permission for that channel!");
return;
}
changeChannel(any.get().getId());
MessageUtil.reply(event, cfg, "Set todo channel to " + any.get().getName());
} else {
MessageUtil.reply(event, cfg, "Channel not found!");
}
}
}
}
示例5: submitText
import net.dv8tion.jda.entities.TextChannel; //导入方法依赖的package包/类
public void submitText(Feeds.Type type, List<Guild> guilds, String text)
{
if(type==Feeds.Type.MODLOG || type== Feeds.Type.SERVERLOG || type==Feeds.Type.TAGLOG)
text = logFormat(text);
else if (type==Feeds.Type.BOTLOG)
text = botlogFormat(text);
for(Guild guild : guilds)
{
if(lists.getState(guild.getId())==GlobalLists.ListState.BLACKLIST)
continue;
String[] matching = feeds.feedForGuild(guild, type);
if(matching==null)
continue;
TextChannel target = guild.getJDA().getTextChannelById(matching[Feeds.CHANNELID]);
if(target==null)
{
if(guild.isAvailable())//channel was deleted
{
feeds.removeFeed(matching);
}
continue;
}
if(!target.checkPermission(target.getJDA().getSelfInfo(), Permission.MESSAGE_READ, Permission.MESSAGE_WRITE))
{
feeds.removeFeed(matching);
Sender.sendPrivate(SpConst.WARNING+"Feed `"+matching[Feeds.FEEDTYPE]+"` has been removed from <#"
+target.getId()+"> because I cannot send messages there.", guild.getOwner().getPrivateChannel());
continue;
}
synchronized(buffers){
Buffer buffer = buffers.get(guild.getId());
if(buffer==null)
{
Long ratelimit = ((JDAImpl)guild.getJDA()).getMessageLimit(guild.getId());
if(ratelimit!=null)
{
buffer = new Buffer(text);
buffers.put(guild.getId(), buffer);
bufferTimers.schedule(() -> {
synchronized(buffers)
{
buffers.remove(guild.getId());
Buffer thisbuffer = buffers.get(guild.getId());
String txt = thisbuffer.getBuffer();
if(txt!=null)
Sender.sendMsg(thisbuffer.getBuffer(), target);
if(thisbuffer.getFile()!=null)
{
Sender.sendMsgFile(thisbuffer.getFileText(), thisbuffer.getFile(), thisbuffer.getFileAltText(), target);
}
statistics.sentFeed(guild.getId());
}
}, Math.min(ratelimit-System.currentTimeMillis()+10, 10000), TimeUnit.MILLISECONDS);
}
else
{
Sender.sendMsg(text, target);
statistics.sentFeed(guild.getId());
}
}
else
{
buffer.append(text);
}
}
}
}