Skip to content

Commit

Permalink
Merge pull request #18 from Redmomn/main
Browse files Browse the repository at this point in the history
docs: 迁移LagrangeGo文档
  • Loading branch information
pk5ls20 authored Oct 6, 2024
2 parents 351a02e + 36d6231 commit 0c02f13
Show file tree
Hide file tree
Showing 12 changed files with 492 additions and 6 deletions.
28 changes: 27 additions & 1 deletion docs/.vitepress/catalogue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const coreSidebar = {
},
{
text: "扩展",
link: "/Lagrange.Core/Login/Extern"
link: "/Lagrange.Core/Login/Extern",
},
],
},
Expand Down Expand Up @@ -223,3 +223,29 @@ export const oneBotSidebar = {
},
],
}

export const goSidebar = {
text: "LagrangeGo",
base: "",
items: [
{
text: "LagrangeGo",
link: "/LagrangeGo/",
},
{
text: "Bot实例",
items: [{ text: "创建bot实例", link: "/LagrangeGo/CreateBot/" }],
},
{
text: "登录",
items: [
{ text: "登录", link: "/LagrangeGo/Login/" },
{ text: "完整示例", link: "/LagrangeGo/Example/" },
],
},
{
text: "事件",
items: [{ text: "概述", link: "/LagrangeGo/Event/" }],
},
],
}
6 changes: 6 additions & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import type { DefaultTheme, UserConfig } from "vitepress"
import { defineConfig } from "vitepress"
import taskLists from "markdown-it-task-lists"
import { theme } from "./theme"

export default defineConfig({
title: "Lagrange 文档",
description: "Lagrange's document",
base: "/Lagrange.Doc/",
lang: "zh-CN",
markdown: {
config: (md) => {
md.use(taskLists)
},
},
cleanUrls: true,
lastUpdated: true,
themeConfig: theme,
Expand Down
19 changes: 19 additions & 0 deletions docs/.vitepress/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,22 @@ export const oneBotNav = {
},
],
}

export const goNav = {
text: "LagrangeGo",
base: "",
items: [
{
text: "LagrangeGo",
link: "/LagrangeGo/",
},
{
text: "Bot 实例",
link: "/LagrangeGo/CreateBot/",
},
{
text: "登录",
link: "/LagrangeGo/Login/",
},
],
}
11 changes: 6 additions & 5 deletions docs/.vitepress/theme.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { DefaultTheme } from "vitepress"
import { coreSidebar, oneBotSidebar } from "./catalogue"
import { coreNav, oneBotNav } from "./nav"
import { coreSidebar, goSidebar, oneBotSidebar } from "./catalogue"
import { coreNav, goNav, oneBotNav } from "./nav"

export const theme: DefaultTheme.Config = {
search: {
provider: 'local'
provider: "local",
},
nav: [
{ text: "首页", link: "/" },
coreNav,
oneBotNav,
goNav,
{
text: "GitHub",
items: [
Expand Down Expand Up @@ -39,13 +40,13 @@ export const theme: DefaultTheme.Config = {
sidebar: {
"/Lagrange.Core/": coreSidebar,
"/Lagrange.OneBot/": oneBotSidebar,
"/LagrangeGo/": goSidebar,
} as DefaultTheme.SidebarMulti,
socialLinks: [
{ icon: "github", link: "https://github.com/LagrangeDev/Lagrange.Doc" },
],
editLink: {
pattern:
"https://github.com/LagrangeDev/Lagrange.Doc/edit/main/docs/:path",
pattern: "https://github.com/LagrangeDev/Lagrange.Doc/edit/main/docs/:path",
text: "在 GitHub 上帮助我们完善这个页面",
},
docFooter: {
Expand Down
67 changes: 67 additions & 0 deletions docs/LagrangeGo/CreateBot/index.md
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)
```
37 changes: 37 additions & 0 deletions docs/LagrangeGo/Event/index.md
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]` | 昵称变动 |
Loading

0 comments on commit 0c02f13

Please sign in to comment.