Add simplified one-line API for publishing a single announcement

This commit is contained in:
Him188 2021-07-05 16:01:03 +08:00
parent b98fcdd2e5
commit d08c6b81a8
3 changed files with 85 additions and 0 deletions

View File

@ -572,12 +572,30 @@ public abstract interface class net/mamoe/mirai/contact/VoiceSupported : net/mam
}
public abstract interface class net/mamoe/mirai/contact/announcement/Announcement {
public static final field Companion Lnet/mamoe/mirai/contact/announcement/Announcement$Companion;
public abstract fun getContent ()Ljava/lang/String;
public abstract fun getParameters ()Lnet/mamoe/mirai/contact/announcement/AnnouncementParameters;
public static fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public static fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public static fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lnet/mamoe/mirai/contact/announcement/AnnouncementParameters;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public static fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lnet/mamoe/mirai/contact/announcement/AnnouncementParameters;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun publishTo (Lnet/mamoe/mirai/contact/Group;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public fun publishTo (Lnet/mamoe/mirai/contact/Group;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
public final class net/mamoe/mirai/contact/announcement/Announcement$Companion {
public final fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public final fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public final fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lnet/mamoe/mirai/contact/announcement/AnnouncementParameters;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public final fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lnet/mamoe/mirai/contact/announcement/AnnouncementParameters;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun publishAnnouncement$default (Lnet/mamoe/mirai/contact/announcement/Announcement$Companion;Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lnet/mamoe/mirai/contact/announcement/AnnouncementParameters;ILjava/lang/Object;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public static synthetic fun publishAnnouncement$default (Lnet/mamoe/mirai/contact/announcement/Announcement$Companion;Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lnet/mamoe/mirai/contact/announcement/AnnouncementParameters;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}
public final class net/mamoe/mirai/contact/announcement/AnnouncementImage {
public static final field Companion Lnet/mamoe/mirai/contact/announcement/AnnouncementImage$Companion;
public static final field SERIAL_NAME Ljava/lang/String;

View File

@ -572,12 +572,30 @@ public abstract interface class net/mamoe/mirai/contact/VoiceSupported : net/mam
}
public abstract interface class net/mamoe/mirai/contact/announcement/Announcement {
public static final field Companion Lnet/mamoe/mirai/contact/announcement/Announcement$Companion;
public abstract fun getContent ()Ljava/lang/String;
public abstract fun getParameters ()Lnet/mamoe/mirai/contact/announcement/AnnouncementParameters;
public static fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public static fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public static fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lnet/mamoe/mirai/contact/announcement/AnnouncementParameters;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public static fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lnet/mamoe/mirai/contact/announcement/AnnouncementParameters;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun publishTo (Lnet/mamoe/mirai/contact/Group;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public fun publishTo (Lnet/mamoe/mirai/contact/Group;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
public final class net/mamoe/mirai/contact/announcement/Announcement$Companion {
public final fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public final fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public final fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lnet/mamoe/mirai/contact/announcement/AnnouncementParameters;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public final fun publishAnnouncement (Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lnet/mamoe/mirai/contact/announcement/AnnouncementParameters;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun publishAnnouncement$default (Lnet/mamoe/mirai/contact/announcement/Announcement$Companion;Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lnet/mamoe/mirai/contact/announcement/AnnouncementParameters;ILjava/lang/Object;)Lnet/mamoe/mirai/contact/announcement/OnlineAnnouncement;
public static synthetic fun publishAnnouncement$default (Lnet/mamoe/mirai/contact/announcement/Announcement$Companion;Lnet/mamoe/mirai/contact/Group;Ljava/lang/String;Lnet/mamoe/mirai/contact/announcement/AnnouncementParameters;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}
public final class net/mamoe/mirai/contact/announcement/AnnouncementImage {
public static final field Companion Lnet/mamoe/mirai/contact/announcement/AnnouncementImage$Companion;
public static final field SERIAL_NAME Ljava/lang/String;

View File

@ -15,6 +15,9 @@ package net.mamoe.mirai.contact.announcement
import net.mamoe.kjbb.JvmBlockingBridge
import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.contact.PermissionDeniedException
import net.mamoe.mirai.contact.announcement.Announcement.Companion.publishAnnouncement
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
/**
@ -35,6 +38,8 @@ import net.mamoe.mirai.contact.PermissionDeniedException
*
* 在构造时可提供可选的 [AnnouncementParameters] 来设置一些附加属性.
*
* 也可以使用 [Announcement.publishAnnouncement] 扩展快捷创建并发送公告.
*
* ### 转发获取的公告到其他群
*
* 通过一个群的 [Announcements] 获取到 [OnlineAnnouncement], 然后调用 [OnlineAnnouncement.publishTo] 到另一个群即可.
@ -70,6 +75,50 @@ public sealed interface Announcement {
* @see Announcements.publish
*/
public suspend fun publishTo(group: Group): OnlineAnnouncement = group.announcements.publish(this)
public companion object {
/**
* 在该群发布群公告并获得 [OnlineAnnouncement]. 发布公告后群内将会出现 "有新公告" 系统提示.
*
* @param content 公告内容
* @param parameters 可选的附加参数
*
* @throws PermissionDeniedException 当没有权限时抛出
* @throws IllegalStateException 当协议异常时抛出
*
* @see OfflineAnnouncement
* @see Announcement.publishTo
* @see AnnouncementParametersBuilder
*/
@JvmOverloads
@JvmStatic
public suspend inline fun Group.publishAnnouncement(
content: String,
parameters: AnnouncementParameters = AnnouncementParameters.DEFAULT
): OnlineAnnouncement = this.announcements.publish(OfflineAnnouncement(content, parameters))
/**
* 在该群发布群公告并获得 [OnlineAnnouncement]. 发布公告后群内将会出现 "有新公告" 系统提示.
*
* @param content 公告内容
* @param parameters 可选的附加参数
*
* @throws PermissionDeniedException 当没有权限时抛出
* @throws IllegalStateException 当协议异常时抛出
*
* @see OfflineAnnouncement
* @see Announcement.publishTo
* @see AnnouncementParametersBuilder
*/
@JvmSynthetic
public suspend inline fun Group.publishAnnouncement(
content: String,
parameters: AnnouncementParametersBuilder.() -> Unit
): OnlineAnnouncement {
contract { callsInPlace(parameters, InvocationKind.EXACTLY_ONCE) }
return this.announcements.publish(OfflineAnnouncement(content, parameters))
}
}
}
/**