• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JDAImpl类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: login

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
@Override
public void login(String token, ShardInfo shardInfo, SessionReconnectQueue reconnectQueue) throws LoginException, RateLimitedException {
    setStatus(Status.LOGGING_IN);
    if(token == null || token.isEmpty()) throw new LoginException("Provided token was null or empty!");

    setToken(token);
    verifyToken();
    this.shardInfo = shardInfo;
    JDAImpl.LOG.info("Login Successful!");

    client = new ClientWebSocketClient(this, reconnectQueue, gatewayClient);
    client.send(new JSONObject()
            .put("d", presence.getFullPresence())
            .put("op", WebSocketCode.PRESENCE).toString());

    if(shutdownHook != null) {
        Runtime.getRuntime().addShutdownHook(shutdownHook);
    }
}
 
开发者ID:natanbc,项目名称:discord-bot-gateway,代码行数:20,代码来源:ClientJDA.java


示例2: initJda

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
/**
 * Starts JDA.
 *
 * @return {@code true} if everything went well, {@code false} otherwise.
 */
private boolean initJda() {

    try {
        SimpleLog.Level level = JDAImpl.LOG.getLevel();
        SimpleLog.Level socketLevel = WebSocketClient.LOG.getLevel();
        JDAImpl.LOG.setLevel(SimpleLog.Level.OFF);
        WebSocketClient.LOG.setLevel(SimpleLog.Level.OFF);

        jda = new JDABuilder(AccountType.BOT).setToken(botToken).buildBlocking();
        jda.getPresence().setGame(Game.of("2.0.2"));
        logger.writeFrom("jda", "Successfully connected!");
        logger.writeFrom("jda WebSocket", "Connected to WebSocket!");

        JDAImpl.LOG.setLevel(level);
        WebSocketClient.LOG.setLevel(socketLevel);
    } catch (LoginException | InterruptedException | RateLimitedException e) {
        logger.writeFrom("jda", "Couldn't connect!");
        e.printStackTrace();
        return false;
    }
    return true;
}
 
开发者ID:iSach,项目名称:Samaritan,代码行数:28,代码来源:Samaritan.java


