當前位置: 首頁>>代碼示例>>Java>>正文


Java User類代碼示例

本文整理匯總了Java中net.dv8tion.jda.core.entities.User的典型用法代碼示例。如果您正苦於以下問題:Java User類的具體用法?Java User怎麽用?Java User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


User類屬於net.dv8tion.jda.core.entities包,在下文中一共展示了User類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: executeWithConfig

import net.dv8tion.jda.core.entities.User; //導入依賴的package包/類
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    final User user = commandEvent.getAuthor();
    final String userName = user.getName();
    final Locale localeForUser = localeService.getLocaleForUser(user);
    String gymName = commandEvent.getArgs();
    final Gym gym = gymRepository.search(user, gymName, config.getRegion());
    final Raid raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
    final SignUp removed = raid.remove(user, raidRepository);
    if (removed != null) {
        commandEvent.reactSuccess();
        removeOriginMessageIfConfigSaysSo(config, commandEvent);
    } else {
        final String message =
                localeService.getMessageFor(LocaleService.NO_SIGNUP_AT_GYM, localeForUser, userName, gym.getName());
        replyErrorBasedOnConfig(config, commandEvent, new UserMessedUpException(user, message));
    }
}
 
開發者ID:magnusmickelsson,項目名稱:pokeraidbot,代碼行數:19,代碼來源:RemoveSignUpCommand.java

示例2: privateChannel

import net.dv8tion.jda.core.entities.User; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:krobot-framework,項目名稱:krobot,代碼行數:25,代碼來源:UserUtils.java

示例3: onCommand

import net.dv8tion.jda.core.entities.User; //導入依賴的package包/類
@Override
public boolean onCommand(Message message, String[] args) {
    User user = message.getAuthor();
    if (args.length > 0) {
        user = MentionableUtil.getUser(message, args);
    }

    if (user == null) {
        return sendErrorMessage(message, "I found no users with the name or ID of `%s`", args[0]);
    }

    MessageFactory.makeSuccess(message, ":id: of the user **:target** is `:targetid`")
        .set("target", user.getAsMention())
        .set("targetid", user.getId())
        .queue();
    return true;
}
 
開發者ID:avaire,項目名稱:avaire,代碼行數:18,代碼來源:UserIdCommand.java

示例4: checkIfInputIsValidAndUserHasRights

import net.dv8tion.jda.core.entities.User; //導入依賴的package包/類
private void checkIfInputIsValidAndUserHasRights(CommandEvent commandEvent, Config config, User user, Raid raid,
                                                 LocalDateTime newDateTime) {
    verifyIsModOrHasGroupForRaid(commandEvent, user, raid, config);
    assertTimeInRaidTimespan(user, newDateTime, raid, localeService);
    assertGroupTimeNotBeforeNow(user, newDateTime, localeService);
    if (raidRepository.existsGroupForRaidAt(raid, newDateTime)) { // Check for any user
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.GROUP_NOT_ADDED,
                localeService.getLocaleForUser(user), String.valueOf(raid)));
    }

    if (raidRepository.hasManyGroupsForRaid(user, raid)) {
        throw new UserMessedUpException(user, localeService.getMessageFor(
                LocaleService.MANY_GROUPS_FOR_RAID,
                localeService.getLocaleForUser(user), String.valueOf(raid)));
    }
}
 
開發者ID:magnusmickelsson,項目名稱:pokeraidbot,代碼行數:17,代碼來源:AlterRaidCommand.java

示例5: execute

import net.dv8tion.jda.core.entities.User; //導入依賴的package包/類
@Override
public void execute(Member author, User authorUser, MessageChannel channel, Message message, String parameters, Map<String, CommandStructure> commandList) {
    Long guildID = author.getGuild().getIdLong();
    if (hasPermission(author)) {
        //toggle command
        Boolean delCmd = !dbMan.getDeleteCommand(guildID);
        try {
            dbMan.setDeleteCommand(guildID, delCmd);
            if (!delCmd) {
                message.addReaction(":heavy_check_mark:").queue();
            }
        } catch (SQLException e) {
            channel.sendMessage(localize(channel, "command.toggle_delete.error.sql")).queue();
        }


    }

}
 
開發者ID:IANetworks,項目名稱:Ducky-Mc-Duckerson,代碼行數:20,代碼來源:DeleteCommandCS.java

示例6: execute

import net.dv8tion.jda.core.entities.User; //導入依賴的package包/類
@Override
public void execute(Member author, User authorUser, MessageChannel channel, Message message, String parameters, Map<String, CommandStructure> commandList) {
    Long guildID = author.getGuild().getIdLong();

    if (!dbMan.isWerewolfOn(guildID)) {
        //Werewolf is turned off for this guild, so ignore the command
        return;
    }

    if (hasPermission(author)) {
        //check to make sure that we're in a gamestarted state
        GameState gs = ww.getWerewolfGameState(guildID);
        if (gs != null && gs == GameState.GAMESTART) {
            ww.joinGame(guildID, author);
        }
    }
}
 
開發者ID:IANetworks,項目名稱:Ducky-Mc-Duckerson,代碼行數:18,代碼來源:WerewolfJoinCS.java

示例7: sendPrivateMessage

import net.dv8tion.jda.core.entities.User; //導入依賴的package包/類
private void sendPrivateMessage(User user, String content)
{
    // openPrivateChannel provides a RestAction<PrivateChannel>
    // which means it supplies you with the resulting channel
    user.openPrivateChannel().queue((channel) ->
    {
        // value is a parameter for the `accept(T channel)` method of our callback.
        // here we implement the body of that method, which will be called later by JDA automatically.
        try {
            channel.sendMessage(content).queue(m -> {}, m ->{
                LOGGER.warn("Could not send private message for tracking " + this + ": " + m.getMessage());
            });
            // here we access the enclosing scope variable -content-
            // which was provided to sendPrivateMessage(User, String) as a parameter
        } catch (Throwable t) {
            LOGGER.warn("Could not send private message for tracking " + this + ": " + t.getMessage());
        }
    });
}
 
開發者ID:magnusmickelsson,項目名稱:pokeraidbot,代碼行數:20,代碼來源:PokemonTrackingTarget.java

示例8: assignRole

import net.dv8tion.jda.core.entities.User; //導入依賴的package包/類
public static void assignRole(UserData data) {
    User user = ZLevels.jda.getUserById(data.getUserId());
    Guild guild = ZLevels.jda.getGuildById(Config.SERVER);
    int level = data.getLevel();

    for (int requiredLevel : roles.keySet()) {
        if (level < requiredLevel) return;

        Member member = guild.getMember(user);
        Role role = guild.getRolesByName(roles.get(requiredLevel).getString("name"), false).get(0);

        if (member == null || role == null) return;
        if (member.getRoles().contains(role)) return;

        try {
            guild.getController().addRolesToMember(member, role).queue();
        } catch (Exception e) {
            ZLogger.warn("Could not assign role to " + user.getName() + "!");
        }
    }
}
 
開發者ID:ZP4RKER,項目名稱:zlevels,代碼行數:22,代碼來源:AutoRole.java

示例9: sendPrivateMsg

import net.dv8tion.jda.core.entities.User; //導入依賴的package包/類
/**
 * sends a message to a private message channel, opening the channel before use
 *, asynchronous (non-blocking)
 * @param content the message to send as a string
 * @param user the user to send the private message to
 * @param action a non null Consumer will do operations on the results returned
 */
public static void sendPrivateMsg(String content, User user, Consumer<Message> action )
{
    if (content.isEmpty()) return;
    if (user.isBot()) return;

    try
    {
        user.openPrivateChannel().queue(privateChannel -> sendMsg(content, privateChannel, action), null);
    }
    catch (PermissionException ignored) { }
    catch (Exception e)
    {
        Logging.exception( MessageUtilities.class, e );
    }
}
 
開發者ID:notem,項目名稱:Saber-Bot,代碼行數:23,代碼來源:MessageUtilities.java

示例10: getUserFromBearer

import net.dv8tion.jda.core.entities.User; //導入依賴的package包/類
public static User getUserFromBearer(JDA jda, String token) {
    try {
        JSONObject user =  Unirest.get(Requester.DISCORD_API_PREFIX + "/users/@me")
                .header("Authorization", "Bearer " + token)
                .header("User-agent", USER_AGENT)
                .asJson()
                .getBody()
                .getObject();

        if(user.has("id")){
            return jda.retrieveUserById(user.getString("id")).complete(true);
        }
    } catch (UnirestException | RateLimitedException ignored) {}

    return null;
}
 
開發者ID:Frederikam,項目名稱:GensokyoBot,代碼行數:17,代碼來源:DiscordUtil.java

示例11: handleMessages

import net.dv8tion.jda.core.entities.User; //導入依賴的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));
}
 
開發者ID:GloriousEggroll,項目名稱:quorrabot,代碼行數:25,代碼來源:DiscordAPI.java

示例12: doCommand

