# 好友 OneBotFriend

> For the complete documentation index, see [llms.txt](https://simbot.forte.love/llms.txt).

`OneBotFriend` 实现 `Contact`, `OneBotStrangerAware` 和其他一些功能接口（后续 "更多能力" 中会介绍）， 用于表示一个 OneBot11 协议中的 好友。

## Contact

`OneBotFriend` 实现来自 `Contact` 定义的抽象属性或函数。

id
: QQ号。

avatar
: 成员QQ头像。

name
: 用户名。

## SendSupport

`OneBotFriend` 拥有发送消息的能力。 使用 `send` 发送纯文本、消息或转发事件消息体。

Kotlin:

```KOTLIN
val friend: OneBotFriend = ...
friend.send("text")
friend.send("text".toText() + Face(123.ID))
friend.send(messageContent)
```

Java:

```JAVA
OneBotFriend friend = ...;
friend.sendAsync("text"); 
friend.sendAsync(
    Messages.builder()
        .add("text")
        .add(new Face(Identifies.of(123)))
        .build()
); 
friend.sendAsync(messageContent); 
```

```JAVA
OneBotFriend friend = ...;
friend.sendBlocking("text");
friend.sendBlocking(
        Messages.builder()
            .add("text")
            .add(new Face(Identifies.of(123)))
            .build()
    );
friend.sendBlocking(messageContent);
```

```JAVA
OneBotFriend friend = ...;
friend.sendReserve("text")
    .transform(SuspendReserves.mono())
    .subscribe();

friend.sendReserve(
    Messages.builder()
            .add("text")
            .add(new Face(Identifies.of(123)))
    .build()
    )
        .transform(SuspendReserves.mono())
    .subscribe();

friend.sendReserve(messageContent)
    .transform(SuspendReserves.mono())
    .subscribe();
```

## OneBotStrangerAware

`OneBotFriend` 实现 `OneBotStrangerAware`， 可以通过 `toStranger` 查询并得到一个对应的 `OneBotStranger` 类型。

Kotlin:

```KOTLIN
val friend: OneBotFriend = ...
val stranger = friend.toStranger()
```

Java:

```JAVA
OneBotFriend friend = ...;
friend.toStrangerAsync()
        .thenAccept(stranger -> {
            // ...
        });
```

```JAVA
OneBotFriend friend = ...;
var stranger = friend.toStrangerBlocking();
```

```JAVA
OneBotFriend friend = ...;
friend.toStrangerReserve()
        .transform(SuspendReserves.mono())
        .subscribe(stranger -> {
            // ... 
        });
```

## 更多能力

### SendLinkSupport

`OneBotFriend` 实现 `SendLinkSupport` 接口， 支持使用 `sendLike(Int)` 来点赞用户。

参数代表次数，一般来说一人一天最多共计10次赞， 但是代码内无校验，交给OneBot服务端处理。

Kotlin:

```KOTLIN
val friend: OneBotFriend = ...
friend.sendLike(5)
```

Java:

```JAVA
OneBotFriend friend = ...;
friend.sendLinkAsync(5);
```

```JAVA
OneBotFriend friend = ...;
friend.sendLinkBlocking(5);
```

```JAVA
OneBotFriend friend = ...;
friend.sendLinkReserve(5)
        .transform(SuspendReserves.mono())
        .subscribe();
```

## 获取 OneBotFriend

好友 `OneBotFriend` 通常来自 [OneBotBot](component-onebot-v11-onebotbot.html) 或与好友相关的事件。

### 来自事件

大多数跟好友相关的事件中都可以直接获取到 `OneBotFriend`。 通常来讲，如果事件主体与好友相关，那么就是 `content`， 如果侧面相关，例如某个好友消息事件中， 消息才是重点，而好友则为 `author`。

