Skip to content

Commit 2229d26

Browse files
authored
Merge pull request #29 from simple-robot/set-group-card
OneBotMember和OneBotGroup增加设置群成员群备注(card)的API支持
2 parents 4708a1f + 09e502a commit 2229d26

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed

simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotGroup.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ public interface OneBotGroup : ChatGroup, DeleteSupport {
150150
* 当 [setName] 修改成功后会影响 [name] 的值,
151151
* 但是仅会影响 **当前对象** 内的属性值。
152152
*
153-
* [name] 在内部的实现应当是 `Volatile` 的,
154-
* 但是 [setName] 不保证并发安全也不会加锁,
153+
* [setName] 不保证并发安全也不会加锁,
155154
* 如果并发请求 [setName],无法保证 [name] 的最终结果。
156155
*
157156
* @param newName 要设置的新群名
@@ -160,6 +159,17 @@ public interface OneBotGroup : ChatGroup, DeleteSupport {
160159
*/
161160
@ST
162161
public suspend fun setName(newName: String)
162+
163+
/**
164+
* 设置 bot 在此群内的群备注。
165+
*
166+
* @see OneBotMember.nick
167+
*
168+
* @param newNick 要设置的新备注, `null` 或空字符串代表删除备注
169+
* @throws Throwable 任何在请求API过程中可能产生的异常
170+
*/
171+
@ST
172+
public suspend fun setBotGroupNick(newNick: String?)
163173
}
164174

165175
/**

simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/OneBotMember.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,37 @@ public interface OneBotMember : Member, DeleteSupport {
7979
override val avatar: String
8080
get() = qqAvatar640(id.literal)
8181

82+
/**
83+
* 群成员的QQ名。
84+
*/
85+
override val name: String
86+
87+
/**
88+
* 群成员在群内的昵称,
89+
* 即群成员在群里的群备注,也就是 `card`。
90+
* 如果备注为空字符串,则会被视为 `null`,也就是没有备注。
91+
*
92+
* 不支持获取的情况下也会得到 `null`,例如在临时会话中。
93+
*/
94+
override val nick: String?
95+
96+
/**
97+
* 设置成员在此群内的群备注。
98+
*
99+
* 当 [setNick] 修改成功后会影响 [nick] 的值,
100+
* 但是仅会影响 **当前对象** 内的属性值。
101+
*
102+
* [setNick] 不保证并发安全也不会加锁,
103+
* 如果并发请求 [setNick],无法保证 [nick] 的最终结果。
104+
*
105+
* @see nick
106+
*
107+
* @param newNick 要设置的新备注, `null` 或空字符串代表删除备注
108+
* @throws Throwable 任何在请求API过程中可能产生的异常
109+
*/
110+
@ST
111+
public suspend fun setNick(newNick: String?)
112+
82113
/**
83114
* 向此成员发送消息。
84115
*

simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/internal/OneBotGroupImpl.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ internal abstract class OneBotGroupImpl(
159159
this.name = newName
160160
}
161161

162+
override suspend fun setBotGroupNick(newNick: String?) {
163+
SetGroupCardApi.create(
164+
groupId = id,
165+
userId = bot.userId,
166+
card = newNick
167+
).requestDataBy(bot)
168+
}
169+
162170
override fun toString(): String = "OneBotGroup(id=$id, bot=${bot.id})"
163171
}
164172

simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/actor/internal/OneBotMemberImpl.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ import love.forte.simbot.common.time.TimeUnit
2424
import love.forte.simbot.component.onebot.v11.core.actor.OneBotMember
2525
import love.forte.simbot.component.onebot.v11.core.actor.OneBotMemberDeleteOption
2626
import love.forte.simbot.component.onebot.v11.core.actor.OneBotMemberRole
27-
import love.forte.simbot.component.onebot.v11.core.api.GetGroupMemberInfoResult
28-
import love.forte.simbot.component.onebot.v11.core.api.SetGroupAnonymousBanApi
29-
import love.forte.simbot.component.onebot.v11.core.api.SetGroupBanApi
30-
import love.forte.simbot.component.onebot.v11.core.api.SetGroupKickApi
27+
import love.forte.simbot.component.onebot.v11.core.api.*
3128
import love.forte.simbot.component.onebot.v11.core.bot.internal.OneBotBotImpl
3229
import love.forte.simbot.component.onebot.v11.core.bot.requestDataBy
3330
import love.forte.simbot.component.onebot.v11.core.internal.message.toReceipt
@@ -168,6 +165,14 @@ internal abstract class OneBotMemberImpl : OneBotMember {
168165
).requestDataBy(bot)
169166
}
170167

168+
override suspend fun setNick(newNick: String?) {
169+
SetGroupCardApi.create(
170+
groupId = groupIdOrFailure,
171+
userId = id,
172+
card = newNick
173+
)
174+
}
175+
171176
override fun toString(): String = "OneBotMember(id=$id, bot=${bot.id})"
172177
}
173178

0 commit comments

Comments
 (0)