-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Add] BotCommandProcess 新增'色图'功能以随机从排行榜中获取一张图片;
[Add] BufferMessageEvent 增加用于获取Sender发送内容的Event实现; [Change] BotEventHandler Handler现在允许命令处理方法不返回消息(返回'null');
- Loading branch information
Showing
3 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/net/lamgc/cgj/bot/event/BufferMessageEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |