• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java Javacord类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中de.btobastian.javacord.Javacord的典型用法代码示例。如果您正苦于以下问题:Java Javacord类的具体用法?Java Javacord怎么用?Java Javacord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

Javacord类属于de.btobastian.javacord包,在下文中一共展示了Javacord类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: loginBotAccount

点赞 3

import de.btobastian.javacord.Javacord; //导入依赖的package包/类
public static boolean loginBotAccount() {
    GlobalConfig config = mod.getConfig();

    if (StringUtils.isBlank(config.botToken)) {
        logger.warn("No Bot token is available! Messages can only get from and to authenticated players.");
        return false;
    }

    DiscordAPI defaultClient = mod.getBotClient();
    if (defaultClient != null && defaultClient.getToken().equals(config.botToken)) {
        return true;
    }

    if (defaultClient != null) {
        defaultClient.disconnect();
    }

    logger.info("Logging in to bot Discord account...");

    DiscordAPI client = Javacord.getApi(config.botToken, true);
    prepareBotClient(client, null);
    return true;
}
 

开发者ID:nguyenquyhy,
项目名称:DiscordBridge,
代码行数:24,
代码来源:LoginHandler.java

示例2: loginHumanAccount

点赞 3

import de.btobastian.javacord.Javacord; //导入依赖的package包/类
/**
 * @param player
 * @return
 */
public static boolean loginHumanAccount(Player player) {
    IStorage storage = mod.getStorage();

    if (storage != null) {
        String cachedToken = mod.getStorage().getToken(player.getUniqueId());
        if (StringUtils.isNotBlank(cachedToken)) {
            player.sendMessage(Text.of(TextColors.GRAY, "Logging in to Discord..."));

            DiscordAPI client = mod.getHumanClients().get(player.getUniqueId());
            if (client != null) {
                client.disconnect();
            } else {
                client = Javacord.getApi(cachedToken, false);
            }

            prepareHumanClient(client, player);
            return true;
        }
    }
    return false;
}
 

开发者ID:nguyenquyhy,
项目名称:DiscordBridge,
代码行数:26,
代码来源:LoginHandler.java

示例3: otp

点赞 3

import de.btobastian.javacord.Javacord; //导入依赖的package包/类
public static CommandResult otp(CommandSource commandSource, int code) {
    String ticket = MFA_TICKETS.remove(commandSource);
    if (ticket == null) {
        commandSource.sendMessage(Text.of(TextColors.RED, "No OTP auth queued!"));
        return CommandResult.empty();
    }
    try {
        HttpResponse<JsonNode> response = Unirest.post("https://discordapp.com/api/v6/auth/mfa/totp")
                .header("content-type", "application/json")
                .body(new JSONObject().put("code", String.format("%06d", code)).put("ticket", ticket))
                .asJson();
        if (response.getStatus() != 200) {
            commandSource.sendMessage(Text.of(TextColors.RED, "Wrong auth code! Retry with '/discord loginconfirm <email> <password>'"));
            return CommandResult.empty();
        }
        String token = response.getBody().getObject().getString("token");
        prepareHumanClient(Javacord.getApi(token, false), commandSource);
    } catch (UnirestException e) {
        e.printStackTrace();
        commandSource.sendMessage(Text.of(TextColors.RED, "Unexpected error!"));
        return CommandResult.empty();
    }

    return CommandResult.success();
}
 

开发者ID:nguyenquyhy,
项目名称:DiscordBridge,
代码行数:26,
代码来源:LoginHandler.java

示例4: getEmojiAsByteArray

点赞 2

import de.btobastian.javacord.Javacord; //导入依赖的package包/类
@Override
public Future<byte[]> getEmojiAsByteArray(FutureCallback<byte[]> callback) {
    ListenableFuture<byte[]> future =
            api.getThreadPool().getListeningExecutorService().submit(new Callable<byte[]>() {
                @Override
                public byte[] call() throws Exception {
                    logger.debug("Trying to get emoji {} from server {}", ImplCustomEmoji.this, server);
                    URL url = getImageUrl();
                    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
                    conn.setRequestMethod("GET");
                    conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
                    conn.setRequestProperty("User-Agent", Javacord.USER_AGENT);
                    InputStream in = new BufferedInputStream(conn.getInputStream());
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    byte[] buf = new byte[1024];
                    int n;
                    while (-1 != (n = in.read(buf))) {
                        out.write(buf, 0, n);
                    }
                    out.close();
                    in.close();
                    byte[] emoji = out.toByteArray();
                    logger.debug("Got emoji {} from server {} (size: {})",
                            ImplCustomEmoji.this, server, emoji.length);
                    return emoji;
                }
            });
    if (callback != null) {
        Futures.addCallback(future, callback);
    }
    return future;
}
 

开发者ID:BtoBastian,
项目名称:Javacord,
代码行数:33,
代码来源:ImplCustomEmoji.java

示例5: getAvatarAsByteArray

点赞 2

