Skip to content

Commit

Permalink
feat(core): OneBotGroup 支持 setAnonymous
Browse files Browse the repository at this point in the history
  • Loading branch information
ForteScarlet committed Jun 21, 2024
1 parent dc033b1 commit 0d531ea
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
41 changes: 40 additions & 1 deletion Writerside/topics/onebot11-OneBotGroup.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ group.setNameReserve("newName")
</tab>
</tabs>


### 设置bot群备注

可以通过 `setBotGroupNick(String?)` 来设置bot在群内的群备注。
Expand Down Expand Up @@ -398,6 +397,46 @@ group.getAllHonorInfoReserve()
- `strong_newbie`
- `emotion`

### 设置匿名聊天

可以通过 `setAnonymous(Boolean)` 来设置是否允许匿名聊天,`true` 为开启。

> 这可能需要bot拥有管理权限。
<tabs group="code">
<tab title="Kotlin" group-key="Kotlin">

```Kotlin
val group: OneBotGroup = ...
group.setAnonymous(true)
```

</tab>
<tab title="Java" group-key="Java">

```Java
OneBotGroup group = ...;
group.setAnonymousAsync(true);
```
{switcher-key=%ja%}

```Java
OneBotGroup group = ...;
group.setAnonymousBlocking(true);
```
{switcher-key=%jb%}

```Java
OneBotGroup group = ...;
group.setAnonymousReserve(true)
.transform(SuspendReserves.mono())
.subscribe();
```
{switcher-key=%jr%}

</tab>
</tabs>

## 获取 OneBotGroup

`OneBotGroup` 主要来自 `OneBotBot` 获取或与群相关的事件。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ 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.GetGroupHonorInfoApi
import love.forte.simbot.component.onebot.v11.core.api.GetGroupHonorInfoResult
import love.forte.simbot.component.onebot.v11.core.api.SetGroupAdminApi
import love.forte.simbot.component.onebot.v11.core.api.SetGroupLeaveApi
import love.forte.simbot.component.onebot.v11.core.api.*
import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot
import love.forte.simbot.component.onebot.v11.message.OneBotMessageReceipt
import love.forte.simbot.definition.ChatGroup
Expand Down Expand Up @@ -136,6 +133,15 @@ public interface OneBotGroup : ChatGroup, DeleteSupport {
@STP
override suspend fun botAsMember(): OneBotMember

/**
* 使用 [SetGroupAnonymousApi] 设置群组匿名(的开关)。
*
* @param enable 是否开启(允许)匿名聊天。true为允许。
* @throws Throwable 任何可能在请求API过程中产生的异常。
*/
@ST
public suspend fun setAnonymous(enable: Boolean)

/**
* 向此群内发送消息。
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ public interface OneBotMember : Member, DeleteSupport, OneBotStrangerAware {
@JvmSynthetic
public suspend fun setSpecialTitle(specialTitle: String, duration: Duration)



/**
* 向此成员发送消息。
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ internal abstract class OneBotGroupImpl(
return result.dataOrThrow.toMember(bot)
}


override suspend fun setAnonymous(enable: Boolean) {
SetGroupAnonymousApi.create(
groupId = id,
enable = enable
).requestDataBy(bot)
}

override suspend fun send(text: String): OneBotMessageReceipt {
return sendGroupTextMsgApi(
target = id,
Expand Down

0 comments on commit 0d531ea

Please sign in to comment.