示例3: handleInternally

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
@Override
protected Long handleInternally(JSONObject content)
{
    final long guildId = content.getLong("guild_id");
    List<JSONArray> memberChunks = memberChunksCache.get(guildId);
    int expectMemberCount = expectedGuildMembers.get(guildId);

    JSONArray members = content.getJSONArray("members");
    JDAImpl.LOG.debug("GUILD_MEMBER_CHUNK for: {}\tMembers: {}", guildId, members.length());
    memberChunks.add(members);

    int currentTotal = 0;
    for (JSONArray arr : memberChunks)
        currentTotal += arr.length();

    if (currentTotal >= expectMemberCount)
    {
        JDAImpl.LOG.debug("Finished chunking for: {}", guildId);
        api.getEntityBuilder().createGuildSecondPass(guildId, memberChunks);
        memberChunksCache.remove(guildId);
        expectedGuildMembers.remove(guildId);
    }
    return null;
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:25,代码来源:GuildMembersChunkHandler.java


示例4: handleInternally

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
@Override
protected Long handleInternally(JSONObject content)
{
    final long guildId = content.getLong("id");
    if (!api.getGuildMap().containsKey(guildId))
    {
        JDAImpl.LOG.error("Received a GUILD_SYNC for a Guild that does not yet exist in JDA's guild cache. This is a BAD ERROR FOR CLIENTS!");
        return null;
    }

    GuildImpl guild = (GuildImpl) api.getGuildMap().get(guildId);
    JSONArray members = content.getJSONArray("members");
    JSONArray presences = content.getJSONArray("presences");
    api.getEntityBuilder().handleGuildSync(guild, members, presences);

    return null;
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:18,代码来源:GuildSyncHandler.java


示例5: AudioWebSocket

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
public AudioWebSocket(ConnectionListener listener, String endpoint, JDAImpl api, Guild guild, String sessionId, String token, boolean shouldReconnect)
{
    this.listener = listener;
    this.endpoint = endpoint;
    this.api = api;
    this.guild = guild;
    this.sessionId = sessionId;
    this.token = token;
    this.shouldReconnect = shouldReconnect;

    keepAlivePool = api.getAudioKeepAlivePool();

    //Append the Secure Websocket scheme so that our websocket library knows how to connect
    wssEndpoint = String.format("wss://%s/?v=%d", endpoint, 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!");
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:21,代码来源:AudioWebSocket.java


示例6: setupSendSystem

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
private synchronized void setupSendSystem()
{
    if (udpSocket != null && !udpSocket.isClosed() && sendHandler != null && sendSystem == null)
    {
        IntBuffer error = IntBuffer.allocate(4);
        opusEncoder = Opus.INSTANCE.opus_encoder_create(OPUS_SAMPLE_RATE, OPUS_CHANNEL_COUNT, Opus.OPUS_APPLICATION_AUDIO, error);

        IAudioSendFactory factory = ((JDAImpl) channel.getJDA()).getAudioSendFactory();
        sendSystem = factory.createSendSystem(new PacketProvider());
        sendSystem.setContextMap(contextMap);
        sendSystem.start();
    }
    else if (sendHandler == null && sendSystem != null)
    {
        sendSystem.shutdown();
        sendSystem = null;

        if (opusEncoder != null)
        {
            Opus.INSTANCE.opus_encoder_destroy(opusEncoder);
            opusEncoder = null;
        }
    }
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:25,代码来源:AudioConnection.java


示例7: RichPresence

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
public RichPresence(JDAImpl jda) { //JDA object can be casted to a JDAImpl
    JSONObject obj = new JSONObject();
    JSONObject gameObj = new JSONObject();

    /* LAYOUT:
    * name
    * details
    * time elapsed (timestamps)
    * status
    */
    gameObj.put("name", "Name Here");
    gameObj.put("type", 0); //1 if streaming
    gameObj.put("details", "Details Here");
    gameObj.put("state", "Spotify - PLAYING");
    gameObj.put("timestamps", new JSONObject().put("start", 1508373056)); //somehow used for the time elapsed thing I assume, you can probably also set the end to make it show "xx:xx left"

    JSONObject assetsObj = new JSONObject();
    assetsObj.put("large_image", "376410582829498368"); //ID of large icon
    assetsObj.put("large_text", "Large Text");

    assetsObj.put("small_image", "376410693861244928"); //ID of small icon

    gameObj.put("assets", assetsObj);
    gameObj.put("application_id", "354736186516045835"); //Application ID

    obj.put("game", gameObj);
    obj.put("afk", jda.getPresence().isIdle());
    obj.put("status", jda.getPresence().getStatus().getKey());
    obj.put("since", System.currentTimeMillis());

    System.out.println(obj);

    jda.getClient().send(new JSONObject()
            .put("d", obj)
            .put("op", WebSocketCode.PRESENCE).toString());
}
 
开发者ID:WheezyGold7931,项目名称:happybot,代码行数:37,代码来源:RichPresence.java


示例8: ClientWebSocketClient

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
public ClientWebSocketClient(JDAImpl api, SessionReconnectQueue reconnectQueue, GatewayClient gatewayClient) {
    super(api, reconnectQueue);
    this.gatewayClient = gatewayClient;
    try {
        gatewayClient.register(this);
    } catch(IOException e) {
        throw new UncheckedIOException(e);
    }
    ratelimitThread.interrupt();
    setupSendThread();
}
 
开发者ID:natanbc,项目名称:discord-bot-gateway,代码行数:12,代码来源:ClientWebSocketClient.java


示例9: login

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
@Override
public void login(String token, ShardInfo shardInfo, SessionReconnectQueue reconnectQueue) throws LoginException, RateLimitedException {
    setStatus(Status.LOGGING_IN);
    if(token == null || token.isEmpty()) throw new LoginException("Provided token was null or empty!");

    setToken(token);
    verifyToken();
    this.shardInfo = shardInfo;
    JDAImpl.LOG.info("Login Successful!");

    client = new ServerWebSocketClient(this, reconnectQueue, gatewayServer);

    JSONObject cachedPresence = gatewayServer.cachedPresence;
    if(cachedPresence != null) {
        JSONObject game = cachedPresence.optJSONObject("game");
        if(game != null) {
            getPresence().setPresence(
                    OnlineStatus.fromKey(cachedPresence.getString("status")),
                    Game.of(game.getString("name"), game.optString("url")),
                    cachedPresence.getBoolean("afk")
            );
        } else {
            getPresence().setPresence(
                    OnlineStatus.fromKey(cachedPresence.getString("status")),
                    null,
                    cachedPresence.getBoolean("afk")
            );
        }
        gatewayServer.cachedPresence = null;
    }

    if(shutdownHook != null) {
        Runtime.getRuntime().addShutdownHook(shutdownHook);
    }
}
 
开发者ID:natanbc,项目名称:discord-bot-gateway,代码行数:36,代码来源:ServerJDA.java


示例10: setGame

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
public static void setGame() {
	if (McLink.instance.bot != null) {
		JSONObject obj = new JSONObject();
		JSONObject gameObj = new JSONObject();

		gameObj.put("name", "SuperiorNetworks");
		gameObj.put("type", 0);
		gameObj.put("details", "Playing on the lobby");
		gameObj.put("state", "SuperiorNetworks - PLAYING");
		gameObj.put("timestamps", new JSONObject().put("start", 1508373056));

		JSONObject assetsObj = new JSONObject();
		assetsObj.put("large_image", "lobby");
		assetsObj.put("large_text", "In the lobby");
		assetsObj.put("small_image", "lobby");
		gameObj.put("assets", assetsObj);
		gameObj.put("application_id", McLink.instance.bot.bot.getToken());

		obj.put("game", gameObj);
		obj.put("afk", McLink.instance.bot.bot.getPresence().isIdle());
		obj.put("status", McLink.instance.bot.bot.getPresence().getStatus().getKey());
		obj.put("since", System.currentTimeMillis());

		((JDAImpl) McLink.instance.bot.bot).getClient()
				.send(new JSONObject().put("d", obj).put("op", WebSocketCode.PRESENCE).toString());
	}
}
 
开发者ID:GigaGamma,项目名称:McLink,代码行数:28,代码来源:RichPresence.java


示例11: edit

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
public static void edit(DiscordUser user, DiscordConversation conversation, String message) throws WebhookException
{
    TextChannel channel = (TextChannel) conversation.getChannel();
    Guild guild = channel.getGuild();
    JDAImpl jda = (JDAImpl) guild.getJDA();

    if (!initialized)
    {
        Webhook.initBotHooks(jda);
        initialized = true;
    }

    Webhook hook = Webhook.getBotHook(jda, channel);

    if (hook == null)
    {
        throw new WebhookException("creating", channel.getName());
    }

    if (!hook.execute(jda, new JSONObject(new HashMap<String, Object>()
    {
        {
            put("username", user.getUsername());
            put("avatar_url", user.getAvatar());
            put("content", message);
        }
    })))
    {
        throw new WebhookException("sending", channel.getName());
    }
}
 
开发者ID:SalonDesDevs,项目名称:Shenron-Legacy,代码行数:32,代码来源:MessageEditor.java


示例12: setExpectedGuildMembers

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
public void setExpectedGuildMembers(long guildId, int count)
{
    if (expectedGuildMembers.containsKey(guildId))
        JDAImpl.LOG.warn("Set the count of expected users from GuildMembersChunk even though a value already exists! GuildId: {}", guildId);

    expectedGuildMembers.put(guildId, count);

    if (memberChunksCache.containsKey(guildId))
        JDAImpl.LOG.warn("Set the memberChunks for MemberChunking for a guild that was already setup for chunking! GuildId: {}", guildId);

    memberChunksCache.put(guildId, new LinkedList<>());
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:13,代码来源:GuildMembersChunkHandler.java


示例13: appendSession

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
@Override
public void appendSession(SessionConnectNode node)
{
    if (queue != null && node.isReconnect())
        queue.appendSession(((JDAImpl) node.getJDA()).getClient());
    else
        super.appendSession(node);
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:9,代码来源:ProvidingSessionController.java


示例14: removeSession

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
@Override
public void removeSession(SessionConnectNode node)
{
    if (queue != null && node.isReconnect())
        queue.removeSession(((JDAImpl) node.getJDA()).getClient());
    else
        super.removeSession(node);
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:9,代码来源:ProvidingSessionController.java


示例15: Attachment

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
public Attachment(long id, String url, String proxyUrl, String fileName, int size, int height, int width, JDAImpl jda)
{
    this.id = id;
    this.url = url;
    this.proxyUrl = proxyUrl;
    this.fileName = fileName;
    this.size = size;
    this.height = height;
    this.width = width;
    this.jda = jda;
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:12,代码来源:Message.java


示例16: download

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
/**
 * Downloads this attachment to given File
 *
 * @param  file
 *         The file, where the attachment will get downloaded to
 *
 * @return boolean true, if successful, otherwise false
 */
public boolean download(File file)
{
    try
    {
        withInputStream((in) -> Files.copy(in, Paths.get(file.getAbsolutePath())));
        return true;
    }
    catch (Exception e)
    {
        JDAImpl.LOG.error("Error while downloading an attachment", e);
    }
    return false;
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:22,代码来源:Message.java


示例17: handle

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
@Override
public void handle(Event event)
{
    for (EventListener listener : listeners)
    {
        try
        {
            listener.onEvent(event);
        }
        catch (Throwable throwable)
        {
            JDAImpl.LOG.error("One of the EventListeners had an uncaught exception", throwable);
        }
    }
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:16,代码来源:InterfacedEventManager.java


示例18: handle

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void handle(Event event)
{
    Class<? extends Event> eventClass = event.getClass();
    do
    {
        Map<Object, List<Method>> listeners = methods.get(eventClass);
        if (listeners != null)
        {
            listeners.entrySet().forEach(e -> e.getValue().forEach(method ->
            {
                try
                {
                    method.setAccessible(true);
                    method.invoke(e.getKey(), event);
                }
                catch (IllegalAccessException | InvocationTargetException e1)
                {
                    JDAImpl.LOG.error("Couldn't access annotated eventlistener method", e1);
                }
                catch (Throwable throwable)
                {
                    JDAImpl.LOG.error("One of the EventListeners had an uncaught exception", throwable);
                }
            }));
        }
        eventClass = eventClass == Event.class ? null : (Class<? extends Event>) eventClass.getSuperclass();
    }
    while (eventClass != null);
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:32,代码来源:AnnotatedEventManager.java


示例19: buildAsync

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
/**
 * Builds a new {@link net.dv8tion.jda.core.JDA} instance and uses the provided token to start the login process.
 * <br>The login process runs in a different thread, so while this will return immediately, {@link net.dv8tion.jda.core.JDA} has not
 * finished loading, thus many {@link net.dv8tion.jda.core.JDA} methods have the chance to return incorrect information.
 * <br>The main use of this method is to start the JDA connect process and do other things in parallel while startup is
 * being performed like database connection or local resource loading.
 *
 * <p>If you wish to be sure that the {@link net.dv8tion.jda.core.JDA} information is correct, please use
 * {@link net.dv8tion.jda.core.JDABuilder#buildBlocking() buildBlocking()} or register an
 * {@link net.dv8tion.jda.core.hooks.EventListener EventListener} to listen for the
 * {@link net.dv8tion.jda.core.events.ReadyEvent ReadyEvent} .
 *
 * @throws LoginException
 *         If the provided token is invalid.
 * @throws IllegalArgumentException
 *         If the provided token is empty or null.
 *
 * @return A {@link net.dv8tion.jda.core.JDA} instance that has started the login process. It is unknown as
 *         to whether or not loading has finished when this returns.
 */
public JDA buildAsync() throws LoginException
{
    OkHttpClient.Builder httpClientBuilder = this.httpClientBuilder == null ? new OkHttpClient.Builder() : this.httpClientBuilder;
    WebSocketFactory wsFactory = this.wsFactory == null ? new WebSocketFactory() : this.wsFactory;

    if (controller == null)
    {
        if (reconnectQueue != null || shardRateLimiter != null)
            controller = new ProvidingSessionController(reconnectQueue, shardRateLimiter);
        else if (shardInfo != null)
            controller = new SessionControllerAdapter();
    }
    JDAImpl jda = new JDAImpl(accountType, token, controller, httpClientBuilder, wsFactory, autoReconnect, enableVoice, enableShutdownHook,
            enableBulkDeleteSplitting, requestTimeoutRetry, enableContext, corePoolSize, maxReconnectDelay, contextMap);

    if (eventManager != null)
        jda.setEventManager(eventManager);

    if (audioSendFactory != null)
        jda.setAudioSendFactory(audioSendFactory);

    listeners.forEach(jda::addEventListener);
    jda.setStatus(JDA.Status.INITIALIZED);  //This is already set by JDA internally, but this is to make sure the listeners catch it.

    String gateway = jda.getGateway();

    // Set the presence information before connecting to have the correct information ready when sending IDENTIFY
    ((PresenceImpl) jda.getPresence())
            .setCacheGame(game)
            .setCacheIdle(idle)
            .setCacheStatus(status);
    jda.login(gateway, shardInfo);
    return jda;
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:55,代码来源:JDABuilder.java


示例20: AudioConnection

import net.dv8tion.jda.core.entities.impl.JDAImpl; //导入依赖的package包/类
public AudioConnection(AudioWebSocket webSocket, VoiceChannel channel)
{
    this.channel = channel;
    this.webSocket = webSocket;
    this.webSocket.audioConnection = this;

    final JDAImpl api = (JDAImpl) channel.getJDA();
    this.threadIdentifier = api.getIdentifierString() + " AudioConnection Guild: " + channel.getGuild().getId();
    this.contextMap = api.getContextMap();
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:11,代码来源:AudioConnection.java



注:本文中的net.dv8tion.jda.core.entities.impl.JDAImpl类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Task类代码示例发布时间:2022-05-22
下一篇:
Java IMetric类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap