-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from Redmomn/main
docs: 迁移LagrangeGo文档
- Loading branch information
Showing
12 changed files
with
492 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# 创建一个bot实例 | ||
|
||
## QQClient | ||
|
||
位于`github.com/LagrangeDev/LagrangeGo/client` | ||
|
||
> 创建一个QQClient,参数分别是qq号,appinfo,sign地址... | ||
方法签名: | ||
|
||
```go | ||
func NewClient(uin uint32, appInfo *auth.AppInfo, signUrl ...string) *QQClient | ||
``` | ||
|
||
示例 | ||
|
||
```go | ||
qqclient := client.NewClient(0, appInfo,"https://sign.lagrangecore.org/api/sign") | ||
``` | ||
|
||
## DeviceInfo | ||
|
||
```go | ||
// 创建一个新的DeviceInfo,可使用随机数字作为参数 | ||
deviceInfo := NewDeviceInfo(114514) | ||
``` | ||
|
||
```go | ||
// 加载DeviceInfo,如果指定的路径不存在,则返回一个新的info并保存 | ||
deviceInfo := auth.LoadOrSaveDevice(path) | ||
|
||
// 保存DeviceInfo | ||
deviceInfo.Save(path) | ||
``` | ||
|
||
```go | ||
qqclient.UseDevice(deviceInfo) | ||
``` | ||
|
||
## SigInfo | ||
|
||
```go | ||
// 序列化,得到的data可自行存储 | ||
data, err := sig.Marshal() | ||
|
||
// 反序列化 | ||
sig, err := UnmarshalSigInfo(data, true) | ||
``` | ||
|
||
```go | ||
// 存储与加载sig示例 | ||
data, err := os.ReadFile("sig.bin") | ||
if err != nil { | ||
logrus.Warnln("read sig error:", err) | ||
} else { | ||
sig, err := auth.UnmarshalSigInfo(data, true) | ||
if err != nil { | ||
logrus.Warnln("load sig error:", err) | ||
} else { | ||
qqclient.UseSig(sig) | ||
} | ||
} | ||
``` | ||
|
||
```go | ||
qqclient.UseSig(sig) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# 事件 | ||
|
||
LagrangeGo使用的是事件订阅机制 | ||
|
||
方法签名: | ||
|
||
```go | ||
EventHandle[T].Subscribe(func(client *QQClient, event T)) | ||
``` | ||
|
||
示例 | ||
|
||
```go | ||
qqclient.GroupMessageEvent.Subscribe(func(client *client.QQClient, event *message.GroupMessage) { | ||
// 你可以从event中获取事件的各个参数 | ||
|
||
// 这段代码会将群聊收到的消息打印出来 | ||
fmt.Println(event.ToString()) | ||
}) | ||
``` | ||
|
||
目前支持的EventHandle | ||
|
||
| EventHandle[T] | 描述 | | ||
|:------------------------------------------------------------:|:--------:| | ||
| `EventHandle[*message.GroupMessage]` | 群聊消息事件 | | ||
| `PrivateMessageEvent[*message.PrivateMessage]` | 私聊消息事件 | | ||
| `TempMessageEvent[*message.TempMessage]` | 临时会话消息事件 | | ||
| `GroupInvitedEvent[*event.GroupInvite]` | 被邀请入群 | | ||
| `GroupMemberJoinRequestEvent[*event.GroupMemberJoinRequest]` | 加群申请 | | ||
| `GroupMemberJoinEvent[*event.GroupMemberIncrease]` | 成员入群 | | ||
| `GroupMemberLeaveEvent[*event.GroupMemberDecrease]` | 成员退群 | | ||
| `GroupMuteEvent[*event.GroupMute]` | 群聊禁言 | | ||
| `GroupRecallEvent[*event.GroupRecall]` | 群聊撤回消息 | | ||
| `FriendRequestEvent[*event.FriendRequest]` | 好友申请 | | ||
| `FriendRecallEvent[*event.FriendRecall]` | 好友消息撤回 | | ||
| `RenameEvent[*event.Rename]` | 昵称变动 | |
Oops, something went wrong.