net.dv8tion.jda.api.utils.TimeUtil Java Examples
The following examples show how to use
net.dv8tion.jda.api.utils.TimeUtil.
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: TextChannelImpl.java From JDA with Apache License 2.0 | 5 votes |
@Nonnull @Override public RestAction<Void> deleteMessagesByIds(@Nonnull Collection<String> messageIds) { checkPermission(Permission.MESSAGE_MANAGE, "Must have MESSAGE_MANAGE in order to bulk delete messages in this channel regardless of author."); if (messageIds.size() < 2 || messageIds.size() > 100) throw new IllegalArgumentException("Must provide at least 2 or at most 100 messages to be deleted."); long twoWeeksAgo = TimeUtil.getDiscordTimestamp((System.currentTimeMillis() - (14 * 24 * 60 * 60 * 1000))); for (String id : messageIds) Checks.check(MiscUtil.parseSnowflake(id) > twoWeeksAgo, "Message Id provided was older than 2 weeks. Id: " + id); return deleteMessages0(messageIds); }
Example #2
Source File: InvestigateCmd.java From MantaroBot with GNU General Public License v3.0 | 4 votes |
OffsetDateTime timestamp() { return TimeUtil.getTimeCreated(MiscUtil.parseSnowflake(id)); }
Example #3
Source File: TextChannelImpl.java From JDA with Apache License 2.0 | 4 votes |
@Nonnull @Override @SuppressWarnings("ConstantConditions") public List<CompletableFuture<Void>> purgeMessagesById(@Nonnull long... messageIds) { if (messageIds == null || messageIds.length == 0) return Collections.emptyList(); if (getJDA().getAccountType() != AccountType.BOT || !getGuild().getSelfMember().hasPermission(this, Permission.MESSAGE_MANAGE)) return TextChannel.super.purgeMessagesById(messageIds); // remove duplicates and sort messages List<CompletableFuture<Void>> list = new LinkedList<>(); TreeSet<Long> bulk = new TreeSet<>(Comparator.reverseOrder()); TreeSet<Long> norm = new TreeSet<>(Comparator.reverseOrder()); long twoWeeksAgo = TimeUtil.getDiscordTimestamp(System.currentTimeMillis() - (14 * 24 * 60 * 60 * 1000) + 10000); for (long messageId : messageIds) { if (messageId > twoWeeksAgo) bulk.add(messageId); else norm.add(messageId); } // delete chunks of 100 messages each if (!bulk.isEmpty()) { List<String> toDelete = new ArrayList<>(100); while (!bulk.isEmpty()) { toDelete.clear(); for (int i = 0; i < 100 && !bulk.isEmpty(); i++) toDelete.add(Long.toUnsignedString(bulk.pollLast())); if (toDelete.size() == 1) list.add(deleteMessageById(toDelete.get(0)).submit()); else if (!toDelete.isEmpty()) list.add(deleteMessages0(toDelete).submit()); } } // delete messages too old for bulk delete if (!norm.isEmpty()) { for (long message : norm) list.add(deleteMessageById(message).submit()); } return list; }
Example #4
Source File: ISnowflake.java From JDA with Apache License 2.0 | 2 votes |
/** * The time this entity was created. Calculated through the Snowflake in {@link #getIdLong}. * * @return OffsetDateTime - Time this entity was created at. * * @see TimeUtil#getTimeCreated(long) */ @Nonnull default OffsetDateTime getTimeCreated() { return TimeUtil.getTimeCreated(getIdLong()); }