net.dv8tion.jda.api.JDAInfo Java Examples

The following examples show how to use net.dv8tion.jda.api.JDAInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BannerPrinter.java    From MantaroBot with GNU General Public License v3.0 6 votes vote down vote up
public BannerPrinter(int spaces) {
    try {
        List<String> lines = defaultBanner.get();
        StringBuilder builder = new StringBuilder();

        if (spaces >= 1) {
            builder.append("\n".repeat(spaces));
        }

        for (String line : lines) {
            String toPrint = line.replace("%version%", MantaroInfo.VERSION)
                    .replace("%jdaversion%", JDAInfo.VERSION);
            builder.append(toPrint).append("\n");
        }

        if (spaces > 1) {
            builder.append("\n".repeat(spaces - 1));
        }

        toPrint = builder.toString();
    } catch (Exception e) {
        e.printStackTrace();
        toPrint = "Exception arose while getting the default banner";
    }
}
 
Example #2
Source File: BannerPrinter.java    From MantaroBot with GNU General Public License v3.0 6 votes vote down vote up
public BannerPrinter(int spaces, DataManager<List<String>> dm) {
    List<String> lines = dm.get();
    StringBuilder builder = new StringBuilder();

    if (spaces >= 1) {
        builder.append("\n".repeat(spaces));
    }

    for (String line : lines) {
        String toPrint = line.replace("%version%", MantaroInfo.VERSION)
                .replace("%jdaversion%", JDAInfo.VERSION);
        builder.append(toPrint).append("\n");
    }

    if (spaces >= 1) {
        builder.append("\n".repeat(spaces));
    }

    toPrint = builder.toString();
}
 
Example #3
Source File: AudioWebSocket.java    From JDA with Apache License 2.0 6 votes vote down vote up
protected AudioWebSocket(
        AudioConnection audioConnection, ConnectionListener listener, String endpoint, Guild guild,
        String sessionId, String token, boolean shouldReconnect)
{
    this.audioConnection = audioConnection;
    this.listener = listener;
    this.guild = guild;
    this.sessionId = sessionId;
    this.token = token;
    this.shouldReconnect = shouldReconnect;

    keepAlivePool = getJDA().getAudioLifeCyclePool();

    //Append the Secure Websocket scheme so that our websocket library knows how to connect
    wssEndpoint = String.format("wss://%s/?v=%d", endpoint, JDAInfo.AUDIO_GATEWAY_VERSION);

    if (sessionId == null || sessionId.isEmpty())
        throw new IllegalArgumentException("Cannot create a voice connection using a null/empty sessionId!");
    if (token == null || token.isEmpty())
        throw new IllegalArgumentException("Cannot create a voice connection using a null/empty token!");
}
 
Example #4
Source File: InfoCommand.java    From Yui with Apache License 2.0 6 votes vote down vote up
@Override
public void onCommand(MessageReceivedEvent e, String[] args)
{

    MessageBuilder builder = new MessageBuilder();
    builder.append("__Yui Information__\n")
            .append("    **Version**:       " + YuiInfo.VERSION.toString().replace("_", "\\_") + "\n")
            .append("    **ID**:                " + e.getJDA().getSelfUser().getId() + "\n")
            .append("__Creator__\n")
            .append("    **Name**:          DV8FromTheWorld\n")
            .append("    **ID**:                107562988810027008\n")
            .append("    **Github**:        <http://code.dv8tion.net>\n")
            .append("__Development__\n")
            .append("    **Language**:   Java 8\n")
            .append("    **Library**:        JDA - v" + JDAInfo.VERSION + "\n")
            .append("    **Source**:        <https://github.com/DV8FromTheWorld/Yui>");
    sendMessage(e, builder.build());
}
 
Example #5
Source File: BotinfoCommand.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void execute(@Nonnull CommandContext ctx) {
    if ("support".equals(ctx.getInvoke())) {
        MessageUtils.sendMsg(ctx, "You can join my support server here: <https://dunctebot.link/server>");
        return;
    }

    final User u = ctx.getJDA().getSelfUser();
    final String duncte = " <@191231307290771456> (duncte123#1245)";

    final MessageEmbed eb = EmbedUtils.defaultEmbed()
        .setDescription("Here is some information about me \uD83D\uDE09")
        .setThumbnail(u.getEffectiveAvatarUrl())
        .addField("About me", "Hello there, my name is DuncteBot and I’m currently being developed by " +
            duncte + ".\n" +
            "If you want to add me to your server you can do that by [clicking here](https://bots.discord.pw/bots/210363111729790977).\n" +
            "\n**[Support server](https://dunctebot.link/server)** \u2022 **[Website](https://dunctebot.com/)** \u2022 " +
            "**[Invite me](https://dunctebot.link/invite)**" +
            " \u2022 **[Twitter](https://twitter.com/DuncteBot)**  \u2022 **[Cheap hosting](https://billing.oxide.host/aff.php?aff=6)**" +
            "\n\u200B", true)
        .addField("Lang & lib info", "**Coded in:** Java (version " + System.getProperty("java.version") +
            ") and Kotlin (version " + KotlinVersion.CURRENT + ")\n\n" +
            "**JDA version:** " + JDAInfo.VERSION + "" +
            "\n**LavaPlayer version:** " + this.lavaplayerVersion + "\n" +
            "**Weeb.java version:** " + WeebInfo.VERSION + "\n\u200B", false)
        .addField("Support", "If you want to help keep the bot up 24/7, please consider " +
            "[becoming a patron](https://www.patreon.com/DuncteBot).", false)
        .build();

    sendEmbed(ctx, eb);
}
 
