Add Stranger.asFriend and Stranger.asFriendOrNull

This commit is contained in:
Him188 2021-01-28 17:59:44 +08:00
parent 33fc9c9daa
commit 32362f02c3
2 changed files with 21 additions and 1 deletions

View File

@ -579,6 +579,11 @@ public abstract interface class net/mamoe/mirai/contact/Stranger : kotlinx/corou
public fun uploadImage (Lnet/mamoe/mirai/utils/ExternalResource;)Lnet/mamoe/mirai/message/data/Image;
}
public final class net/mamoe/mirai/contact/StrangerKt {
public static final fun asFriend (Lnet/mamoe/mirai/contact/Stranger;)Lnet/mamoe/mirai/contact/Friend;
public static final fun asFriendOrNull (Lnet/mamoe/mirai/contact/Stranger;)Lnet/mamoe/mirai/contact/Friend;
}
public abstract interface class net/mamoe/mirai/contact/TempUser : net/mamoe/mirai/contact/User {
public fun queryProfile ()Lnet/mamoe/mirai/data/UserProfile;
public fun sendMessage (Ljava/lang/String;)Lnet/mamoe/mirai/message/MessageReceipt;

View File

@ -92,3 +92,18 @@ public interface Stranger : User, CoroutineScope {
*/
public override fun nudge(): StrangerNudge = StrangerNudge(this)
}
/**
* 得到此陌生人作为好友的对象.
*
* @throws IllegalStateException 当此成员不是好友时抛出
* @since 2.2
*/
public fun Stranger.asFriend(): Friend = this.bot.getFriend(this.id) ?: error("$this is not a friend")
/**
* 得到此陌生人作为好友的对象, 当此成员不是好友时返回 `null`
* @since 2.2
*/
public fun Stranger.asFriendOrNull(): Friend? = this.bot.getFriend(this.id)