Java 类net.dv8tion.jda.core.entities.PrivateChannel 实例源码

项目:Rubicon    文件:CommandKick.java   
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
    Message msg = parsedCommandInvocation.getMessage();
    if (msg.getMentionedUsers().isEmpty()) {
        return new MessageBuilder().setEmbed(EmbedUtil.info("Usage", "kick <@User>").build()).build();
    }
    Member target = msg.getGuild().getMember(msg.getMentionedUsers().get(0));
    if (!msg.getGuild().getSelfMember().canInteract(target)) {
        return new MessageBuilder().setEmbed(EmbedUtil.error("No permissions", "Sorry I can't kick this User!!!").build()).build();
    } else {
        PrivateChannel channel = target.getUser().openPrivateChannel().complete();
        channel.sendMessage(EmbedUtil.success("Kicked", "You got kicked").build()).queue();
        msg.getGuild().getController().kick(target).queue();


        return new MessageBuilder().setEmbed(EmbedUtil.success("Kicked", "Succesfully kicked " + target.getAsMention()).build()).build();
    }
}
项目:Rubicon    文件:CommandUnmute.java   
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
    Message message = parsedCommandInvocation.getMessage();
    if (message.getMentionedUsers().isEmpty())
        return new MessageBuilder().setEmbed(EmbedUtil.info("Usage", "unmute <@User>").build()).build();
    Member target = message.getGuild().getMember(message.getMentionedUsers().get(0));
    if (!message.getGuild().getSelfMember().canInteract(target))
        return new MessageBuilder().setEmbed(EmbedUtil.error("No permission", "Sorry i can't unmute this use! It's a moderator or higher").build()).build();

    TextChannel channel = message.getTextChannel();
    if (channel.getPermissionOverride(target) == null)
        channel.createPermissionOverride(target).complete();
    if (!channel.getPermissionOverride(target).getDenied().contains(Permission.MESSAGE_WRITE))
        return new MessageBuilder().setEmbed(EmbedUtil.error("Not muted", "This user is no muted. Use `mute <@User>` to mute him").build()).build();
    message.getGuild().getTextChannels().forEach(c -> {
        if (c.getPermissionOverride(target) == null)
            c.createPermissionOverride(target).complete();
        c.getPermissionOverride(target).getManager().grant(Permission.MESSAGE_WRITE).queue();
    });
    PrivateChannel targetch = target.getUser().openPrivateChannel().complete();
    targetch.sendMessage(EmbedUtil.info("Unmuted", "You got unmuted on `" + message.getGuild().getName() + "` by " + message.getAuthor().getAsMention()).build()).queue();
    return new MessageBuilder().setEmbed(EmbedUtil.success("Unmuted", "Successfully Unmuted " + target.getAsMention()).build()).build();

}
项目:Rubicon    文件:CommandMute.java   
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
    Message message = parsedCommandInvocation.getMessage();
    if (message.getMentionedUsers().isEmpty())
        return new MessageBuilder().setEmbed(EmbedUtil.info("Usage", "mute <@User>").build()).build();
    Member target = message.getGuild().getMember(message.getMentionedUsers().get(0));
    if (!message.getGuild().getSelfMember().canInteract(target))
        return new MessageBuilder().setEmbed(EmbedUtil.error("No permission", "Sorry i can't mute this user! His/her role is higher than yours.").build()).build();

    TextChannel channel = message.getTextChannel();
    if (channel.getPermissionOverride(target) == null)
        channel.createPermissionOverride(target).complete();
    if (channel.getPermissionOverride(target).getDenied().contains(Permission.MESSAGE_WRITE))
        return new MessageBuilder().setEmbed(EmbedUtil.error("Already muted", "This user is already muted.").build()).build();
    message.getGuild().getTextChannels().forEach(c -> {
        if (c.getPermissionOverride(target) == null)
            c.createPermissionOverride(target).complete();
        c.getPermissionOverride(target).getManager().deny(Permission.MESSAGE_WRITE).queue();
    });
    PrivateChannel targetch = target.getUser().openPrivateChannel().complete();
    targetch.sendMessage(EmbedUtil.info("Muted", "You got muted on `" + message.getGuild().getName() + "` by " + message.getAuthor().getAsMention()).build()).queue();
    return new MessageBuilder().setEmbed(EmbedUtil.success("Muted", "Successfully muted " + target.getAsMention()).build()).build();
}
项目:Rubicon    文件:CommandBan.java   
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
    Message msg = parsedCommandInvocation.getMessage();
    if (msg.getMentionedUsers().isEmpty()) {
        return new MessageBuilder().setEmbed(EmbedUtil.info("Usage", "ban <@User>").build()).build();
    }
    Member target = msg.getGuild().getMember(msg.getMentionedUsers().get(0));
    if (!msg.getGuild().getSelfMember().canInteract(target)) {
        return new MessageBuilder().setEmbed(EmbedUtil.error("No permissions", "Sorry I can't ban this User.").build()).build();
    } else {
        if (!target.getUser().isBot()) {
            PrivateChannel channel = target.getUser().openPrivateChannel().complete();
            channel.sendMessage(EmbedUtil.success("Banned", "You got banned").build()).queue();
        }
        msg.getGuild().getController().ban(target, 7).queue();
        return new MessageBuilder().setEmbed(EmbedUtil.success("Banned", "Successfully banned " + target.getAsMention()).build()).build();
    }
}
项目:Rubicon    文件:RemindHandler.java   
private void remind(){
    if (!open)
        throw new IllegalStateException("Remind is not open any more");

    PrivateChannel pc = getAuthor().openPrivateChannel().complete();
    pc.sendMessage(new EmbedBuilder()
            .setColor(Colors.COLOR_SECONDARY)
            .setAuthor(getAuthor().getName(),"http://rubicon.fun",getAuthor().getAvatarUrl())
            .setTitle("Hey, "+ getAuthor().getName() + " you wanted to be Reminded to do:")
            .setDescription("```fix\n"+remindmsg+"```")
    .build()
    ).queue();


    delete();
}
项目:Amme    文件:kick.java   
@Override
public void action(String[] args, GuildMessageReceivedEvent event) throws ParseException, IOException {
        Guild g = event.getGuild();
        if (core.permissionHandler.check(2, event))
        if (args.length < 2) event.getChannel().sendMessage(help());
        String reason = String.join(" ", args).split(args[0])[1];
        User kick =  event.getMessage().getMentionedUsers().get(0);
    String channel = SQL.getValue(g, "logchannel");
        event.getGuild().getTextChannelById(channel).sendMessage(":mans_shoe: " + kick.getAsMention() + " got kicked by " + event.getAuthor().getAsMention() + " (" + event.getMember().getRoles().get(0).getName() + ").\n\n" +
                "Reason: " + reason
        ).queue();
    event.getChannel().sendMessage(":white_check_mark: Sucessfully kicked" + kick.getName()).queue();
    PrivateChannel pc = event.getMessage().getMentionedUsers().get(0).openPrivateChannel().complete();
    pc.sendMessage(
            "Sorry, you got kicked from Server " + event.getGuild().getName() + " by " + event.getAuthor().getAsMention() + " (" + event.getMember().getRoles().get(0).getName() + ").\n\n" +
                    "Reason: " + reason
    ).queue();

    event.getGuild().getController().kick(event.getGuild().getMember(event.getMessage().getMentionedUsers().get(0))
    , reason).queue();

}
项目:Amme    文件:guildJoin.java   
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
    Guild guild = event.getGuild();
    if(!SQL.ifGuildExists(guild))
        SQL.createServer(guild);
    if (event.getMember().getUser().isBot()) return;
    if (event.getGuild().getId().equals("307084334198816769")) return;
    PrivateChannel pc = event.getMember().getUser().openPrivateChannel().complete();
    if(SQL.getValue(event.getGuild(), "autorole").equals("0")) {
        pc.sendMessage(
                "**Hey,** " + event.getMember().getAsMention() + " and welcome on " + event.getGuild().getName() + " :wave:\n\n" +
                        "Now, have a nice day and a lot of fun on the server! ;)"
        ).queue();


    }else {
        try {
            event.getGuild().getController().addRolesToMember(event.getMember(), event.getGuild().getRolesByName(SQL.getValue(event.getGuild(), "autorole"), true)).queue();
            pc.sendMessage(
                    "**Hey,** " + event.getMember().getAsMention() + " and welcome on " + event.getGuild().getName() + " :wave:\n\n" +
                            "You automatically got the Role `" + SQL.getValue(event.getGuild(), "autorole") + "` \n" +
                            "Now, have a nice day and a lot of fun on the server! ;)"
            ).queue();
        } catch (Exception e) {
            e.printStackTrace();
            PrivateChannel ow = event.getGuild().getOwner().getUser().openPrivateChannel().complete();
            ow.sendMessage("Please enter a valid Autorole Role!").queue();
            ow.sendMessage(Main.commands.get("settings").help() + "\n Only in Guild do not send commands at PM!");
        }
        String enabled = SQL.getValue(guild, "joinchannel");
        String channelid = SQL.getValue(guild, "joinchannel");
        String joinmessage = SQL.getValue(guild, "joinmessage").replace("%user%", event.getUser().getAsMention()).replace("%guild%", guild.getName());
        if (!enabled.equals("0")) {
            TextChannel channel = guild.getTextChannelById(channelid);
            channel.sendTyping().queue();
            channel.sendMessage(joinmessage).queue();
        }
    }
}
项目:krobot    文件:UserUtils.java   
/**
 * Get the private channel of the given user. Opens it if needed.
 *
 * @param user The user private channel
 *
 * @return The private channel
 *
 * @deprecated Deprecated in JDA, use now {@link User#openPrivateChannel()} directly.
 */
