注意:您使用的 sdk 版本与 Perpetua 版本号应当一一对应
Perpetua 的通信 sdk,java 实现
<repository>
<id>iunlimit-releases</id>
<name>IllTamer's Repository</name>
<url>https://maven.illtamer.com/releases</url>
</repository>
<dependency>
<groupId>com.illtamer.perpetua.sdk</groupId>
<artifactId>perpetua-sdk</artifactId>
<version>${project.version}</version>
</dependency>
OneBotConnection.start("127.0.0.1", 8080, null, event -> {
if (event instanceof HeartbeatEvent) return;
if (event instanceof MessageEvent) {
System.out.println(event);
System.out.println(((MessageEvent) event).getMessage().getMessageChain());
}
});
Message message = MessageBuilder.json()
.text("Hi", false)
.face(FaceType._159)
.text("这是一条自动换行消息")
.build();
Message message = ((MessageEvent) event).getMessage();
for (TransferEntity entity : message.getMessageChain()) {
if (entity instanceof At) {
System.out.printf("QQ: %s, 被@", ((At) entity).getQq());
}
}
-
同步
OpenAPIHandling.sendMessage("hi", 765743073L);
或者
Response<Map<String, Object>> response = new PrivateMsgSendHandler() .setUserId(userId) .setMessage(message) .request(); long messageId = (long) response.getData().get("message_id");
-
异步
Supplier<Response<Object>> supplier = new GroupSetCardHandler() .setGroupId(863522624L) .setUserId(765743073L) .setCard("新的群名片昵称") .requestAsync(); // new thread System.out.println(supplier.get());
public class OneBotAutoConfiguration implements ApplicationRunner {
private final BotProperties botProperties;
private final Consumer<Event> eventConsumer;
public OneBotAutoConfiguration(
BotProperties botProperties,
ApplicationContext context
) {
this.botProperties = botProperties;
this.eventConsumer = context::publishEvent;
}
@Async
@Override
public void run(ApplicationArguments args) throws InterruptedException {
OneBotConnection.start(
botProperties.getHost(),
botProperties.getHttpUri(),
botProperties.getAuthorization(),
eventConsumer
);
}
}