Ejemplo n.º 1
0
  @Override
  protected String handleInternally(JSONObject content) {
    String messageId = content.getString("id");
    String channelId = content.getString("channel_id");
    TextChannel channel = api.getChannelMap().get(channelId);

    if (channel != null) {
      if (GuildLock.get(api).isLocked(channel.getGuild().getId())) {
        return channel.getGuild().getId();
      }
      api.getEventManager()
          .handle(
              new GuildMessageDeleteEvent(
                  api, responseNumber,
                  messageId, channel));
    } else {
      PrivateChannel privChannel = api.getPmChannelMap().get(channelId);
      if (privChannel == null)
        throw new IllegalArgumentException(
            "Message deleted in unknown channel! (unknown channel id). JSON: " + content);
      api.getEventManager()
          .handle(
              new PrivateMessageDeleteEvent(
                  api, responseNumber,
                  messageId, privChannel));
    }
    // Combo event
    api.getEventManager()
        .handle(new MessageDeleteEvent(api, responseNumber, messageId, channelId, channel == null));
    return null;
  }
Ejemplo n.º 2
0
  @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;
  }