import de.btobastian.javacord.Javacord; //导入依赖的package包/类
@Override
public Future<byte[]> getAvatarAsByteArray(FutureCallback<byte[]> callback) {
    ListenableFuture<byte[]> future =
            api.getThreadPool().getListeningExecutorService().submit(new Callable<byte[]>() {
                @Override
                public byte[] call() throws Exception {
                    logger.debug("Trying to get avatar from user {}", ImplUser.this);
                    if (avatarId == null) {
                        logger.debug("User {} seems to have no avatar. Returning empty array!", ImplUser.this);
                        return new byte[0];
                    }
                    URL url = new URL("https://discordapp.com/api/v6/users/" + id + "/avatars/" + avatarId + ".jpg");
                    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
                    conn.setRequestMethod("GET");
                    conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
                    conn.setRequestProperty("User-Agent", Javacord.USER_AGENT);
                    InputStream in = new BufferedInputStream(conn.getInputStream());
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    byte[] buf = new byte[1024];
                    int n;
                    while (-1 != (n = in.read(buf))) {
                        out.write(buf, 0, n);
                    }
                    out.close();
                    in.close();
                    byte[] avatar = out.toByteArray();
                    logger.debug("Got avatar from user {} (size: {})", ImplUser.this, avatar.length);
                    return avatar;
                }
            });
    if (callback != null) {
        Futures.addCallback(future, callback);
    }
    return future;
}
 

开发者ID:BtoBastian,
项目名称:Javacord,
代码行数:36,
代码来源:ImplUser.java

示例6: getIconAsByteArray

点赞 2

import de.btobastian.javacord.Javacord; //导入依赖的package包/类
public Future<byte[]> getIconAsByteArray() {
    ListenableFuture<byte[]> future =
            api.getThreadPool().getListeningExecutorService().submit(new Callable<byte[]>() {
                @Override
                public byte[] call() throws Exception {
                    logger.debug("Trying to get icon from server {}", ImplServer.this);
                    if (iconHash == null) {
                        logger.debug("Server {} has default icon. Returning empty array!", ImplServer.this);
                        return new byte[0];
                    }
                    URL url = getIconUrl();
                    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
                    conn.setRequestMethod("GET");
                    conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
                    conn.setRequestProperty("User-Agent", Javacord.USER_AGENT);
                    InputStream in = new BufferedInputStream(conn.getInputStream());
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    byte[] buf = new byte[1024];
                    int n;
                    while (-1 != (n = in.read(buf))) {
                        out.write(buf, 0, n);
                    }
                    out.close();
                    in.close();
                    byte[] avatar = out.toByteArray();
                    logger.debug("Got icon from server {} (size: {})", ImplServer.this, avatar.length);
                    return avatar;
                }
            });
    return future;
}
 

开发者ID:BtoBastian,
项目名称:Javacord,
代码行数:32,
代码来源:ImplServer.java

示例7: connect

点赞 2

import de.btobastian.javacord.Javacord; //导入依赖的package包/类
/**
 * Attempts to establish a connection to the Discord Services, using a given
 * email address and a password.
 */
public void connect(String emailAddress, String password, String token) {
    // Grab the API.
    api = Javacord.getApi();
    connectedUsingToken = true;
    api.setToken(token, true);
    // Point to self as the Callback handler.
    api.connect(this);
}
 

开发者ID:JabJabJab,
项目名称:Sledgehammer,
代码行数:13,
代码来源:DiscordBot.java

示例8: login

点赞 2

import de.btobastian.javacord.Javacord; //导入依赖的package包/类
public static CommandResult login(CommandSource commandSource, String email, String password) {
    logout(commandSource, true);

    try {
        HttpResponse<JsonNode> response = Unirest.post("https://discordapp.com/api/v6/auth/login")
                .header("content-type", "application/json")
                .body(new JSONObject().put("email", email).put("password", password))
                .asJson();
        if (response.getStatus() != 200) {
            DiscordBridge.getInstance().getLogger().info("Auth response {} code with: {}", response.getStatus(), response.getBody());
            commandSource.sendMessage(Text.of(TextColors.RED, "Wrong email or password!"));
            return CommandResult.empty();
        }
        JSONObject result = response.getBody().getObject();
        if (result.has("mfa") && result.getBoolean("mfa")) {
            MFA_TICKETS.put(commandSource, result.getString("ticket"));
            commandSource.sendMessage(Text.of(TextColors.GREEN, "Additional authorization required! Please type '/discord otp <code>' within a code from your authorization app"));
        } else if (result.has("token")) {
            String token = result.getString("token");
            prepareHumanClient(Javacord.getApi(token, false), commandSource);
        } else {
            commandSource.sendMessage(Text.of(TextColors.RED, "Unexpected error!"));
        }
    } catch (UnirestException e) {
        e.printStackTrace();
        commandSource.sendMessage(Text.of(TextColors.RED, "Unexpected error!"));
        return CommandResult.empty();
    }

    return CommandResult.success();
}
 

开发者ID:nguyenquyhy,
项目名称:DiscordBridge,
代码行数:32,
代码来源:LoginHandler.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)