public static PrivateChannel privateChannel(@NotNull User user)
{
    if (!user.hasPrivateChannel())
    {
        try
        {
            return user.openPrivateChannel().submit().get();
        }
        catch (InterruptedException | ExecutionException ignored)
        {
        }
    }

    return user.getPrivateChannel();
}
项目:Tazbot    文件:SendMessage.java   
public static void sendMessage(String channelId, Message message) {
    // Try to send to guild
    TextChannel tc = Bot.getJDA().getTextChannelById(channelId);
    if (tc != null) {
        sendMessage(tc, message);
        return;
    }
    // Try to send to private
    PrivateChannel pc = Bot.getJDA().getPrivateChannelById(channelId);
    if (pc != null) {
        sendPrivate(pc, message);
        return;
    }
    // Failed to send message. Could not find channel with channelId
    MessageLogger.failedSendIdMessage(channelId, message);
}
项目:Tazbot    文件:SendMessage.java   
public static void sendDeveloper(Message message) {
    List<PrivateChannel> cs = new ArrayList<PrivateChannel>();
    // If dev has debug flag = true, add their private channel to list
    ConfigManager.getInstance().getConfig().getDevs().stream()
        .forEach(d -> {
            if (d.isDebug()) {
                cs.add(Bot.getJDA().getUserById(d.getId()).getPrivateChannel());
            }
        });

    if (!cs.isEmpty()) {
        // Send debug messages
        for (PrivateChannel c : cs) {
            sendPrivate(c, message);
        }
    }
}
项目:TransparentDiscord    文件:UIPrivateChat.java   
/**
 * Constructs a private channel from the given parameter
 * @param privateChannel the private channel to construct this UI around
 */
