Skip to content

Commit

Permalink
Merge pull request #24 from simple-robot/dev/set-group-name-support
Browse files Browse the repository at this point in the history
OneBotGroup 支持设置群名API
  • Loading branch information
ForteScarlet authored Jun 12, 2024
2 parents 75e6755 + ef35627 commit 17525fd
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2024. ForteScarlet.
*
* This file is part of simbot-component-onebot.
*
* simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot.
* If not, see <https://www.gnu.org/licenses/>.
*/

package love.forte.simbot.component.onebot.common.annotations

/**
* 一个标记性注解,标记一个类型 (通常是一个抽象类或接口)
* 或函数应当仅由**内部实现**,
* 对外实现不稳定且不保证兼容性。
*
*/
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@MustBeDocumented
public annotation class OneBotInternalImplementationsOnly
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package love.forte.simbot.component.onebot.v11.core.actor

import love.forte.simbot.common.id.ID
import love.forte.simbot.common.id.literal
import love.forte.simbot.component.onebot.common.annotations.OneBotInternalImplementationsOnly
import love.forte.simbot.component.onebot.v11.common.utils.qqAvatar640
import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot
import love.forte.simbot.component.onebot.v11.message.OneBotMessageReceipt
Expand All @@ -39,6 +40,7 @@ import kotlin.coroutines.CoroutineContext
*
* @author ForteScarlet
*/
@OneBotInternalImplementationsOnly
public interface OneBotFriend : Contact, SendLikeSupport {
/**
* 协程上下文。源自 [OneBotBot], 但是不含 [Job][kotlinx.coroutines.Job]。

Check warning on line 46 in simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotFriend.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unresolved reference in KDoc

Cannot resolve symbol 'coroutines'

Check warning on line 46 in simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotFriend.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unresolved reference in KDoc

Cannot resolve symbol 'kotlinx'

Check warning on line 46 in simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotFriend.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unresolved reference in KDoc

Cannot resolve symbol 'Job'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import love.forte.simbot.ability.StandardDeleteOption
import love.forte.simbot.common.collectable.Collectable
import love.forte.simbot.common.collectable.asCollectable
import love.forte.simbot.common.id.ID
import love.forte.simbot.component.onebot.common.annotations.OneBotInternalImplementationsOnly
import love.forte.simbot.component.onebot.v11.core.api.SetGroupLeaveApi
import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot
import love.forte.simbot.component.onebot.v11.message.OneBotMessageReceipt
Expand Down Expand Up @@ -53,6 +54,7 @@ import kotlin.jvm.JvmSynthetic
*
* @author ForteScarlet
*/
@OneBotInternalImplementationsOnly
public interface OneBotGroup : ChatGroup, DeleteSupport {
/**
* 协程上下文。源自 [OneBotBot], 但是不含 [Job][kotlinx.coroutines.Job]。

Check warning on line 60 in simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotGroup.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unresolved reference in KDoc

Cannot resolve symbol 'coroutines'

Check warning on line 60 in simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotGroup.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unresolved reference in KDoc

Cannot resolve symbol 'kotlinx'

Check warning on line 60 in simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotGroup.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unresolved reference in KDoc

Cannot resolve symbol 'Job'
Expand Down Expand Up @@ -141,6 +143,23 @@ public interface OneBotGroup : ChatGroup, DeleteSupport {
*/
@ST
public suspend fun ban(enable: Boolean)

/**
* 设置群名。
*
* 当 [setName] 修改成功后会影响 [name] 的值,

Check warning on line 150 in simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotGroup.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unresolved reference in KDoc

Cannot resolve symbol 'name'
* 但是仅会影响 **当前对象** 内的属性值。
*
* [name] 在内部的实现应当是 `Volatile` 的,

Check warning on line 153 in simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotGroup.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unresolved reference in KDoc

Cannot resolve symbol 'name'
* 但是 [setName] 不保证并发安全也不会加锁,
* 如果并发请求 [setName],无法保证 [name] 的最终结果。

Check warning on line 155 in simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotGroup.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unresolved reference in KDoc

Cannot resolve symbol 'name'
*
* @param newName 要设置的新群名
*
* @throws Throwable 任何在请求API过程中可能产生的异常
*/
@ST
public suspend fun setName(newName: String)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import love.forte.simbot.ability.StandardDeleteOption
import love.forte.simbot.common.id.ID
import love.forte.simbot.common.id.literal
import love.forte.simbot.common.time.TimeUnit
import love.forte.simbot.component.onebot.common.annotations.OneBotInternalImplementationsOnly
import love.forte.simbot.component.onebot.v11.common.utils.qqAvatar640
import love.forte.simbot.component.onebot.v11.core.api.SetGroupBanApi
import love.forte.simbot.component.onebot.v11.core.api.SetGroupKickApi
Expand Down Expand Up @@ -54,6 +55,7 @@ import kotlin.time.Duration
*
* @author ForteScarlet
*/
@OneBotInternalImplementationsOnly
public interface OneBotMember : Member, DeleteSupport {
/**
* 协程上下文。源自 [OneBotBot], 但是不含 [Job][kotlinx.coroutines.Job]。

Check warning on line 61 in simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotMember.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unresolved reference in KDoc

Cannot resolve symbol 'kotlinx'

Check warning on line 61 in simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotMember.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unresolved reference in KDoc

Cannot resolve symbol 'Job'

Check warning on line 61 in simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotMember.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unresolved reference in KDoc

Cannot resolve symbol 'coroutines'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package love.forte.simbot.component.onebot.v11.core.actor

import love.forte.simbot.common.id.ID
import love.forte.simbot.common.id.literal
import love.forte.simbot.component.onebot.common.annotations.OneBotInternalImplementationsOnly
import love.forte.simbot.component.onebot.v11.common.utils.qqAvatar640
import love.forte.simbot.component.onebot.v11.core.api.GetStrangerInfoApi
import love.forte.simbot.definition.User
Expand All @@ -31,6 +32,7 @@ import love.forte.simbot.definition.User
*
* @author ForteScarlet
*/
@OneBotInternalImplementationsOnly
public interface OneBotStranger : User {
override val id: ID
override val name: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@ import love.forte.simbot.component.onebot.v11.message.OneBotMessageReceipt
import love.forte.simbot.component.onebot.v11.message.resolveToOneBotSegmentList
import love.forte.simbot.message.Message
import love.forte.simbot.message.MessageContent
import kotlin.concurrent.Volatile
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmInline


internal abstract class OneBotGroupImpl : OneBotGroup {
internal abstract class OneBotGroupImpl(
initialName: String
) : OneBotGroup {
protected abstract val bot: OneBotBotImpl

@Volatile
override var name: String = initialName
protected set

override val members: Collectable<OneBotMember>
get() = flowCollectable {
val list = GetGroupMemberListApi.create(id)
Expand Down Expand Up @@ -143,6 +150,15 @@ internal abstract class OneBotGroupImpl : OneBotGroup {
).requestDataBy(bot)
}

override suspend fun setName(newName: String) {
SetGroupNameApi.create(
id,
newName
).requestDataBy(bot)

this.name = newName
}

override fun toString(): String = "OneBotGroup(id=$id, bot=${bot.id})"
}

Expand All @@ -153,13 +169,10 @@ internal class OneBotGroupApiResultImpl(
private val source: GetGroupInfoResult,
override val bot: OneBotBotImpl,
override val ownerId: ID?,
) : OneBotGroupImpl() {
) : OneBotGroupImpl(source.groupName) {
override val coroutineContext: CoroutineContext = bot.subContext
override val id: ID
get() = source.groupId

override val name: String
get() = source.groupName
}

internal fun GetGroupInfoResult.toGroup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import love.forte.simbot.bot.GuildRelation
import love.forte.simbot.common.collectable.Collectable
import love.forte.simbot.common.id.ID
import love.forte.simbot.component.onebot.common.annotations.InternalOneBotAPI
import love.forte.simbot.component.onebot.common.annotations.OneBotInternalImplementationsOnly
import love.forte.simbot.component.onebot.v11.core.actor.OneBotFriend
import love.forte.simbot.component.onebot.v11.core.actor.OneBotGroup
import love.forte.simbot.component.onebot.v11.core.actor.OneBotMember
Expand All @@ -52,6 +53,7 @@ import kotlin.jvm.JvmSynthetic
*
* @author ForteScarlet
*/
@OneBotInternalImplementationsOnly
public interface OneBotBot : Bot {
override val coroutineContext: CoroutineContext

Expand Down Expand Up @@ -163,6 +165,7 @@ public interface OneBotBot : Bot {
*
* @see OneBotBot.contactRelation
*/
@OneBotInternalImplementationsOnly
public interface OneBotBotFriendRelation : ContactRelation {
/**
* 获取好友列表。
Expand Down Expand Up @@ -202,6 +205,7 @@ public interface OneBotBotFriendRelation : ContactRelation {
*
* @see OneBotBot.groupRelation
*/
@OneBotInternalImplementationsOnly
public interface OneBotBotGroupRelation : GroupRelation {
/**
* 获取群列表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import love.forte.simbot.common.services.Services
import love.forte.simbot.common.services.addProviderExceptJvm
import love.forte.simbot.component.NoSuchComponentException
import love.forte.simbot.component.find
import love.forte.simbot.component.onebot.common.annotations.OneBotInternalImplementationsOnly
import love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotManagerImpl
import love.forte.simbot.component.onebot.v11.core.component.OneBot11Component
import love.forte.simbot.logger.LoggerFactory
Expand All @@ -46,6 +47,7 @@ import love.forte.simbot.plugin.PluginFactoryProvider
*
* @author ForteScarlet
*/
@OneBotInternalImplementationsOnly
public abstract class OneBotBotManager : BotManager, JobBasedBotManager() {
abstract override fun all(): Sequence<OneBotBot>
abstract override fun get(id: ID): OneBotBot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package love.forte.simbot.component.onebot.v11.core.event

import love.forte.simbot.common.id.LongID
import love.forte.simbot.common.time.Timestamp
import love.forte.simbot.component.onebot.common.annotations.OneBotInternalImplementationsOnly
import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot
import love.forte.simbot.component.onebot.v11.core.event.stage.OneBotBotStageEvent
import love.forte.simbot.component.onebot.v11.core.utils.timestamp
Expand All @@ -36,14 +37,18 @@ public typealias OBSourceEvent = love.forte.simbot.component.onebot.v11.event.Ev
* 也是一些与OneBot协议本身无关的事件类型
* (例如 [OneBotBotStageEvent]) 的父类。
*/
@OneBotInternalImplementationsOnly
public interface OneBotCommonEvent : Event


/**
* OneBot11的[事件](https://github.com/botuniverse/onebot-11/tree/master/event)。
*
* 所有的事件类型接口都应当仅由内部实现,对外实现不稳定、不保证兼容性。
*
* @author ForteScarlet
*/
@OneBotInternalImplementationsOnly
public interface OneBotEvent : OneBotCommonEvent {
/**
* 来自事件JSON的反序列化数据体。
Expand Down Expand Up @@ -78,6 +83,7 @@ public interface OneBotEvent : OneBotCommonEvent {
/**
* OneBot组件事件中的 [BotEvent]。

Check warning on line 84 in simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/event/OneBotEvent.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unresolved reference in KDoc

Cannot resolve symbol 'BotEvent'
*/
@OneBotInternalImplementationsOnly
public interface OneBotBotEvent : OneBotEvent, BotEvent {
override val bot: OneBotBot
}

0 comments on commit 17525fd

Please sign in to comment.