Exemple #1
0
  public List<Event> getEvents(String clientId) {
    synchronized (registry) {
      if (!isRegistered(clientId)) {
        // TODO [MS] Throw properly typed exception here?
        throw new RuntimeException("Unable to get events. Client not registered: " + clientId);
      }

      EventCache cache = registry.get(clientId);
      try {
        return cache.getEvents();
      } finally {
        cache.clear();
      }
    }
  }
  @Override
  protected String handleInternally(JSONObject content) {
    ChannelType type = ChannelType.fromId(content.getInt("type"));

    if ((type == ChannelType.TEXT || type == ChannelType.VOICE)
        && GuildLock.get(api).isLocked(content.getString("guild_id"))) {
      return content.getString("guild_id");
    }

    switch (type) {
      case TEXT:
        {
          api.getEventManager()
              .handle(
                  new TextChannelCreateEvent(
                      api,
                      responseNumber,
                      new EntityBuilder(api)
                          .createTextChannel(content, content.getString("guild_id"))));
          break;
        }
      case VOICE:
        {
          api.getEventManager()
              .handle(
                  new VoiceChannelCreateEvent(
                      api,
                      responseNumber,
                      new EntityBuilder(api)
                          .createVoiceChannel(content, content.getString("guild_id"))));
          break;
        }
      case PRIVATE:
        {
          PrivateChannel pc = new EntityBuilder(api).createPrivateChannel(content);
          if (pc == null) {
            JDAImpl.LOG.warn(
                "Discord API sent us a Private CREATE_CHANNEL for a user we can't see, ignoring event.");
          } else {
            api.getEventManager()
                .handle(new PrivateChannelCreateEvent(api, responseNumber, pc.getUser()));
          }
          break;
        }
      case GROUP:
        {
          JDAImpl.LOG.debug(
              "Received GROUP channel create. Ignoring because JDA doesn't support groups. (Use JDA-Client)");
          break;
        }
      default:
        throw new IllegalArgumentException(
            "Discord provided an CREATE_CHANNEL event with an unknown channel type! JSON: "
                + content);
    }
    EventCache.get(api).playbackCache(EventCache.Type.CHANNEL, content.getString("id"));
    return null;
  }