Skip to content

Commit

Permalink
Beta: 无新增与修复
Browse files Browse the repository at this point in the history
重构了部分代码 现在 MessageEvent 可以接收qq群与频道的消息 和发送操作
  • Loading branch information
Kloping committed Nov 18, 2023
1 parent 2c912cf commit 329a5e1
Show file tree
Hide file tree
Showing 38 changed files with 480 additions and 264 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.kloping</groupId>
<artifactId>bot-qqpd-java</artifactId>
<version>1.5.0-L6</version>
<version>1.5.0-Beta</version>

<packaging>jar</packaging>
<name>bot-qqpd-java</name>
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/io/github/kloping/qqbot/api/DirectSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.github.kloping.qqbot.entities.qqpd.message.RawMessage;
import io.github.kloping.qqbot.entities.qqpd.message.RawPreMessage;
import io.github.kloping.qqbot.http.data.ActionResult;
import io.github.kloping.qqbot.http.data.Result;
import io.github.kloping.qqbot.impl.MessagePacket;

/**
Expand All @@ -12,22 +13,22 @@
*/
public interface DirectSender extends Sender {
@Override
default ActionResult send(String text) {
default Result<ActionResult> send(String text) {
return sendDirect(text);
}

@Override
default ActionResult send(String text, RawMessage message) {
default Result<ActionResult> send(String text, RawMessage message) {
return sendDirect(text, message);
}

@Override
default ActionResult send(MessagePacket packet) {
default Result<ActionResult> send(MessagePacket packet) {
return sendDirect(packet);
}

@Override
default ActionResult send(RawPreMessage msg) {
default Result<ActionResult> send(RawPreMessage msg) {
return sendDirect(msg);
}

Expand All @@ -37,7 +38,7 @@ default ActionResult send(RawPreMessage msg) {
* @param text
* @return
*/
ActionResult sendDirect(String text);
Result<ActionResult> sendDirect(String text);

/**
* 以JSON方式发送文本消息并引用指定消息
Expand All @@ -46,21 +47,21 @@ default ActionResult send(RawPreMessage msg) {
* @param message
* @return
*/
ActionResult sendDirect(String text, RawMessage message);
Result<ActionResult> sendDirect(String text, RawMessage message);

/**
* 以自定义方式发送消息
*
* @param packet
* @return
*/
ActionResult sendDirect(MessagePacket packet);
Result<ActionResult> sendDirect(MessagePacket packet);

/**
* 自定义消息
*
* @param msg
* @return
*/
ActionResult sendDirect(RawPreMessage msg);
Result<ActionResult> sendDirect(RawPreMessage msg);
}
5 changes: 2 additions & 3 deletions src/main/java/io/github/kloping/qqbot/api/SendAble.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.kloping.qqbot.api;

import io.github.kloping.qqbot.api.SenderAndCidMidGetter;
import io.github.kloping.qqbot.http.data.ActionResult;
import io.github.kloping.qqbot.http.data.Result;

/**
* @author github.kloping
Expand All @@ -13,5 +12,5 @@ public interface SendAble {
* @param er
* @return
*/
ActionResult send(SenderAndCidMidGetter er);
Result send(SenderAndCidMidGetter er);
}
26 changes: 15 additions & 11 deletions src/main/java/io/github/kloping/qqbot/api/Sender.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.github.kloping.qqbot.entities.qqpd.message.RawMessage;
import io.github.kloping.qqbot.entities.qqpd.message.RawPreMessage;
import io.github.kloping.qqbot.http.data.ActionResult;
import io.github.kloping.qqbot.http.data.Result;
import io.github.kloping.qqbot.impl.MessagePacket;

/**
Expand All @@ -18,7 +18,7 @@ public interface Sender {
* @param text
* @return
*/
ActionResult send(String text);
Result send(String text);

/**
* 以JSON方式发送文本消息并引用指定消息
Expand All @@ -27,29 +27,33 @@ public interface Sender {
* @param message
* @return
*/
ActionResult send(String text, RawMessage message);
Result send(String text, RawMessage message);

/**
* 以自定义方式发送消息
* 以各种方式 达到想要发送的效果
*
* @param packet
* @param msg
* @return
*/
ActionResult send(MessagePacket packet);
Result send(SendAble msg);

/**
* 自定义消息
* 以自定义方式发送消息
*
* @param msg
* @param packet
* @return
*/
ActionResult send(RawPreMessage msg);
default Result send(MessagePacket packet) {
return null;
}

/**
* 以各种方式 达到想要发送的效果
* 自定义消息
*
* @param msg
* @return
*/
ActionResult send(SendAble msg);
default Result send(RawPreMessage msg) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.kloping.qqbot.api;

import io.github.kloping.qqbot.api.event.BotContent;
import io.github.kloping.qqbot.entities.ex.enums.EnvType;

/**
* @author github.kloping
Expand All @@ -21,4 +22,12 @@ public interface SenderAndCidMidGetter extends Sender, BotContent {
default String getMid() {
return null;
}

/**
* 获得发送环境
* guild/qq
*
* @return
*/
EnvType getEnvType();
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.github.kloping.qqbot.api.message;

import io.github.kloping.qqbot.api.Reactive;
import io.github.kloping.qqbot.entities.qqpd.Member;

/**
* 消息接收事件
*
* @author github.kloping
*/
public interface MessageChannelReceiveEvent extends MessageEvent, Reactive {
public interface MessageChannelReceiveEvent extends MessageEvent<Member>, Reactive {
/**
* 消息内容
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.github.kloping.qqbot.api.message;

import io.github.kloping.qqbot.entities.qqpd.Member;

/**
* @author github.kloping
*/
public interface MessageDeleteEvent extends MessageEvent {
public interface MessageDeleteEvent extends MessageEvent<Member> {
/**
* 事件 操作者ID
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.kloping.qqbot.entities.qqpd.message.RawMessage;
import io.github.kloping.qqbot.entities.qqpd.message.RawPreMessage;
import io.github.kloping.qqbot.http.data.ActionResult;
import io.github.kloping.qqbot.http.data.Result;
import io.github.kloping.qqbot.impl.MessagePacket;

/**
Expand Down Expand Up @@ -42,7 +43,7 @@ public interface MessageDirectReceiveEvent extends MessageReceiveEvent, DirectSe
* @return
*/
@Override
default ActionResult send(String text) {
default Result<ActionResult> send(String text) {
return sendDirect(text);
}

Expand All @@ -54,7 +55,7 @@ default ActionResult send(String text) {
* @return
*/
@Override
default ActionResult send(String text, RawMessage message) {
default Result<ActionResult> send(String text, RawMessage message) {
return sendDirect(text, message);
}

Expand All @@ -65,7 +66,7 @@ default ActionResult send(String text, RawMessage message) {
* @return
*/
@Override
default ActionResult send(MessagePacket packet) {
default Result<ActionResult> send(MessagePacket packet) {
return sendDirect(packet);
}

Expand All @@ -76,7 +77,7 @@ default ActionResult send(MessagePacket packet) {
* @return
*/
@Override
default ActionResult send(RawPreMessage msg) {
default Result<ActionResult> send(RawPreMessage msg) {
return sendDirect(msg);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.kloping.qqbot.api.message;

import io.github.kloping.qqbot.api.event.ChannelEvent;
import io.github.kloping.qqbot.api.Sender;
import io.github.kloping.qqbot.api.event.Event;
import io.github.kloping.qqbot.entities.ex.msg.MessageChain;
import io.github.kloping.qqbot.entities.qqpd.Member;
import io.github.kloping.qqbot.entities.qqpd.message.RawMessage;
Expand All @@ -11,7 +11,7 @@
*
* @author github.kloping
*/
public interface MessageEvent extends ChannelEvent, Sender {
public interface MessageEvent<T> extends Event, Sender {
/**
* 获取消息
*
Expand All @@ -24,7 +24,7 @@ public interface MessageEvent extends ChannelEvent, Sender {
*
* @return
*/
Member getSender();
T getSender();

/**
* 将消息转为 MessageChain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.github.kloping.qqbot.api.message;

import io.github.kloping.qqbot.entities.qqpd.Member;
import io.github.kloping.qqbot.entities.qqpd.message.EmojiReaction;

/**
* 消息表情表态事件接口
*
* @author github.kloping
*/
public interface MessageReactionEvent extends MessageEvent {
public interface MessageReactionEvent extends MessageEvent<Member> {

/**
* get MessageReaction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.github.kloping.qqbot.api.message;

import io.github.kloping.qqbot.entities.qqpd.Member;

/**
* 消息接收事件
*
* @author github.kloping
*/
public interface MessageReceiveEvent extends MessageEvent {
public interface MessageReceiveEvent extends MessageEvent<Member> {
/**
* 消息内容
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package io.github.kloping.qqbot.api.v2;

import io.github.kloping.qqbot.api.message.MessageEvent;
import io.github.kloping.qqbot.entities.qqpd.v2.Contact;
import io.github.kloping.qqbot.entities.qqpd.v2.Group;

/**
* @author github.kloping
*/
public interface GroupMessageEvent extends GroupEvent, MessageV2Event {

public interface GroupMessageEvent extends GroupEvent, MessageEvent<Contact>, MessageV2Event {
/**
* 发送环境
*
* @return
*/
Group getSubject();
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package io.github.kloping.qqbot.api.v2;

import io.github.kloping.qqbot.api.SendAble;
import io.github.kloping.qqbot.api.Sender;
import io.github.kloping.qqbot.api.event.Event;
import io.github.kloping.qqbot.entities.ex.msg.MessageChain;
import io.github.kloping.qqbot.entities.qqpd.v2.Contact;
import io.github.kloping.qqbot.http.data.V2Result;

/**
* @author github.kloping
*/
public interface MessageV2Event<T> extends Event {
public interface MessageV2Event extends Event, Sender {
/**
* 发送纯文本
*
* @param text
* @return
*/
T sendMessage(String text);
V2Result sendMessage(String text);

T sendMessage(SendAble msg);
V2Result sendMessage(SendAble msg);

/**
* 当前 因为腾讯服务器原因 消息中不存在at类型
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/io/github/kloping/qqbot/entities/ex/At.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import io.github.kloping.qqbot.api.SendAble;
import io.github.kloping.qqbot.api.SenderAndCidMidGetter;
import io.github.kloping.qqbot.http.data.ActionResult;
import io.github.kloping.qqbot.entities.ex.enums.EnvType;
import io.github.kloping.qqbot.http.data.Result;
import io.github.kloping.qqbot.impl.MessagePacket;
import lombok.Data;

Expand Down Expand Up @@ -32,9 +33,14 @@ public String toString() {
}

@Override
public ActionResult send(SenderAndCidMidGetter er) {
MessagePacket packet = new MessagePacket();
packet.setContent(toString());
return er.send(packet);
public Result send(SenderAndCidMidGetter er) {
if (er.getEnvType() == EnvType.GUILD) {
MessagePacket packet = new MessagePacket();
packet.setContent(toString());
return er.send(packet);
} else {
//暂未开放
return er.send(toString());
}
}
}
Loading

0 comments on commit 329a5e1

Please sign in to comment.