public UIPrivateChat(PrivateChannel privateChannel) {
    super();
    this.channel = privateChannel;
    this.messageHistory = privateChannel.getHistory();

    //Set up gridbag to add new messages
    c = new GridBagConstraints();
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1;
    c.fill = GridBagConstraints.HORIZONTAL;

    //Get some message history and add it to the message list
    //Message history in order from newest to oldest
    messageHistory.retrievePast(20).queue(messages -> {
        newestGroup = oldestGroup = new UIMessageGroup(messages.get(0));
        messageList.add(oldestGroup,c,0);

        //Going from newest to oldest...
        for (int i = 1; i < messages.size(); i++) {
            if (oldestGroup.canAddMessage(messages.get(i))) {
                oldestGroup.addMessage(messages.get(i));
            }
            else {
                oldestGroup = new UIMessageGroup(messages.get(i));
                messageList.add(oldestGroup,c,0);
            }
        }

        refresh();
        scrollToBottom();
        doneLoad = true;
    });

    add(new UITitleBar(channel.getName(), TransparentDiscord.chatWindow), BorderLayout.NORTH);
}
项目:TransparentDiscord    文件:UIChannelList.java   
/**
 * Add a list of PrivateChats to the UI
 * @param channels the channels to add
 */
public void addPrivateChannels(List<PrivateChannel> channels) {
    List<UIChannelListItem> uiChannels = UIChannelListItem.loadPrivateChannels(channels);
    Collections.sort(uiChannels);
    for (UIChannelListItem item : uiChannels) {
        channelList.add(item, c, channelList.getComponentCount());
        channelItems.put(item.getID(), item);
    }
}
项目:TransparentDiscord    文件:UIChannelList.java   
public void addGroupsAndPrivateChannels(List<Group> groups, List<PrivateChannel> channels) {
    List<UIChannelListItem> uiItems = UIChannelListItem.loadGroups(groups);
    uiItems.addAll(UIChannelListItem.loadPrivateChannels(channels));
    Collections.sort(uiItems);
    for (UIChannelListItem item : uiItems) {
        channelList.add(item, c, channelList.getComponentCount());
        channelItems.put(item.getID(), item);
    }
}
项目:Supreme-Bot    文件:Util.java   
public static final boolean sendPrivateMessage(User user, String message) {
    try {
        final PrivateChannel privateChannel = user.openPrivateChannel().complete();
        privateChannel.sendMessage(message).queue();
        privateChannel.close();
        return true;
    } catch (Exception ex) {
        System.err.println(ex);
        return false;
    }
}
项目:Supreme-Bot    文件:Util.java   
public static final boolean sendPrivateMessageFormat(User user, String message, Object... format) {
    try {
        final PrivateChannel privateChannel = user.openPrivateChannel().complete();
        privateChannel.sendMessageFormat(message, format).queue();
        privateChannel.close();
        return true;
    } catch (Exception ex) {
        System.err.println(ex);
        return false;
    }
}
项目:Supreme-Bot    文件:Util.java   
public static final boolean sendPrivateMessage(User user, Message message) {
    try {
        final PrivateChannel privateChannel = user.openPrivateChannel().complete();
        privateChannel.sendMessage(message).queue();
        privateChannel.close();
        return true;
    } catch (Exception ex) {
        System.err.println(ex);
        return false;
    }
}
项目:Supreme-Bot    文件:Util.java   
public static final boolean sendPrivateMessage(User user, MessageEmbed message) {
    try {
        final PrivateChannel privateChannel = user.openPrivateChannel().complete();
        privateChannel.sendMessage(message).queue();
        privateChannel.close();
        return true;
    } catch (Exception ex) {
        System.err.println(ex);
        return false;
    }
}
项目:Supreme-Bot    文件:Util.java   
public static final Message sendAndWaitPrivateMessage(User user, String message) {
    try {
        final PrivateChannel privateChannel = user.openPrivateChannel().complete();
        final Message temp = privateChannel.sendMessage(message).complete();
        privateChannel.close();
        return temp;
    } catch (Exception ex) {
        System.err.println(ex);
        return null;
    }
}
项目:Supreme-Bot    文件:Util.java   
public static final Message sendAndWaitPrivateMessageFormat(User user, String message, Object... format) {
    try {
        final PrivateChannel privateChannel = user.openPrivateChannel().complete();
        final Message temp = privateChannel.sendMessageFormat(message, format).complete();
        privateChannel.close();
        return temp;
    } catch (Exception ex) {
        System.err.println(ex);
        return null;
    }
}
项目:Supreme-Bot    文件:Util.java   
public static final Message sendAndWaitPrivateMessage(User user, Message message) {
    try {
        final PrivateChannel privateChannel = user.openPrivateChannel().complete();
        final Message temp = privateChannel.sendMessage(message).complete();
        privateChannel.close();
        return temp;
    } catch (Exception ex) {
        System.err.println(ex);
        return null;
    }
}
项目:Supreme-Bot    文件:Util.java   
public static final Message sendAndWaitPrivateMessage(User user, MessageEmbed message) {
    try {
        final PrivateChannel privateChannel = user.openPrivateChannel().complete();
        final Message temp = privateChannel.sendMessage(message).complete();
        privateChannel.close();
        return temp;
    } catch (Exception ex) {
        System.err.println(ex);
        return null;
    }
}
项目:NoMoreOversleeps    文件:IntegrationDiscord.java   
public void send(SendableMessage message)
{
    if (jda != null)
    {
        String actualMessage = "`NMO` " + message.message;
        switch (message.targetType)
        {
        case SERVER:
            TextChannel channel = jda.getTextChannelById(message.targetID);
            if (channel != null)
            {
                channel.sendMessage(actualMessage).complete();
            }
            break;
        case GROUP:
            Group group = jda.asClient().getGroupById(message.targetID);
            if (group != null)
            {
                group.sendMessage(actualMessage).complete();
            }
            break;
        case USER:
            User user = jda.getUserById(message.targetID);
            if (user != null)
            {
                PrivateChannel pchannel = user.openPrivateChannel().complete();
                pchannel.sendMessage(actualMessage).complete();
            }
            break;
        }
    }
}
项目:legendarybot    文件:DebugGuildCommand.java   
@Override
public void execute(MessageReceivedEvent event, String[] args) {
    final Guild[] guildEntry = {null};
    getBot().getJDA().forEach((jda -> {
        if (guildEntry[0] == null) {
            guildEntry[0] = jda.getGuildById(args[0]);
        }

    }));

    if (guildEntry[0] != null) {
        Guild guild = guildEntry[0];
        StringBuilder builder = new StringBuilder();
        PrivateChannel channel = event.getAuthor().openPrivateChannel().complete();
        builder.append("Guild " + guild.getName() + "\n");
        builder.append("Roles:\n");
        guild.getRoles().forEach((role -> builder.append(role.getName() + "\n")));
        builder.append("Config:\n");
        builder.append("Guild Name: " + getBot().getGuildSettings(guild).getGuildName()+ "\n");
        builder.append("Region Name: "  + getBot().getGuildSettings(guild).getRegionName()+ "\n");
        builder.append("Realm name: " + getBot().getGuildSettings(guild).getWowServerName()+ "\n");
        builder.append("WoW Rank config:\n");
        builder.append("Rank 0: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_0")+ "\n");
        builder.append("Rank 1: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_1")+ "\n");
        builder.append("Rank 2: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_2")+ "\n");
        builder.append("Rank 3: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_3")+ "\n");
        builder.append("Rank 4: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_4")+ "\n");
        builder.append("Rank 5: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_5")+ "\n");
        builder.append("Rank 6: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_6")+ "\n");
        builder.append("Rank 7: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_7")+ "\n");
        builder.append("Rank 8: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_8")+ "\n");
        builder.append("Rank 9: " + getBot().getGuildSettings(guild).getSetting("wowlink_rank_9")+ "\n");
        builder.append("Rank Enabled: " + getBot().getGuildSettings(guild).getSetting("wowlink_rankset")+ "\n");
        channel.sendMessage(builder.toString()).queue();

    }
}
项目:BeamTeamDiscordBot    文件:JDAManager.java   
public static PrivateChannel getPrivateChannel(User user) {
    if (!user.hasPrivateChannel()) {
        user.openPrivateChannel();
    }

    return user.getPrivateChannel();
}
项目:BullyBot    文件:Queue.java   
/**
 * Creates a new game.
 * Removes players in-game from other queues.
 * Sends notification to the pug channel and to each player in queue.
 */
private void popQueue() {
    String names = "";
    List<User> players = new ArrayList<User>(playersInQueue);
    TextChannel pugChannel = ServerManager.getServer(guildId).getPugChannel();

    // Send alert to players and compile their names
    for(User u : players){
        names += u.getName() + ", ";
        PrivateChannel c = u.openPrivateChannel().complete();
        c.sendMessage(String.format("`Your game: %s has started!`", name)).queue();
    }
    names = names.substring(0, names.lastIndexOf(","));

    // Create Game and add to the list of active games
    Game newGame = new Game(guildId, name, players);
    games.add(newGame);

    // Remove players from all other queues
    ServerManager.getServer(guildId).getQueueManager().purgeQueue(players);

    // Generate captain string
    String captainString = "";
    if(ServerManager.getServer(guildId).getSettings().randomizeCaptains()){
        captainString = String.format("**Captains:** <@%s> & <@%s>", newGame.getCaptains()[0].getId(), newGame.getCaptains()[1].getId());
    }

    // Send game start message to pug channel
    pugChannel.sendMessage(Utils.createMessage(String.format("Game: %s starting%n", name), String.format("%s%n%s", names, captainString), Color.YELLOW)).queueAfter(2, TimeUnit.SECONDS);

    /*String servers = new CmdPugServers().getServers(guildId, null);
    if(!servers.equals("N/A")){
        pugChannel.sendMessage(Utils.createMessage("`Pug servers:`", servers, true)).queueAfter(2, TimeUnit.SECONDS);
    }*/
}
项目:Tazbot    文件:MessageCommand.java   
@Override
public void onCommand(MessageReceivedEvent e, String[] args) {
    if (args.length > 2) {
        String message = e.getMessage().getRawContent().replace(getAliases().get(0) + " ", "");
        message = message.substring(message.indexOf(" ")+1);
        TextChannel tc = e.getJDA().getTextChannelById(args[1]);
        VoiceChannel vc = e.getJDA().getVoiceChannelById(args[1]);
        PrivateChannel pc = e.getJDA().getPrivateChannelById(args[1]);
        if (tc != null) {
            try {
                tc.sendMessage(message);
                SendMessage.sendMessage(e, "Successfully sent message.");
            }
            catch (PermissionException ex) {
                SendMessage.sendMessage(e, "Error: Could not send message. The bot does not have read/write permission.");
            }
        }
        if (vc != null) {
            SendMessage.sendMessage(e, "Error: Can not send message to a voice channel.");
        }
        if (pc != null) {
            pc.sendMessage(message);
            SendMessage.sendMessage(e, "Successfully sent message.");
        }
    }
    else {
        SendMessage.sendMessage(e, "Error: Incorrect usage.");
    }
}
项目:Tazbot    文件:CGUInformation.java   
public static String getChannelInfo(String id, JDA jda) {
    TextChannel tc = jda.getTextChannelById(id);
    VoiceChannel vc = jda.getVoiceChannelById(id);
    PrivateChannel pc = jda.getPrivateChannelById(id);
    if (tc != null) {
        return getChannelInfo(tc);
    }
    if (vc != null) {
        return getChannelInfo(vc);
    }
    if (pc != null) {
        return getChannelInfo(pc);
    }
    return null;
}
项目:Samaritan    文件:Samaritan.java   
/**
 * Shuts Samaritan down.
 *
 * @param exitSystem If true, will execute a 'System.exit(0);'
 */