Example #6
Source File: BannerPrinter.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
public BannerPrinter() {
    try {
        List<String> lines = defaultBanner.get();
        StringBuilder builder = new StringBuilder();
        for (String line : lines) {
            String toPrint = line.replace("%version%", MantaroInfo.VERSION)
                    .replace("%jdaversion%", JDAInfo.VERSION);
            builder.append(toPrint).append("\n");
        }
        toPrint = builder.toString();
    } catch (Exception e) {
        e.printStackTrace();
        toPrint = "Exception arose while getting the default banner";
    }
}
 
Example #7
Source File: BannerPrinter.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
public BannerPrinter(DataManager<List<String>> dm) {
    List<String> lines = dm.get();
    StringBuilder builder = new StringBuilder();
    for (String line : lines) {
        String toPrint = line.replace("%version%", MantaroInfo.VERSION)
                .replace("%jdaversion%", JDAInfo.VERSION);
        builder.append(toPrint).append("\n");
    }
    toPrint = builder.toString();
}
 
Example #8
Source File: WebSocketClient.java    From JDA with Apache License 2.0 5 votes vote down vote up
protected void sendIdentify()
{
    LOG.debug("Sending Identify-packet...");
    PresenceImpl presenceObj = (PresenceImpl) api.getPresence();
    DataObject connectionProperties = DataObject.empty()
        .put("$os", System.getProperty("os.name"))
        .put("$browser", "JDA")
        .put("$device", "JDA")
        .put("$referring_domain", "")
        .put("$referrer", "");
    DataObject payload = DataObject.empty()
        .put("presence", presenceObj.getFullPresence())
        .put("token", getToken())
        .put("properties", connectionProperties)
        .put("v", JDAInfo.DISCORD_GATEWAY_VERSION)
        .put("large_threshold", api.getLargeThreshold());
    //We only provide intents if they are not the default (all) for backwards compatibility
    // Discord has additional enforcements put in place even if you specify to subscribe to all intents
    if (api.useIntents())
        payload.put("intents", gatewayIntents);

    DataObject identify = DataObject.empty()
            .put("op", WebSocketCode.IDENTIFY)
            .put("d", payload);
    if (shardInfo != null)
    {
        payload
            .put("shard", DataArray.empty()
                .add(shardInfo.getShardId())
                .add(shardInfo.getShardTotal()));
    }
    send(identify.toString(), true);
    handleIdentifyRateLimit = true;
    identifyTime = System.currentTimeMillis();
    sentAuthInfo = true;
    api.setStatus(JDA.Status.AWAITING_LOGIN_CONFIRMATION);
}
 
Example #9
Source File: DiscordNotifier.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getVersion() {
	return JDAInfo.VERSION;
}
 
Example #10
Source File: DiscordBotServer.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getVersion() {
	return JDAInfo.VERSION;
}
 
Example #11
Source File: WebSocketClient.java    From JDA with Apache License 2.0 4 votes vote down vote up
protected synchronized void connect()
{
    if (api.getStatus() != JDA.Status.ATTEMPTING_TO_RECONNECT)
        api.setStatus(JDA.Status.CONNECTING_TO_WEBSOCKET);
    if (shutdown)
        throw new RejectedExecutionException("JDA is shutdown!");
    initiating = true;

    String url = api.getGatewayUrl() + "?encoding=json&v=" + JDAInfo.DISCORD_GATEWAY_VERSION;
    if (compression != Compression.NONE)
    {
        url += "&compress=" + compression.getKey();
        switch (compression)
        {
            case ZLIB:
                if (decompressor == null || decompressor.getType() != Compression.ZLIB)
                    decompressor = new ZlibDecompressor(api.getMaxBufferSize());
                break;
            default:
                throw new IllegalStateException("Unknown compression");
        }
    }

    try
    {
        WebSocketFactory socketFactory = api.getWebSocketFactory();
        //noinspection SynchronizationOnLocalVariableOrMethodParameter
        synchronized (socketFactory)
        {
            String host = IOUtil.getHost(url);
            // null if the host is undefined, unlikely but we should handle it
            if (host != null)
                socketFactory.setServerName(host);
            else // practically should never happen
                socketFactory.setServerNames(null);
            socket = socketFactory.createSocket(url);
        }
        socket.setDirectTextMessage(true);
        socket.addHeader("Accept-Encoding", "gzip")
              .addListener(this)
              .connect();
    }
    catch (IOException | WebSocketException e)
    {
        api.resetGatewayUrl();
        //Completely fail here. We couldn't make the connection.
        throw new IllegalStateException(e);
    }
}