mirror of
https://github.com/mamoe/mirai.git
synced 2024-12-28 09:30:10 +08:00
Separate mirai-japt
from main repository
This commit is contained in:
parent
6b45f99160
commit
9ea6b2899f
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
||||
#Thu Feb 06 14:10:33 CST 2020
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 14 KiB |
Binary file not shown.
Before Width: | Height: | Size: 6.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 6.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 32 KiB |
@ -1,100 +0,0 @@
|
||||
|
||||
# mirai-japt
|
||||
|
||||
Mirai Java Apt
|
||||
|
||||
提供阻塞API 来让 Java 调用 Mirai 的 API 更容易
|
||||
|
||||
## 编译需求
|
||||
|
||||
- JDK 1.8+
|
||||
|
||||
## 配置依赖
|
||||
|
||||
使用 `Gradle` 或 `Maven`.
|
||||
|
||||
请将 `CORE_VERSION` 替换为最新的版本(如 `0.15.0`):
|
||||
[![Download](https://api.bintray.com/packages/him188moe/mirai/mirai-core/images/download.svg)](https://bintray.com/him188moe/mirai/mirai-core/)
|
||||
|
||||
请将 `JAPT_VERSION` 替换为最新的版本(如 `1.0.0`):
|
||||
[![Download](https://api.bintray.com/packages/him188moe/mirai/mirai-japt/images/download.svg)](https://bintray.com/him188moe/mirai/mirai-japt/)
|
||||
|
||||
### Maven
|
||||
```xml
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jcenter</id>
|
||||
<url>https://jcenter.bintray.com/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
```
|
||||
```xml
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.mamoe</groupId>
|
||||
<artifactId>mirai-core-qqandroid-jvm</artifactId>
|
||||
<version>CORE_VERSION</version> <!-- 替换版本为最新版本 -->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.mamoe</groupId>
|
||||
<artifactId>mirai-japt</artifactId>
|
||||
<version>JAPT_VERSION</version> <!-- 替换版本为最新版本 -->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
### Gradle
|
||||
```kotlin
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("net.mamoe:mirai-core-qqandroid-jvm:CORE_VERSION")
|
||||
implementation("net.mamoe:mirai-japt:JAPT_VERSION")
|
||||
}
|
||||
```
|
||||
|
||||
## 开始
|
||||
|
||||
```java
|
||||
class Test{
|
||||
public static void main(String[] args){
|
||||
BlockingBot bot = BlockingBot.newInstance(123456, "");
|
||||
|
||||
bot.login();
|
||||
|
||||
bot.getFriendList().forEach(friend -> {
|
||||
System.out.println(friend.getNick());
|
||||
});
|
||||
|
||||
Events.subscribeAlways(GroupMessage.class, (GroupMessage message) -> {
|
||||
final BlockingQQ sender = BlockingContacts.createBlocking(message.getSender());
|
||||
|
||||
sender.sendMessage("Hello");
|
||||
});
|
||||
|
||||
Thread.sleep(999999999);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 便捷开发
|
||||
|
||||
在 IntelliJ IDEA 或 Android Studio 中找到设置 `Editor -> General -> Postfix Completion`, 添加一个设置到 `Java` 分类中:
|
||||
![](.README_images/ce3034e3.png)
|
||||
Applicable expression types:
|
||||
```
|
||||
net.mamoe.mirai.contact.Contact
|
||||
```
|
||||
转换后表达式:
|
||||
```
|
||||
net.mamoe.mirai.japt.BlockingContacts.createBlocking($EXPR$)
|
||||
```
|
||||
|
||||
效果:
|
||||
|
||||
![4SY8BC@J4ZKQM7OZ_~BC1I_1](.README_images/4SY8BC%40J4ZKQM%5D7OZ_~BC1I_1.png)
|
||||
|
||||
![722WEHTTXD6XFFH43](.README_images/722W%28E%24HTTX%7BD6XFFH%5D%5D%2443.png)
|
@ -1,136 +0,0 @@
|
||||
import java.util.*
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
google()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Do try to waste your time.
|
||||
@kotlin.Suppress("GradleDependency") // 1.8.4 不能跑
|
||||
classpath("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0")
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
java
|
||||
id("com.jfrog.bintray") version "1.8.0"
|
||||
`maven-publish`
|
||||
// maven
|
||||
}
|
||||
|
||||
val kotlinVersion: String by rootProject.ext
|
||||
val atomicFuVersion: String by rootProject.ext
|
||||
val coroutinesVersion: String by rootProject.ext
|
||||
val kotlinXIoVersion: String by rootProject.ext
|
||||
val coroutinesIoVersion: String by rootProject.ext
|
||||
val serializationVersion: String by rootProject.ext
|
||||
|
||||
val klockVersion: String by rootProject.ext
|
||||
val ktorVersion: String by rootProject.ext
|
||||
|
||||
description = "Java helper for Mirai"
|
||||
|
||||
@Suppress("PropertyName")
|
||||
val mirai_japt_version: String by rootProject.ext
|
||||
version = mirai_japt_version
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
all {
|
||||
languageSettings.enableLanguageFeature("InlineClasses")
|
||||
|
||||
languageSettings.useExperimentalAnnotation("kotlin.Experimental")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
|
||||
|
||||
fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"
|
||||
|
||||
dependencies {
|
||||
implementation(project(":mirai-core"))
|
||||
runtimeOnly(files("../mirai-core/build/classes/kotlin/jvm/main")) // classpath is not added correctly by IDE
|
||||
|
||||
api(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-javafx", version = "1.3.2")
|
||||
|
||||
api(kotlin("stdlib", kotlinVersion))
|
||||
api(kotlinx("io-jvm", kotlinXIoVersion))
|
||||
api(kotlinx("io", kotlinXIoVersion))
|
||||
api(kotlinx("coroutines-io", coroutinesIoVersion))
|
||||
api(kotlinx("coroutines-core", coroutinesVersion))
|
||||
api(kotlin("stdlib-jdk7", kotlinVersion))
|
||||
api(kotlin("stdlib-jdk8", kotlinVersion))
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>() {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
bintray {
|
||||
val keyProps = Properties()
|
||||
val keyFile = file("../keys.properties")
|
||||
if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) }
|
||||
|
||||
user = keyProps.getProperty("bintrayUser")
|
||||
key = keyProps.getProperty("bintrayKey")
|
||||
setPublications("mavenJava")
|
||||
setConfigurations("archives")
|
||||
|
||||
pkg.apply {
|
||||
repo = "mirai"
|
||||
name = "mirai-japt"
|
||||
setLicenses("AGPLv3")
|
||||
publicDownloadNumbers = true
|
||||
vcsUrl = "https://github.com/mamoe/mirai"
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
val sourcesJar by tasks.registering(Jar::class) {
|
||||
classifier = "sources"
|
||||
from(sourceSets.main.get().allSource)
|
||||
}
|
||||
|
||||
publishing {
|
||||
/*
|
||||
repositories {
|
||||
maven {
|
||||
// change to point to your repo, e.g. http://my.org/repo
|
||||
url = uri("$buildDir/repo")
|
||||
}
|
||||
}*/
|
||||
publications {
|
||||
register("mavenJava", MavenPublication::class) {
|
||||
from(components["java"])
|
||||
|
||||
groupId = rootProject.group.toString()
|
||||
artifactId = "mirai-japt"
|
||||
version = mirai_japt_version
|
||||
|
||||
pom.withXml {
|
||||
val root = asNode()
|
||||
root.appendNode("description", description)
|
||||
root.appendNode("name", project.name)
|
||||
root.appendNode("url", "https://github.com/mamoe/mirai")
|
||||
root.children().last()
|
||||
}
|
||||
|
||||
artifact(sourcesJar.get())
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
## Contact ##
|
||||
.blocking : Blocking wrap
|
||||
net.mamoe.mirai.contact.QQ → net.mamoe.mirai.japt.BlockingContacts.createBlocking($expr$)
|
||||
net.mamoe.mirai.contact.QQ [net.mamoe.mirai.japt.BlockingContacts] → net.mamoe.mirai.japt.BlockingContacts.createBlocking($expr$)
|
||||
net.mamoe.mirai.timpc.network.QQImpl [net.mamoe.mirai.japt.BlockingContacts] → net.mamoe.mirai.japt.BlockingContacts.createBlocking($expr$)
|
@ -1,193 +0,0 @@
|
||||
package net.mamoe.mirai.japt;
|
||||
|
||||
import net.mamoe.mirai.Bot;
|
||||
import net.mamoe.mirai.BotAccount;
|
||||
import net.mamoe.mirai.BotFactoryJvmKt;
|
||||
import net.mamoe.mirai.contact.QQ;
|
||||
import net.mamoe.mirai.data.AddFriendResult;
|
||||
import net.mamoe.mirai.data.GroupInfo;
|
||||
import net.mamoe.mirai.data.MemberInfo;
|
||||
import net.mamoe.mirai.message.data.Image;
|
||||
import net.mamoe.mirai.network.BotNetworkHandler;
|
||||
import net.mamoe.mirai.utils.BotConfiguration;
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI;
|
||||
import net.mamoe.mirai.utils.MiraiInternalAPI;
|
||||
import net.mamoe.mirai.utils.MiraiLogger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 对 {@link Bot} 的阻塞式包装
|
||||
*
|
||||
* @see Bot
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface BlockingBot {
|
||||
/**
|
||||
* 使用默认配置创建一个机器人实例
|
||||
*
|
||||
* @param id qq 号
|
||||
* @param password 密码
|
||||
* @return 机器人实例
|
||||
*/
|
||||
static BlockingBot newInstance(long id, String password) {
|
||||
return BlockingContacts.createBlocking(BotFactoryJvmKt.Bot(id, password));
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用特定配置创建一个机器人实例
|
||||
*
|
||||
* @param id qq 号
|
||||
* @param password 密码
|
||||
* @return 机器人实例
|
||||
*/
|
||||
static BlockingBot newInstance(long id, String password, BotConfiguration configuration) {
|
||||
return BlockingContacts.createBlocking(BotFactoryJvmKt.Bot(id, password, configuration));
|
||||
}
|
||||
|
||||
// 要获取 Bot 实例列表, 请前往 BotKt
|
||||
|
||||
/**
|
||||
* 账号信息
|
||||
*/
|
||||
@MiraiInternalAPI
|
||||
@NotNull
|
||||
BotAccount getAccount();
|
||||
|
||||
/**
|
||||
* QQ 号码. 实际类型为 uint
|
||||
*/
|
||||
long getUin();
|
||||
|
||||
/**
|
||||
* 获取昵称
|
||||
*/
|
||||
@NotNull
|
||||
@MiraiExperimentalAPI(message = "还未支持")
|
||||
String getNick();
|
||||
|
||||
/**
|
||||
* 日志记录器
|
||||
*/
|
||||
@NotNull
|
||||
MiraiLogger getLogger();
|
||||
|
||||
// region contacts
|
||||
|
||||
/**
|
||||
* 获取自身 QQ 实例
|
||||
*/
|
||||
@NotNull
|
||||
QQ getSelfQQ();
|
||||
|
||||
/**
|
||||
* 与这个机器人相关的 QQ 列表. 机器人与 QQ 不一定是好友
|
||||
*/
|
||||
@NotNull
|
||||
List<BlockingQQ> getFriendList();
|
||||
|
||||
/**
|
||||
* 获取缓存的 QQ 对象. 若没有对应的缓存, 则会线程安全地创建一个.
|
||||
*/
|
||||
@NotNull
|
||||
BlockingQQ getFriend(long id);
|
||||
|
||||
/**
|
||||
* 与这个机器人相关的群列表. 机器人不一定是群成员.
|
||||
*/
|
||||
@NotNull
|
||||
List<BlockingGroup> getGroupList();
|
||||
|
||||
/**
|
||||
* 获取缓存的群对象. 若没有对应的缓存, 则会线程安全地创建一个.
|
||||
* 若 {@code id} 无效, 将会抛出 {@link NoSuchElementException}
|
||||
*/
|
||||
@NotNull
|
||||
BlockingGroup getGroup(long id);
|
||||
|
||||
|
||||
// endregion
|
||||
|
||||
// region network
|
||||
|
||||
/**
|
||||
* 网络模块
|
||||
*/
|
||||
@NotNull
|
||||
BotNetworkHandler getNetwork();
|
||||
|
||||
/**
|
||||
* 登录.
|
||||
*/
|
||||
void login();
|
||||
|
||||
/**
|
||||
* 查询群列表. 返回值前 32 bits 为 uin, 后 32 bits 为 groupCode
|
||||
*/
|
||||
@NotNull
|
||||
Stream<Long> queryGroupList();
|
||||
|
||||
/**
|
||||
* 查询群资料. 获得的仅为当前时刻的资料.
|
||||
* 请优先使用 {@link #getGroup(long)} 然后查看群资料.
|
||||
*/
|
||||
@NotNull
|
||||
GroupInfo queryGroupInfo(long groupCode);
|
||||
|
||||
/**
|
||||
* 查询群成员列表.
|
||||
* 请优先使用 {@link #getGroup(long)} , {@link BlockingGroup#getMembers()} 查看群成员.
|
||||
* <p>
|
||||
* 这个函数很慢. 请不要频繁使用.
|
||||
*/
|
||||
@NotNull
|
||||
Stream<MemberInfo> queryGroupMemberList(long groupUin, long groupCode, long ownerId);
|
||||
|
||||
// endregion
|
||||
|
||||
// region actions
|
||||
|
||||
/**
|
||||
* 下载图片到 {@code outputStream}.
|
||||
* 不会自动关闭 {@code outputStream}
|
||||
*/
|
||||
void downloadTo(@NotNull Image image, @NotNull OutputStream outputStream);
|
||||
|
||||
/**
|
||||
* 下载图片到 {@code outputStream} 并关闭 stream
|
||||
*/
|
||||
void downloadAndClose(@NotNull Image image, @NotNull OutputStream outputStream);
|
||||
|
||||
/**
|
||||
* 添加一个好友
|
||||
*
|
||||
* @param message 若需要验证请求时的验证消息.
|
||||
* @param remark 好友备注
|
||||
*/
|
||||
@NotNull
|
||||
AddFriendResult addFriend(long id, @Nullable String message, @Nullable String remark);
|
||||
|
||||
/**
|
||||
* 同意来自陌生人的加好友请求
|
||||
*/
|
||||
void approveFriendAddRequest(long id, @Nullable String remark);
|
||||
// endregion
|
||||
|
||||
/**
|
||||
* 关闭这个 [Bot], 停止一切相关活动. 不可重新登录.
|
||||
*/
|
||||
void close(@Nullable Throwable throwable);
|
||||
|
||||
/**
|
||||
* @deprecated 使用 {@link #close(Throwable)}
|
||||
*/
|
||||
@Deprecated
|
||||
default void dispose(@Nullable Throwable throwable) {
|
||||
close(throwable);
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
package net.mamoe.mirai.japt;
|
||||
|
||||
import net.mamoe.mirai.Bot;
|
||||
import net.mamoe.mirai.contact.Contact;
|
||||
import net.mamoe.mirai.contact.Member;
|
||||
import net.mamoe.mirai.contact.QQ;
|
||||
import net.mamoe.mirai.event.events.BeforeImageUploadEvent;
|
||||
import net.mamoe.mirai.event.events.EventCancelledException;
|
||||
import net.mamoe.mirai.event.events.ImageUploadEvent;
|
||||
import net.mamoe.mirai.event.events.MessageSendEvent.FriendMessageSendEvent;
|
||||
import net.mamoe.mirai.event.events.MessageSendEvent.GroupMessageSendEvent;
|
||||
import net.mamoe.mirai.message.MessageReceipt;
|
||||
import net.mamoe.mirai.message.data.Image;
|
||||
import net.mamoe.mirai.message.data.Message;
|
||||
import net.mamoe.mirai.message.data.MessageChain;
|
||||
import net.mamoe.mirai.utils.ExternalImage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* 对 {@link Contact} 的阻塞式包装.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface BlockingContact {
|
||||
/**
|
||||
* 这个联系人所属 {@link Bot}
|
||||
*/
|
||||
@NotNull
|
||||
BlockingBot getBot();
|
||||
|
||||
/**
|
||||
* 可以是 QQ 号码或者群号码.
|
||||
* <p>
|
||||
* 对于 QQ, {@code uin} 与 {@code id} 是相同的意思.
|
||||
* 对于 Group, {@code groupCode} 与 {@code id} 是相同的意思.
|
||||
*/
|
||||
long getId();
|
||||
|
||||
/**
|
||||
* 向这个对象发送消息.
|
||||
*
|
||||
* @throws EventCancelledException 当发送消息事件被取消
|
||||
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
|
||||
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
|
||||
* @see GroupMessageSendEvent 发送群消息事件. cancellable
|
||||
*/
|
||||
MessageReceipt<? extends Contact> sendMessage(@NotNull MessageChain messages) throws EventCancelledException, IllegalStateException;
|
||||
|
||||
/**
|
||||
* 向这个对象发送消息.
|
||||
*
|
||||
* @throws EventCancelledException 当发送消息事件被取消
|
||||
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
|
||||
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
|
||||
* @see GroupMessageSendEvent 发送群消息事件. cancellable
|
||||
*/
|
||||
MessageReceipt<? extends Contact> sendMessage(@NotNull String message) throws EventCancelledException, IllegalStateException;
|
||||
|
||||
/**
|
||||
* 向这个对象发送消息.
|
||||
*
|
||||
* @throws EventCancelledException 当发送消息事件被取消
|
||||
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
|
||||
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
|
||||
* @see GroupMessageSendEvent 发送群消息事件. cancellable
|
||||
*/
|
||||
MessageReceipt<? extends Contact> sendMessage(@NotNull Message message) throws EventCancelledException, IllegalStateException;
|
||||
|
||||
/**
|
||||
* 上传一个图片以备发送.
|
||||
* 群图片与好友图片在服务器上是通用的, 在 mirai 目前不通用.
|
||||
*
|
||||
* @throws EventCancelledException 当发送消息事件被取消
|
||||
* @see BeforeImageUploadEvent 图片发送前事件, cancellable
|
||||
* @see ImageUploadEvent 图片发送完成事件
|
||||
*/
|
||||
Image uploadImage(@NotNull ExternalImage image) throws EventCancelledException;
|
||||
|
||||
/**
|
||||
* 判断 {@code this} 和 {@code other} 是否是相同的类型, 并且 {@link Contact#getId()} 相同.
|
||||
* <p>
|
||||
* 注:
|
||||
* {@link Contact#getId()} 相同的 {@link Member} 和 {@link QQ}, 他们并不 equals.
|
||||
* 因为, {@link Member} 含义为群员, 必属于一个群.
|
||||
* 而 {@link QQ} 含义为一个独立的人, 可以是好友, 也可以是陌生人.
|
||||
*/
|
||||
boolean equals(Object other);
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package net.mamoe.mirai.japt;
|
||||
|
||||
import net.mamoe.mirai.Bot;
|
||||
import net.mamoe.mirai.contact.Group;
|
||||
import net.mamoe.mirai.contact.Member;
|
||||
import net.mamoe.mirai.contact.QQ;
|
||||
import net.mamoe.mirai.japt.internal.BlockingBotImpl;
|
||||
import net.mamoe.mirai.japt.internal.BlockingGroupImpl;
|
||||
import net.mamoe.mirai.japt.internal.BlockingMemberImpl;
|
||||
import net.mamoe.mirai.japt.internal.BlockingQQImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 构造阻塞式的联系人.
|
||||
*/
|
||||
public final class BlockingContacts {
|
||||
@NotNull
|
||||
public static BlockingQQ createBlocking(@NotNull QQ qq) {
|
||||
return new BlockingQQImpl(Objects.requireNonNull(qq));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static BlockingGroup createBlocking(@NotNull Group group) {
|
||||
return new BlockingGroupImpl(Objects.requireNonNull(group));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static BlockingMember createBlocking(@NotNull Member member) {
|
||||
return new BlockingMemberImpl(Objects.requireNonNull(member));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static BlockingBot createBlocking(@NotNull Bot bot) {
|
||||
return new BlockingBotImpl(Objects.requireNonNull(bot));
|
||||
}
|
||||
}
|
@ -1,216 +0,0 @@
|
||||
package net.mamoe.mirai.japt;
|
||||
|
||||
import net.mamoe.mirai.contact.*;
|
||||
import net.mamoe.mirai.data.MemberInfo;
|
||||
import net.mamoe.mirai.event.events.*;
|
||||
import net.mamoe.mirai.message.MessageReceipt;
|
||||
import net.mamoe.mirai.message.data.Message;
|
||||
import net.mamoe.mirai.message.data.MessageChain;
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface BlockingGroup extends BlockingContact {
|
||||
/**
|
||||
* 群名称.
|
||||
*/
|
||||
@NotNull
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* 修改群名称
|
||||
* 频繁修改可能会被服务器拒绝.
|
||||
*
|
||||
* @throws PermissionDeniedException 无权限修改时将会抛出异常
|
||||
* @see MemberPermissionChangeEvent
|
||||
*/
|
||||
void setName(@NotNull String name) throws PermissionDeniedException;
|
||||
|
||||
/**
|
||||
* 入群公告, 没有时为空字符串. (同步事件更新)
|
||||
*/
|
||||
@NotNull
|
||||
String getEntranceAnnouncement();
|
||||
|
||||
/**
|
||||
* 修改入群公告.
|
||||
*
|
||||
* @throws PermissionDeniedException 无权限修改时将会抛出异常
|
||||
* @see GroupEntranceAnnouncementChangeEvent
|
||||
*/
|
||||
void setEntranceAnnouncement(@NotNull String announcement) throws PermissionDeniedException;
|
||||
|
||||
/**
|
||||
* 获取全员禁言状态
|
||||
*
|
||||
* @return 全员禁言状态. true 为开启
|
||||
*/
|
||||
boolean isMuteAll();
|
||||
|
||||
/**
|
||||
* 设置全体禁言
|
||||
*
|
||||
* @see GroupMuteAllEvent
|
||||
*/
|
||||
void setMuteAll(boolean enabled) throws PermissionDeniedException;
|
||||
|
||||
/**
|
||||
* 获取坦白说状态
|
||||
*
|
||||
* @return 坦白说状态, true 为允许
|
||||
*/
|
||||
boolean isConfessTalkEnabled();
|
||||
|
||||
/**
|
||||
* 设置坦白说状态
|
||||
*
|
||||
* @throws PermissionDeniedException 无权限修改时将会抛出异常
|
||||
* @see GroupAllowConfessTalkEvent
|
||||
*/
|
||||
void setConfessTalk(boolean enabled) throws PermissionDeniedException;
|
||||
|
||||
/**
|
||||
* 获取允许群员邀请好友入群的状态.
|
||||
*
|
||||
* @return 允许群员邀请好友入群的状态. `true` 为允许
|
||||
*/
|
||||
boolean isAllowMemberInvite();
|
||||
|
||||
/**
|
||||
* 设置允许群员邀请好友入群的状态.
|
||||
*
|
||||
* @throws PermissionDeniedException 无权限修改时将会抛出异常
|
||||
* @see GroupAllowMemberInviteEvent
|
||||
*/
|
||||
void setAllowMemberInvite(boolean allow) throws PermissionDeniedException;
|
||||
|
||||
/**
|
||||
* 获取自动加群审批的状态
|
||||
*/
|
||||
boolean isAutoApproveEnabled();
|
||||
|
||||
/**
|
||||
* 匿名聊天是否开启
|
||||
*/
|
||||
boolean isAnonymousChatEnabled();
|
||||
|
||||
/**
|
||||
* 同为 groupCode, 用户看到的群号码.
|
||||
*/
|
||||
@Override
|
||||
long getId();
|
||||
|
||||
/**
|
||||
* 群主 (同步事件更新)
|
||||
*/
|
||||
@NotNull
|
||||
BlockingMember getOwner();
|
||||
|
||||
/**
|
||||
* 机器人被禁言还剩余多少秒
|
||||
*
|
||||
* @see BotMuteEvent
|
||||
* @see GroupKt#isBotMuted
|
||||
*/
|
||||
int getBotMuteRemaining();
|
||||
|
||||
/**
|
||||
* 检查机器人是否正处于禁言状态
|
||||
*/
|
||||
default boolean isBotMuted() {
|
||||
int time = getBotMuteRemaining();
|
||||
return time != 0 && time != 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* 机器人在这个群里的权限
|
||||
*
|
||||
* @see BotGroupPermissionChangeEvent
|
||||
*/
|
||||
@NotNull
|
||||
@MiraiExperimentalAPI
|
||||
MemberPermission getBotPermission();
|
||||
|
||||
/**
|
||||
* 在 {@link Group} 实例创建的时候查询一次. 并与事件同步事件更新
|
||||
* <p>
|
||||
* **注意**: 获得的列表仅为这一时刻的成员列表的镜像. 它将不会被更新
|
||||
*/
|
||||
@NotNull
|
||||
List<BlockingMember> getMembers();
|
||||
|
||||
/**
|
||||
* 获取群成员. 若此 ID 的成员不存在, 则会抛出 {@link NoSuchElementException}
|
||||
*/
|
||||
@NotNull
|
||||
BlockingMember getMember(long id);
|
||||
|
||||
/**
|
||||
* 获取群成员. 若此 ID 的成员不存在则返回 null
|
||||
*/
|
||||
@Nullable
|
||||
BlockingMember getMemberOrNull(long id);
|
||||
|
||||
/**
|
||||
* 向这个对象发送消息.
|
||||
*
|
||||
* @throws EventCancelledException 当发送消息事件被取消
|
||||
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
|
||||
* @see MessageSendEvent.FriendMessageSendEvent 发送好友信息事件, cancellable
|
||||
* @see MessageSendEvent.GroupMessageSendEvent 发送群消息事件. cancellable
|
||||
*/
|
||||
MessageReceipt<Group> sendMessage(@NotNull MessageChain messages) throws EventCancelledException, IllegalStateException;
|
||||
|
||||
/**
|
||||
* 向这个对象发送消息.
|
||||
*
|
||||
* @throws EventCancelledException 当发送消息事件被取消
|
||||
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
|
||||
* @see MessageSendEvent.FriendMessageSendEvent 发送好友信息事件, cancellable
|
||||
* @see MessageSendEvent.GroupMessageSendEvent 发送群消息事件. cancellable
|
||||
*/
|
||||
MessageReceipt<Group> sendMessage(@NotNull String message) throws EventCancelledException, IllegalStateException;
|
||||
|
||||
/**
|
||||
* 向这个对象发送消息.
|
||||
*
|
||||
* @throws EventCancelledException 当发送消息事件被取消
|
||||
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
|
||||
* @see MessageSendEvent.FriendMessageSendEvent 发送好友信息事件, cancellable
|
||||
* @see MessageSendEvent.GroupMessageSendEvent 发送群消息事件. cancellable
|
||||
*/
|
||||
MessageReceipt<Group> sendMessage(@NotNull Message message) throws EventCancelledException, IllegalStateException;
|
||||
|
||||
/**
|
||||
* 检查此 id 的群成员是否存在
|
||||
*/
|
||||
boolean containsMember(long id);
|
||||
|
||||
/**
|
||||
* 让机器人退出这个群. 机器人必须为非群主才能退出. 否则将会失败
|
||||
*/
|
||||
boolean quit();
|
||||
|
||||
/**
|
||||
* 构造一个 [Member].
|
||||
* 非特殊情况请不要使用这个函数. 优先使用 [get].
|
||||
*/
|
||||
@MiraiExperimentalAPI(message = "dangerous")
|
||||
@NotNull
|
||||
Member newMember(@NotNull MemberInfo memberInfo);
|
||||
|
||||
@NotNull
|
||||
String toFullString();
|
||||
|
||||
static long calculateGroupUinByGroupCode(long groupCode) {
|
||||
return Group.Companion.calculateGroupUinByGroupCode(groupCode);
|
||||
}
|
||||
|
||||
static long calculateGroupCodeByGroupUin(long groupUin) {
|
||||
return Group.Companion.calculateGroupCodeByGroupUin(groupUin);
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
package net.mamoe.mirai.japt;
|
||||
|
||||
import kotlin.text.StringsKt;
|
||||
import net.mamoe.mirai.contact.MemberPermission;
|
||||
import net.mamoe.mirai.contact.PermissionDeniedException;
|
||||
import net.mamoe.mirai.event.events.MemberCardChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface BlockingMember extends BlockingQQ {
|
||||
/**
|
||||
* 所在的群
|
||||
*/
|
||||
@NotNull
|
||||
BlockingGroup getGroup();
|
||||
|
||||
/**
|
||||
* 权限
|
||||
*/
|
||||
@NotNull
|
||||
MemberPermission getPermission();
|
||||
|
||||
/**
|
||||
* 群名片. 可能为空.
|
||||
*/
|
||||
@NotNull
|
||||
String getNameCard();
|
||||
|
||||
/**
|
||||
* 修改群名片. 将会触发事件
|
||||
*
|
||||
* @throws PermissionDeniedException 无权限修改时
|
||||
* @see #getGroupCardOrNick() 获取非空群名片或昵称
|
||||
* @see MemberCardChangeEvent 群名片被管理员, 自己或 [Bot] 改动事件
|
||||
*/
|
||||
void setNameCard(@NotNull String nameCard) throws PermissionDeniedException;
|
||||
|
||||
/**
|
||||
* 获取群名片或昵称
|
||||
*/
|
||||
@NotNull
|
||||
default String getGroupCardOrNick() {
|
||||
String nameCard = this.getNameCard();
|
||||
if (!StringsKt.isBlank(nameCard)) {
|
||||
return nameCard;
|
||||
}
|
||||
return this.getNick();
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁言
|
||||
*
|
||||
* @param durationSeconds 持续时间. 精确到秒. 范围区间表示为 `(0s, 30days]`. 超过范围则会抛出异常.
|
||||
* @throws PermissionDeniedException 无权限修改时
|
||||
*/
|
||||
void mute(int durationSeconds);
|
||||
|
||||
/**
|
||||
* 禁言
|
||||
*
|
||||
* @param durationSeconds 持续时间. 精确到秒. 范围区间表示为 `(0s, 30days]`. 超过范围则会抛出异常.
|
||||
* @throws PermissionDeniedException 无权限修改时
|
||||
*/
|
||||
default void mute(long durationSeconds) {
|
||||
mute((int) durationSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解除禁言
|
||||
*
|
||||
* @throws PermissionDeniedException 无权限修改时
|
||||
*/
|
||||
void unmute();
|
||||
|
||||
/**
|
||||
* 踢出该成员.
|
||||
*
|
||||
* @param message 消息
|
||||
* @throws PermissionDeniedException 无权限修改时
|
||||
*/
|
||||
void kick(@NotNull String message);
|
||||
|
||||
/**
|
||||
* 踢出该成员.
|
||||
*
|
||||
* @throws PermissionDeniedException 无权限修改时
|
||||
*/
|
||||
default void kick() {
|
||||
kick("");
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
package net.mamoe.mirai.japt;
|
||||
|
||||
import net.mamoe.mirai.contact.QQ;
|
||||
import net.mamoe.mirai.data.FriendNameRemark;
|
||||
import net.mamoe.mirai.data.PreviousNameList;
|
||||
import net.mamoe.mirai.data.Profile;
|
||||
import net.mamoe.mirai.event.events.EventCancelledException;
|
||||
import net.mamoe.mirai.event.events.MessageSendEvent;
|
||||
import net.mamoe.mirai.message.MessageReceipt;
|
||||
import net.mamoe.mirai.message.data.Message;
|
||||
import net.mamoe.mirai.message.data.MessageChain;
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface BlockingQQ extends BlockingContact {
|
||||
/**
|
||||
* 获取 QQ 号码
|
||||
*
|
||||
* @return QQ 号码
|
||||
*/
|
||||
@Override
|
||||
long getId();
|
||||
|
||||
/**
|
||||
* 获取昵称
|
||||
*
|
||||
* @return 昵称
|
||||
*/
|
||||
String getNick();
|
||||
|
||||
/**
|
||||
* 查询用户资料
|
||||
*/
|
||||
@MiraiExperimentalAPI(message = "还未支持")
|
||||
@NotNull
|
||||
Profile queryProfile();
|
||||
|
||||
/**
|
||||
* 查询曾用名.
|
||||
* <p>
|
||||
* 曾用名可能是:
|
||||
* - 昵称
|
||||
* - 共同群内的群名片
|
||||
*/
|
||||
@MiraiExperimentalAPI(message = "还未支持")
|
||||
@NotNull
|
||||
PreviousNameList queryPreviousNameList();
|
||||
|
||||
/**
|
||||
* 查询机器人账号给这个人设置的备注
|
||||
*/
|
||||
@MiraiExperimentalAPI(message = "还未支持")
|
||||
@NotNull
|
||||
FriendNameRemark queryRemark();
|
||||
|
||||
/**
|
||||
* 向这个对象发送消息.
|
||||
*
|
||||
* @throws EventCancelledException 当发送消息事件被取消
|
||||
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
|
||||
* @see MessageSendEvent.FriendMessageSendEvent 发送好友信息事件, cancellable
|
||||
* @see MessageSendEvent.GroupMessageSendEvent 发送群消息事件. cancellable
|
||||
*/
|
||||
MessageReceipt<QQ> sendMessage(@NotNull MessageChain messages) throws EventCancelledException, IllegalStateException;
|
||||
|
||||
/**
|
||||
* 向这个对象发送消息.
|
||||
*
|
||||
* @throws EventCancelledException 当发送消息事件被取消
|
||||
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
|
||||
* @see MessageSendEvent.FriendMessageSendEvent 发送好友信息事件, cancellable
|
||||
* @see MessageSendEvent.GroupMessageSendEvent 发送群消息事件. cancellable
|
||||
*/
|
||||
MessageReceipt<QQ> sendMessage(@NotNull String message) throws EventCancelledException, IllegalStateException;
|
||||
|
||||
/**
|
||||
* 向这个对象发送消息.
|
||||
*
|
||||
* @throws EventCancelledException 当发送消息事件被取消
|
||||
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
|
||||
* @see MessageSendEvent.FriendMessageSendEvent 发送好友信息事件, cancellable
|
||||
* @see MessageSendEvent.GroupMessageSendEvent 发送群消息事件. cancellable
|
||||
*/
|
||||
MessageReceipt<QQ> sendMessage(@NotNull Message message) throws EventCancelledException, IllegalStateException;
|
||||
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.japt;
|
||||
|
||||
import kotlinx.coroutines.GlobalScope;
|
||||
import net.mamoe.mirai.event.Event;
|
||||
import net.mamoe.mirai.event.Listener;
|
||||
import net.mamoe.mirai.event.ListeningStatus;
|
||||
import net.mamoe.mirai.event.internal.EventInternalJvmKt;
|
||||
import net.mamoe.mirai.japt.internal.EventsImplKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 事件处理
|
||||
*/
|
||||
public final class Events {
|
||||
|
||||
/**
|
||||
* 监听一个事件, 当 {@code onEvent} 返回 {@link ListeningStatus#STOPPED} 时停止监听.
|
||||
* 机器人离线后不会停止监听.
|
||||
*
|
||||
* @param eventClass 事件类
|
||||
* @param onEvent 事件处理. 返回 {@link ListeningStatus#LISTENING} 时继续监听.
|
||||
* @param <E> 事件类型
|
||||
* @return 事件监听器. 可调用 {@link Listener#complete()} 或 {@link Listener#completeExceptionally(Throwable)} 让监听正常停止或异常停止.
|
||||
*/
|
||||
@NotNull
|
||||
public static <E extends Event> Listener<E> subscribe(@NotNull Class<E> eventClass, @NotNull Function<E, ListeningStatus> onEvent) {
|
||||
return EventInternalJvmKt._subscribeEventForJaptOnly(eventClass, GlobalScope.INSTANCE, onEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听一个事件, 直到手动停止.
|
||||
* 机器人离线后不会停止监听.
|
||||
*
|
||||
* @param eventClass 事件类
|
||||
* @param onEvent 事件处理. 返回 {@link ListeningStatus#LISTENING} 时继续监听.
|
||||
* @param <E> 事件类型
|
||||
* @return 事件监听器. 可调用 {@link Listener#complete()} 或 {@link Listener#completeExceptionally(Throwable)} 让监听正常停止或异常停止.
|
||||
*/
|
||||
@NotNull
|
||||
public static <E extends Event> Listener<E> subscribeAlways(@NotNull Class<E> eventClass, @NotNull Consumer<E> onEvent) {
|
||||
return EventInternalJvmKt._subscribeEventForJaptOnly(eventClass, GlobalScope.INSTANCE, onEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 阻塞地广播一个事件.
|
||||
*
|
||||
* @param event 事件
|
||||
* @param <E> 事件类型
|
||||
* @return {@code event} 本身
|
||||
*/
|
||||
@NotNull
|
||||
public static <E extends Event> E broadcast(@NotNull E event) {
|
||||
return EventsImplKt.broadcast(event);
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.japt.internal
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.BotAccount
|
||||
import net.mamoe.mirai.contact.QQ
|
||||
import net.mamoe.mirai.data.AddFriendResult
|
||||
import net.mamoe.mirai.data.GroupInfo
|
||||
import net.mamoe.mirai.data.MemberInfo
|
||||
import net.mamoe.mirai.japt.BlockingBot
|
||||
import net.mamoe.mirai.japt.BlockingGroup
|
||||
import net.mamoe.mirai.japt.BlockingQQ
|
||||
import net.mamoe.mirai.message.data.Image
|
||||
import net.mamoe.mirai.network.BotNetworkHandler
|
||||
import net.mamoe.mirai.utils.*
|
||||
import java.io.OutputStream
|
||||
import java.util.stream.Stream
|
||||
import kotlin.streams.asStream
|
||||
|
||||
@UseExperimental(MiraiInternalAPI::class, MiraiExperimentalAPI::class)
|
||||
internal class BlockingBotImpl(private val bot: Bot) : BlockingBot {
|
||||
@MiraiInternalAPI
|
||||
override fun getAccount(): BotAccount = bot.account
|
||||
|
||||
override fun getUin(): Long = bot.uin
|
||||
@MiraiExperimentalAPI
|
||||
override fun getNick(): String = bot.nick
|
||||
|
||||
override fun getLogger(): MiraiLogger = bot.logger
|
||||
override fun getSelfQQ(): QQ = bot.selfQQ
|
||||
|
||||
override fun queryGroupMemberList(groupUin: Long, groupCode: Long, ownerId: Long): Stream<MemberInfo> =
|
||||
runBlocking { bot.queryGroupMemberList(groupUin, groupCode, ownerId) }.asStream()
|
||||
|
||||
@UseExperimental(MiraiInternalAPI::class)
|
||||
override fun getFriendList(): List<BlockingQQ> = bot.qqs.delegate.toList().map { it.blocking() }
|
||||
|
||||
override fun getFriend(id: Long): BlockingQQ = bot.getFriend(id).blocking()
|
||||
override fun queryGroupList(): Stream<Long> = runBlocking { bot.queryGroupList() }.asStream()
|
||||
|
||||
override fun getGroupList(): List<BlockingGroup> = bot.groups.delegate.toList().map { it.blocking() }
|
||||
|
||||
override fun queryGroupInfo(code: Long): GroupInfo = runBlocking { bot.queryGroupInfo(code) }
|
||||
|
||||
override fun getGroup(id: Long): BlockingGroup = runBlocking { bot.getGroup(id).blocking() }
|
||||
override fun getNetwork(): BotNetworkHandler = bot.network
|
||||
override fun login() = runBlocking { bot.login() }
|
||||
override fun downloadTo(image: Image, outputStream: OutputStream) = bot.run { runBlocking { openChannel(image).copyTo(outputStream) } }
|
||||
override fun downloadAndClose(image: Image, outputStream: OutputStream) = bot.run { runBlocking { openChannel(image).copyAndClose(outputStream) } }
|
||||
override fun addFriend(id: Long, message: String?, remark: String?): AddFriendResult = runBlocking { bot.addFriend(id, message, remark) }
|
||||
override fun approveFriendAddRequest(id: Long, remark: String?) = runBlocking { bot.approveFriendAddRequest(id, remark) }
|
||||
override fun close(throwable: Throwable?) = bot.close(throwable)
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:Suppress("NOTHING_TO_INLINE", "unused")
|
||||
|
||||
package net.mamoe.mirai.japt.internal
|
||||
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.contact.Member
|
||||
import net.mamoe.mirai.contact.QQ
|
||||
import net.mamoe.mirai.japt.*
|
||||
|
||||
inline fun Group.blocking(): BlockingGroup =
|
||||
BlockingContacts.createBlocking(this)
|
||||
|
||||
inline fun QQ.blocking(): BlockingQQ = BlockingContacts.createBlocking(this)
|
||||
inline fun Member.blocking(): BlockingMember =
|
||||
BlockingContacts.createBlocking(this)
|
||||
|
||||
inline fun Bot.blocking(): BlockingBot = BlockingContacts.createBlocking(this)
|
@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:Suppress("EXPERIMENTAL_API_USAGE")
|
||||
|
||||
package net.mamoe.mirai.japt.internal
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.contact.Member
|
||||
import net.mamoe.mirai.contact.MemberPermission
|
||||
import net.mamoe.mirai.contact.QQ
|
||||
import net.mamoe.mirai.data.FriendNameRemark
|
||||
import net.mamoe.mirai.data.MemberInfo
|
||||
import net.mamoe.mirai.data.PreviousNameList
|
||||
import net.mamoe.mirai.data.Profile
|
||||
import net.mamoe.mirai.japt.BlockingBot
|
||||
import net.mamoe.mirai.japt.BlockingGroup
|
||||
import net.mamoe.mirai.japt.BlockingMember
|
||||
import net.mamoe.mirai.japt.BlockingQQ
|
||||
import net.mamoe.mirai.message.MessageReceipt
|
||||
import net.mamoe.mirai.message.data.*
|
||||
import net.mamoe.mirai.utils.ExternalImage
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||
import net.mamoe.mirai.utils.toList
|
||||
|
||||
internal class BlockingQQImpl(private val delegate: QQ) : BlockingQQ {
|
||||
override fun getBot(): BlockingBot = delegate.bot.blocking()
|
||||
override fun getId(): Long = delegate.id
|
||||
override fun getNick(): String = delegate.nick
|
||||
|
||||
override fun sendMessage(messages: MessageChain): MessageReceipt<QQ> = runBlocking { delegate.sendMessage(messages) }
|
||||
override fun sendMessage(message: String): MessageReceipt<QQ> = runBlocking { delegate.sendMessage(message.toMessage().toChain()) }
|
||||
override fun sendMessage(message: Message): MessageReceipt<QQ> = runBlocking { delegate.sendMessage(message.toChain()) }
|
||||
override fun uploadImage(image: ExternalImage): Image = runBlocking { delegate.uploadImage(image) }
|
||||
|
||||
@MiraiExperimentalAPI
|
||||
override fun queryProfile(): Profile = runBlocking { delegate.queryProfile() }
|
||||
|
||||
@MiraiExperimentalAPI
|
||||
override fun queryPreviousNameList(): PreviousNameList = runBlocking { delegate.queryPreviousNameList() }
|
||||
|
||||
@MiraiExperimentalAPI
|
||||
override fun queryRemark(): FriendNameRemark = runBlocking { delegate.queryRemark() }
|
||||
}
|
||||
|
||||
internal class BlockingGroupImpl(private val delegate: Group) : BlockingGroup {
|
||||
override fun sendMessage(messages: MessageChain): MessageReceipt<Group> = runBlocking { delegate.sendMessage(messages) }
|
||||
override fun sendMessage(message: String): MessageReceipt<Group> = runBlocking { delegate.sendMessage(message.toMessage().toChain()) }
|
||||
override fun sendMessage(message: Message): MessageReceipt<Group> = runBlocking { delegate.sendMessage(message.toChain()) }
|
||||
override fun getOwner(): BlockingMember = delegate.owner.blocking()
|
||||
@MiraiExperimentalAPI
|
||||
override fun newMember(memberInfo: MemberInfo): Member = delegate.Member(memberInfo)
|
||||
|
||||
override fun uploadImage(image: ExternalImage): Image = runBlocking { delegate.uploadImage(image) }
|
||||
override fun setEntranceAnnouncement(announcement: String) {
|
||||
delegate.entranceAnnouncement = announcement
|
||||
}
|
||||
|
||||
override fun getName(): String = delegate.name
|
||||
override fun getId(): Long = delegate.id
|
||||
@MiraiExperimentalAPI
|
||||
override fun getBotPermission(): MemberPermission = delegate.botPermission
|
||||
|
||||
override fun setConfessTalk(enabled: Boolean) {
|
||||
delegate.isConfessTalkEnabled = enabled
|
||||
}
|
||||
|
||||
override fun isAnonymousChatEnabled(): Boolean = delegate.isAnonymousChatEnabled
|
||||
|
||||
override fun isAutoApproveEnabled(): Boolean = delegate.isAutoApproveEnabled
|
||||
|
||||
override fun isConfessTalkEnabled(): Boolean = delegate.isConfessTalkEnabled
|
||||
|
||||
override fun toFullString(): String = delegate.toFullString()
|
||||
override fun containsMember(id: Long): Boolean = delegate.contains(id)
|
||||
|
||||
override fun isAllowMemberInvite(): Boolean = delegate.isAllowMemberInvite
|
||||
|
||||
override fun getMember(id: Long): BlockingMember = delegate[id].blocking()
|
||||
override fun getBot(): BlockingBot = delegate.bot.blocking()
|
||||
override fun getBotMuteRemaining(): Int = delegate.botMuteRemaining
|
||||
|
||||
override fun isMuteAll(): Boolean = delegate.isMuteAll
|
||||
|
||||
override fun setName(name: String) {
|
||||
delegate.name = name
|
||||
}
|
||||
|
||||
override fun setMuteAll(enabled: Boolean) {
|
||||
delegate.isMuteAll = enabled
|
||||
}
|
||||
|
||||
override fun getEntranceAnnouncement(): String = delegate.entranceAnnouncement
|
||||
@UseExperimental(MiraiInternalAPI::class)
|
||||
override fun getMembers(): List<BlockingMember> =
|
||||
delegate.members.delegate.toList().map { it.blocking() }
|
||||
|
||||
override fun setAllowMemberInvite(allow: Boolean) {
|
||||
delegate.isAllowMemberInvite = allow
|
||||
}
|
||||
|
||||
override fun getMemberOrNull(id: Long): BlockingMember? {
|
||||
return delegate.getOrNull(id)?.blocking()
|
||||
}
|
||||
|
||||
override fun quit(): Boolean = runBlocking { delegate.quit() }
|
||||
}
|
||||
|
||||
internal class BlockingMemberImpl(private val delegate: Member) : BlockingMember, BlockingQQ by (delegate as QQ).blocking() {
|
||||
override fun getGroup(): BlockingGroup = delegate.group.blocking()
|
||||
override fun getNameCard(): String = delegate.nameCard
|
||||
|
||||
override fun getPermission(): MemberPermission = delegate.permission
|
||||
override fun setNameCard(nameCard: String) {
|
||||
delegate.nameCard = nameCard
|
||||
}
|
||||
|
||||
override fun mute(durationSeconds: Int) = runBlocking { delegate.mute(durationSeconds) }
|
||||
override fun unmute() = runBlocking { delegate.unmute() }
|
||||
override fun kick(message: String) {
|
||||
runBlocking { delegate.kick(message) }
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.japt.internal
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.mamoe.mirai.event.Event
|
||||
import net.mamoe.mirai.event.broadcast
|
||||
|
||||
internal fun <E : Event> broadcast(e: E): E = runBlocking { e.broadcast() }
|
Loading…
Reference in New Issue
Block a user