public final void shutdown(boolean exitSystem) {
    for (PrivateMessageChatThread chatThread : getPrivateMessageListener().getChatThreads().values()) {
        PrivateChannel privateChannel = (PrivateChannel) chatThread.getMessageChannel();
        privateChannel.sendMessage("I must go, a reboot is in the queue!\nYou can try speaking to me again in a few moments.\nGood bye, my dear " + privateChannel.getUser().getName() + ".");
    }
    try {
        jda.getSelfUser().getManager().setName("Samaritan");
    } catch (Exception exc) {

    }
    jda.shutdown();
    if (exitSystem)
        System.exit(0);
}
项目:JDA    文件:UserImpl.java   
@Override
public RestAction<PrivateChannel> openPrivateChannel()
{
    if (privateChannel != null)
        return new RestAction.EmptyRestAction<>(getJDA(), privateChannel);

    if (fake)
        throw new IllegalStateException("Cannot open a PrivateChannel with a Fake user.");

    Route.CompiledRoute route = Route.Self.CREATE_PRIVATE_CHANNEL.compile();
    JSONObject body = new JSONObject().put("recipient_id", getId());
    return new RestAction<PrivateChannel>(api, route, body)
    {
        @Override
        protected void handleResponse(Response response, Request<PrivateChannel> request)
        {
            if (response.isOk())
            {
                PrivateChannel priv = api.getEntityBuilder().createPrivateChannel(response.getObject());
                UserImpl.this.privateChannel = priv;
                request.onSuccess(priv);
            }
            else
            {
                request.onFailure(response);
            }
        }
    };
}
项目:JDA    文件:UserImpl.java   
public PrivateChannel getPrivateChannel()
{
    if (!hasPrivateChannel())
        throw new IllegalStateException("There is no PrivateChannel for this user yet! Use User#openPrivateChannel() first!");

    return privateChannel;
}
项目:TransparentDiscord    文件:UIChannelList.java   
/**
 * Add a PrivateChannel to the UI
 * @param privateChannel the PrivateChannel to add
 */
