本文整理匯總了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));
}
}
示例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();
}
示例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;
}
示例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)));
}
}
示例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();
}
}
}
示例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);
}
}
}
示例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());
}
});
}
示例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() + "!");
}
}
}
示例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 );
}
}
示例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;
}
示例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));
}
示例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());
}
}
}
示例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());
}
示例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();
}
示例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;
}