import net.dv8tion.jda.core.entities.User; //導入依賴的package包/類
@Override
protected void doCommand(CommandEvent e) {
    EmbedBuilder eb = new EmbedBuilder();
    JDA jda = getMcb().getBot().getJda();
    Color color = Bot.BOT_COLOR; //e.getGuild().getMember(jda.getSelfUser()).getColor()
    eb.setColor(color);
    eb.setDescription(Locale.getCommandsMessage("help.more").f(e.getClient().getPrefix()));
    if (e.getArgs().isEmpty()) {
        eb.setAuthor("Minecordbot Commands", null, null);
        eb.setThumbnail("https://vectr.com/cyrien/k3vhJlcOMS.png?width=168&height=168&select=k3vhJlcOMSpage0");
        eb = listCommands(eb);
        User user = jda.getUserById("193970511615623168");
        if (user != null) {
            eb.setFooter("Questions? contact " + user.getName() + "#" + user.getDiscriminator() + " or join https://discord.cyrien.us", user.getAvatarUrl());
            respond(e, eb.build());
        }
    }
}
 
開發者ID:CyR1en,項目名稱:Minecordbot,代碼行數:19,代碼來源:HelpCmd.java

示例13: action

import net.dv8tion.jda.core.entities.User; //導入依賴的package包/類
@Override
public void action(String[] args, GuildMessageReceivedEvent event) throws ParseException, IOException {
    if (core.permissionHandler.check(4, event)) return;

    String message = String.join(" ", args).split("@")[0];
    User memb = event.getMessage().getMentionedUsers().size() > 0 ?  event.getMessage().getMentionedUsers().get(0) : null;
    User author = event.getAuthor();
    TextChannel chan = event.getChannel();

    if (args.length < 2 || memb == null) {
        chan.sendMessage(new EmbedBuilder().setColor(Color.red).setDescription(help()).build()).queue();
        return;
    }
    event.getMessage().delete().queue();

    memb.openPrivateChannel().queue(pc -> pc.sendMessage(message.substring(0, message.length() - 1)).queue());
}
 
開發者ID:LeeDJD,項目名稱:Amme,代碼行數:18,代碼來源:say.java

示例14: trivia

import net.dv8tion.jda.core.entities.User; //導入依賴的package包/類
@Command(
        name = "trivia",
        description = "Play trivia",
        usage = "`>>trivia`: Play trivia",
        permission = CommandPermission.USER,
        category = CommandCategory.GAME
)
public static void trivia(@Argument("channel") TextChannel channel, @Argument("author") User author) {
    if(check(channel)) return;
    OpenTriviaDatabase.Question q = OpenTriviaDatabase.random();
    if(q == null) {
        channel.sendMessage("Error getting a question from open trivia database").queue();
        return;
    }
    TLongSet players = new TLongHashSet();
    players.add(author.getIdLong());
    EventManagerThread.current().newThread(()->{
        try {
            Thread.sleep(100);
        } catch(InterruptedException e) {
            return;
        }
        InteractiveOperations.create(channel.getIdLong(), 120, new Trivia(channel, players, q));
    }, "Game Starter").start();
}
 
開發者ID:natanbc,項目名稱:GabrielBot,代碼行數:26,代碼來源:GameCommands.java

示例15: getUserCharactersInGuild

import net.dv8tion.jda.core.entities.User; //導入依賴的package包/類
/**
 * Retrieve all characters of a player in a specific guild
 * @param user The user to get the characters from
 * @param guild The guild to retrieve the characters from.
 * @return A List containing all characters of a player that belong to a specific guild.
 */
public List<String> getUserCharactersInGuild(User user, Guild guild) {
    List<String> charactersList = new ArrayList<>();
    try {
        Connection conn = getBot().getDatabase().getConnection();
        PreparedStatement statement = conn.prepareStatement("SELECT * FROM user_characters WHERE user_id=? AND guildName=? AND region=?");
        statement.setString(1,user.getId());
        statement.setString(2, getBot().getGuildSettings(guild).getGuildName());
        statement.setString(3,getBot().getGuildSettings(guild).getRegionName());
        ResultSet set = statement.executeQuery();
        while(set.next()) {
            charactersList.add(set.getString("characterName"));
        }
        set.close();
        statement.close();
        conn.close();
    } catch (SQLException e) {
        e.printStackTrace();
        getBot().getStacktraceHandler().sendStacktrace(e);
    }
    return charactersList;
}
 
開發者ID:greatman,項目名稱:legendarybot,代碼行數:28,代碼來源:WoWLinkPlugin.java


注:本文中的net.dv8tion.jda.core.entities.User類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。