public void addPrivateChannel(PrivateChannel privateChannel) {
    UIChannelListItem item = new UIChannelListItem(privateChannel);
    channelList.add(item,c,0);
    channelItems.put(item.getID(), item);
}
项目:DiscordIntegrationCore    文件:FakeUser.java   
@Override
public RestAction<PrivateChannel> openPrivateChannel() {
    return null;
}
项目:Supreme-Bot    文件:DefaultMessageEvent.java   
@Override
public PrivateChannel getPrivateChannel() {
    return message.getPrivateChannel();
}
项目:MantaroRPG    文件:ShardedUser.java   
@Override
public RestAction<PrivateChannel> openPrivateChannel() {
    return random(users).openPrivateChannel();
}
项目:MantaroRPG    文件:ShardedUser.java   
@Override
public PrivateChannel getPrivateChannel() {
    return random(users).getPrivateChannel();
}
项目:Minecord    文件:MsgCommand.java   
public Result run(String[] argsOrig, MessageReceivedEvent e) {

    //Check for proper argument length
    if (argsOrig.length < 2) {
        return new Result(Outcome.WARNING, ":warning: Please specify a message.");
    }

    //Extract user
    String[] args = ArrayUtils.remove(MessageUtils.getContent(e.getMessage(), true), 0);
    User user = null;
    if (args[0].matches(MessageUtils.mentionRegex)) {
        user = e.getMessage().getMentionedUsers().get(0);
        if (user.getId() == e.getJDA().getSelfUser().getId()) {
            user = e.getMessage().getMentionedUsers().get(1);
        }
    } else if (args[0].matches(MessageUtils.idRegex)) {
        user = e.getJDA().getUserById(args[0]);
    } else {
        return new Result(Outcome.ERROR, ":x: Not a valid user!");
    }

    //Send the message
    String msg = null;
    try {
        PrivateChannel channel = user.openPrivateChannel().submit().get();
        msg = String.join(" ", ArrayUtils.remove(args, 0));
        channel.sendMessage(msg).queue();
    } catch (InterruptedException | ExecutionException ex) {
        ex.printStackTrace();
        return new Result(Outcome.ERROR, ":x: An exception occured.");
    }

    EmbedBuilder eb = new EmbedBuilder();
    eb.setAuthor(e.getAuthor().getName() + " (" + e.getAuthor().getId() + ")",
        null, e.getAuthor().getAvatarUrl());
    eb.setDescription("**Sent a DM to " + user.getName() + " (" + user.getId() + "):**\n" + msg);
    eb.setThumbnail(user.getAvatarUrl());
    MessageUtils.log(eb.build());

    return new Result(Outcome.SUCCESS);
}
项目:Phonon    文件:CommandListener.java   
@Override
public void onMessageReceived(MessageReceivedEvent event) {
    CoreConfig config = this.phononPlugin.getConfigAdapter(CoreModule.ID, CoreConfigAdapter.class).get().getNodeOrDefault();

    if (event.getMessage().getRawContent().startsWith(config.getPrefix()) && !event.getMessage().getAuthor().isBot()) {
        DiscordCommandSource source = new DiscordCommandSource(event.getAuthor(), event.getChannel());

        int end = event.getMessage().getRawContent().indexOf(" ");
        String commandName;
        String arguments;
        if (end == -1) {
            commandName = event.getMessage().getRawContent().substring(1);
            arguments = "";
        } else {
            commandName = event.getMessage().getRawContent().substring(1, end);
            arguments = event.getMessage().getRawContent().substring(end + 1);
        }


        if (aliases.containsKey(commandName)) {
            IDiscordCommand command = aliases.get(commandName);
            CommandElement args= null;
            try {
                CommandArgs commandArgs = new CommandArgs(arguments,
                        InputTokenizer.quotedStrings(false).tokenize(arguments, true));
                CommandContext context = new CommandContext();
                args = GenericArguments.seq(command.getArgs());
                args.parse(source, commandArgs, context);
                if (commandArgs.hasNext()) {
                    commandArgs.next();
                    throw commandArgs.createError(t("Invalid arguments!"));
                }
                command.execute(event.getAuthor(), context, event.getChannel());
            } catch (ArgumentParseException e) {
                String message = "Invalid Arguments";
                if (e.getMessage() != null) {
                    message = e.getMessage();
                }

                if (args == null) {
                    event.getChannel().sendMessage(message).queue();
                } else {
                    event.getChannel().sendMessage(message + System.lineSeparator() +
                            config.getPrefix() + commandName + args.getUsage(source).toPlain()).queue();
                }
            }

            if (!(event.getChannel() instanceof PrivateChannel)) {
                event.getMessage().delete().queue();
            }
        }
    }
}
项目:krobot    文件:ExceptionHandler.java   
/**
 * Handle a command exception
 *
 * @param throwable The exception thrown
 * @param command The command that was being handled
 * @param args The arguments given to the command
 * @param context The command context
 */
public void handle(@NotNull Throwable throwable, @NotNull Command command, @NotNull List<String> args, @NotNull CommandContext context)
{
    if (throwable instanceof BadSyntaxException)
    {
        context.sendMessage(Dialog.warn("Bad command syntax", Markdown.underline("Syntax :") + " " + command.toString("", false) + (throwable.getMessage() != null ? "\n\n" + throwable.getMessage() : "")));
        return;
    }
    else if (throwable instanceof UserNotFoundException)
    {
        context.sendMessage(Dialog.warn("Unknown user", throwable.getMessage()));
        return;
    }
    else if (throwable instanceof BotNotAllowedException)
    {
        context.sendMessage(Dialog.error("Missing required permission", throwable.getMessage()));
        return;
    }
    else if (throwable instanceof UserNotAllowedException)
    {
        context.sendMessage(Dialog.error("You're missing a required permission", throwable.getMessage()));
        return;
    }

    LOGGER.error("Exception while executing the command : " + command.toString("", false), throwable);

    String report = makeCrashReport(throwable, command, args, context);

    try
    {
        deleteAfter(context.sendMessage(Dialog.error("Command crashed !", "A crash report has been sent to you " + context.getUser().getAsMention() + " . Please send it to the developer as soon as possible !")).get(), 5000);
    }
    catch (InterruptedException | ExecutionException ignored)
    {
    }

    PrivateChannel channel = context.getUser().openPrivateChannel().complete();
    for (String message : splitMessageKeepLines(report, MAX_MESSAGE_CHARS - Markdown.code("").length()))
    {
        channel.sendMessage(Markdown.code(message)).queue();
    }
}
项目:Tazbot    文件:MessageLogger.java   
public static void sendPrivateMessage(PrivateChannel c, Message message) {
    String s = getDate() + " TO PRIVATE " + JDAUtil.userToString(c.getUser()) + " CHANNEL ID " + c.getId() + ": " + stripNewLine(message);
    writeLog(s);
}
项目:Tazbot    文件:CGUInformation.java   
public static String getChannelInfo(PrivateChannel c) {
    return String.format("```Private Channel With: %s\n"
            + "User's ID: %s\n"
            + "ID: %s```",
            c.getUser().getName(), c.getUser().getId(), c.getId());
}