@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;
  }
Esempio n. 2
0
  @Override
  public int compareTo(TextChannel chan) {
    if (this == chan) return 0;

    if (this.getGuild() != chan.getGuild())
      throw new IllegalArgumentException(
          "Cannot compare TextChannels that aren't from the same guild!");

    if (this.getPositionRaw() != chan.getPositionRaw())
      return chan.getPositionRaw() - this.getPositionRaw();

    OffsetDateTime thisTime = MiscUtil.getCreationTime(this);
    OffsetDateTime chanTime = MiscUtil.getCreationTime(chan);

    // We compare the provided channel's time to this's time instead of the reverse as one would
    // expect due to how
    // discord deals with hierarchy. The more recent a channel was created, the lower its hierarchy
    // ranking when
    // it shares the same position as another channel.
    return chanTime.compareTo(thisTime);
  }
Esempio n. 3
0
 @Override
 public boolean equals(Object o) {
   if (!(o instanceof TextChannel)) return false;
   TextChannel oTChannel = (TextChannel) o;
   return this == oTChannel || this.getId().equals(oTChannel.getId());
 }