From 461cd246d8bf8587e9bacedf8f4ed371ff1e9331 Mon Sep 17 00:00:00 2001 From: LamGC Date: Wed, 20 May 2020 09:55:50 +0800 Subject: [PATCH] =?UTF-8?q?[Add]=20BotCommandProcess=20=E6=96=B0=E5=A2=9E'?= =?UTF-8?q?=E8=89=B2=E5=9B=BE'=E5=8A=9F=E8=83=BD=E4=BB=A5=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA=E4=BB=8E=E6=8E=92=E8=A1=8C=E6=A6=9C=E4=B8=AD=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=80=E5=BC=A0=E5=9B=BE=E7=89=87;=20[Add]=20Buffer?= =?UTF-8?q?MessageEvent=20=E5=A2=9E=E5=8A=A0=E7=94=A8=E4=BA=8E=E8=8E=B7?= =?UTF-8?q?=E5=8F=96Sender=E5=8F=91=E9=80=81=E5=86=85=E5=AE=B9=E7=9A=84Eve?= =?UTF-8?q?nt=E5=AE=9E=E7=8E=B0;=20[Change]=20BotEventHandler=20Handler?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E5=85=81=E8=AE=B8=E5=91=BD=E4=BB=A4=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=96=B9=E6=B3=95=E4=B8=8D=E8=BF=94=E5=9B=9E=E6=B6=88?= =?UTF-8?q?=E6=81=AF(=E8=BF=94=E5=9B=9E'null');?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/lamgc/cgj/bot/BotCommandProcess.java | 16 +++++ .../lamgc/cgj/bot/event/BotEventHandler.java | 2 +- .../cgj/bot/event/BufferMessageEvent.java | 59 +++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/lamgc/cgj/bot/event/BufferMessageEvent.java diff --git a/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java b/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java index 77d593d..559e3a8 100644 --- a/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java +++ b/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java @@ -7,10 +7,14 @@ import io.netty.handler.codec.http.HttpHeaderNames; import net.lamgc.cgj.Main; import net.lamgc.cgj.bot.cache.*; import net.lamgc.cgj.bot.event.BotEventHandler; +import net.lamgc.cgj.bot.event.BufferMessageEvent; import net.lamgc.cgj.bot.sort.PreLoadDataComparator; import net.lamgc.cgj.pixiv.PixivDownload; import net.lamgc.cgj.pixiv.PixivSearchBuilder; import net.lamgc.cgj.pixiv.PixivURL; +import net.lamgc.cgj.pixiv.PixivDownload.PageQuality; +import net.lamgc.cgj.pixiv.PixivURL.RankingContentType; +import net.lamgc.cgj.pixiv.PixivURL.RankingMode; import net.lamgc.cgj.util.URLs; import net.lamgc.utils.base.runner.Argument; import net.lamgc.utils.base.runner.Command; @@ -295,6 +299,18 @@ public class BotCommandProcess { return "功能未完成"; } + @Command(commandName = "st") + public static String r18Image() { + BufferMessageEvent event = new BufferMessageEvent(); + RandomRankingArtworksSender artworksSender = + new RandomRankingArtworksSender(event, 1, 200, + RankingMode.MODE_MALE, + RankingContentType.TYPE_ALL, + PageQuality.ORIGINAL); + artworksSender.send(); + return event.getBufferMessage(); + } + /** * 搜索命令 * @param fromGroup 来源群(系统提供) diff --git a/src/main/java/net/lamgc/cgj/bot/event/BotEventHandler.java b/src/main/java/net/lamgc/cgj/bot/event/BotEventHandler.java index 24fa75f..26b7583 100644 --- a/src/main/java/net/lamgc/cgj/bot/event/BotEventHandler.java +++ b/src/main/java/net/lamgc/cgj/bot/event/BotEventHandler.java @@ -224,7 +224,7 @@ public class BotEventHandler implements EventHandler { } } long processTime = System.currentTimeMillis() - time; - if(Objects.requireNonNull(result) instanceof String && !isMute(event.getFromGroup())) { + if(!Objects.isNull(result) && result instanceof String && !isMute(event.getFromGroup())) { try { event.sendMessage((String) result); } catch (Exception e) { diff --git a/src/main/java/net/lamgc/cgj/bot/event/BufferMessageEvent.java b/src/main/java/net/lamgc/cgj/bot/event/BufferMessageEvent.java new file mode 100644 index 0000000..ecf6097 --- /dev/null +++ b/src/main/java/net/lamgc/cgj/bot/event/BufferMessageEvent.java @@ -0,0 +1,59 @@ +package net.lamgc.cgj.bot.event; + +import java.util.Objects; + +public class BufferMessageEvent extends MessageEvent { + + StringBuffer buffer = new StringBuffer(); + + public final MessageEvent parent; + + /** + * 以空消息空Id生成BufferMessageEvent + */ + public BufferMessageEvent() { + super(0, 0, ""); + parent = null; + } + + /** + * 提供消息内容构造BufferMessageEvent + * @param message 传入的消息内容 + */ + public BufferMessageEvent(String message) { + super(0, 0, message); + parent = null; + } + + /** + * 使用事件构造BufferMessageEvent + * @param parentEvent 父级消息事件对象 + */ + public BufferMessageEvent(MessageEvent parentEvent) { + super(parentEvent.getFromGroup(), parentEvent.getFromQQ(), parentEvent.getMessage()); + parent = parentEvent; + } + + @Override + public int sendMessage(String message) { + buffer.append(message); + return 0; + } + + /** + * 当提供了父级消息事件时, 本方法调用父级消息事件对象的{@code getImageUrl(String)}, 如果没有, 返回{@code null} + */ + @Override + public String getImageUrl(String image) { + return Objects.isNull(this.parent) ? null : this.parent.getImageUrl(image); + } + + /** + * 获取缓冲区消息内容 + * @return 消息内容 + */ + public String getBufferMessage() { + return buffer.toString(); + } + +} \ No newline at end of file