本文整理汇总了Java中net.dv8tion.jda.core.entities.MessageHistory类的典型用法代码示例。如果您正苦于以下问题:Java MessageHistory类的具体用法?Java MessageHistory怎么用?Java MessageHistory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageHistory类属于net.dv8tion.jda.core.entities包,在下文中一共展示了MessageHistory类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: action
import net.dv8tion.jda.core.entities.MessageHistory; //导入依赖的package包/类
@Override
public void action(String[] args, GuildMessageReceivedEvent event) throws ParseException, IOException {
event.getMessage().delete().queue();
if(core.permissionHandler.check(2, event)) return;
if (args.length < 1) util.embedSender.error().setDescription(help()).setTitle("ERROR!").build();
int numb = getInt(args[0]);
if (numb > 1 && numb <= 100) {
try{
MessageHistory history = new MessageHistory(event.getChannel());
List<Message> msgs;
msgs = history.retrievePast(numb).complete();
event.getChannel().deleteMessages(msgs).queue();
Message msg = event.getChannel().sendMessage(new EmbedBuilder()
.setColor(Color.GREEN)
.setDescription(":bomb: Deleted " + args[0] + " Messages!")
.build()
).complete();
new Timer().schedule(new TimerTask() {
@Override
public void run() {
msg.delete().queue();
}
}, 3000);
}catch (Exception e){
e.printStackTrace();
}
}else {
util.embedSender.error().setDescription(help() + "Max. 100 Message and Min. 1 Message").setTitle("ERROR!").build();
}
}
示例2: loadMessages
import net.dv8tion.jda.core.entities.MessageHistory; //导入依赖的package包/类
private void loadMessages(MessageHistory history, int toDelete, List<Message> messages, List<Long> userIds, int loops, Consumer<List<Message>> consumer) {
long maxMessageAge = (System.currentTimeMillis() - TimeUnit.DAYS.toMillis(14) - MiscUtil.DISCORD_EPOCH) << MiscUtil.TIMESTAMP_OFFSET;
history.retrievePast(100).queue(historyMessages -> {
if (historyMessages.isEmpty()) {
consumer.accept(messages);
return;
}
for (Message historyMessage : historyMessages) {
if (historyMessage.isPinned() || historyMessage.getIdLong() < maxMessageAge) {
continue;
}
if (userIds != null && !userIds.contains(historyMessage.getAuthor().getIdLong())) {
continue;
}
if (messages.size() >= toDelete || loops > MAX_HISTORY_LOOPS) {
consumer.accept(messages);
return;
}
messages.add(historyMessage);
}
loadMessages(history, toDelete, messages, userIds, loops + 1, consumer);
});
}