Skip to content

Commit

Permalink
[Docs] Update Lagrange-Python (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
HornCopper authored Oct 9, 2024
1 parent 70d4b44 commit 464aea7
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 1 deletion.
23 changes: 23 additions & 0 deletions docs/.vitepress/catalogue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,26 @@ export const goSidebar = {
},
],
}

export const pythonSidebar = {
text: "lagrange-python",
base: "",
items: [
{
text: "lagrange-python",
link: "/lagrange-python/"
},
{
text: "登录",
items: [
{ text: "登录", link: "/lagrange-python/Login" }
]
},
{
text: "事件",
items: [
{ text: "事件", link: "/lagrange-python/Event" }
]
}
]
}
19 changes: 19 additions & 0 deletions docs/.vitepress/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,22 @@ export const goNav = {
},
],
}

export const pythonNav = {
text: "lagrange-python",
base: "",
items: [
{
text: "lagrange-python",
link: "/lagrange-python/",
},
{
text: "Bot 实例",
link: "/lagrange-python/CreateBot/",
},
{
text: "事件",
link: "/lagrange-python/Event/",
},
],
}
4 changes: 3 additions & 1 deletion docs/.vitepress/theme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DefaultTheme } from "vitepress"
import { coreSidebar, goSidebar, oneBotSidebar } from "./catalogue"
import { coreNav, goNav, oneBotNav } from "./nav"
import { coreNav, goNav, oneBotNav, pythonNav } from "./nav"

export const theme: DefaultTheme.Config = {
search: {
Expand All @@ -11,6 +11,7 @@ export const theme: DefaultTheme.Config = {
coreNav,
oneBotNav,
goNav,
pythonNav,
{
text: "GitHub",
items: [
Expand Down Expand Up @@ -41,6 +42,7 @@ export const theme: DefaultTheme.Config = {
"/Lagrange.Core/": coreSidebar,
"/Lagrange.OneBot/": oneBotSidebar,
"/LagrangeGo/": goSidebar,
"/lagrange-python/": pythonNav
} as DefaultTheme.SidebarMulti,
socialLinks: [
{ icon: "github", link: "https://github.com/LagrangeDev/Lagrange.Doc" },
Expand Down
6 changes: 6 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ hero:
link: ./Lagrange.OneBot/index
- text: 使用 LagrangeGo
link: ./LagrangeGo/index
- text: 使用 lagrange-python
link: ./lagrange-python/index
---

# 简介
Expand All @@ -32,3 +34,7 @@ Lagrange.Core 是一个开源的 NTQQ 协议实现, 当前处于稳定期, 免
### "喜欢更简易轻量的golang?"

前往 [LagrangeGo](LagrangeGo/index.md)

### "喜欢使用Python?"

前往 [lagrange-python](lagrange-python/index.md)
13 changes: 13 additions & 0 deletions docs/lagrange-python/CreateBot/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 创建 Bot 实例

首先从`lagrange`库直接导入`Lagrange`类,随后创建实例。

初始化参数中,`uin`可直接传入`0`(类型为`int`),`protocol`根据`sign_url`的类型而定,如果使用`Linux``Signer``protocol`请传入`linux`,以此类推。

`sign_url`需要传入一个实际可用的`Lagrange Sign`地址,注意本项目的`Sign`与其他`Lagrange`实现的同版本一致。

将初始化的类实例赋值给一个变量后,可使用实例方法订阅事件以及启动。调用该实例的`launch`方法即可启动`lagrange-python`

> 目前`lagrange-python`只支持扫码登录,如果扫码登录后出现`Code 45`,请检查`Sign`是否正常(连接状态?请求地址?协议版本?)。
初始化完毕后,可参考下一章节对具体的事件进行响应以及处理。
38 changes: 38 additions & 0 deletions docs/lagrange-python/Event/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 事件

`lagrange-python`采用事件订阅制。

`创建 Bot 实例`章节中,初始化的实例具有`subscribe`方法,可以使用该方法进行订阅事件。

**参数**

- event (*dataclass*): 订阅事件数据类,可参考下方事件列表。
- handler (*function*): 订阅事件的处理函数。

> `handler`函数需要传入一个`client`(类型为`lagrange.client.client.Client`)和需要处理的事件,事件可以有联合类型,但是订阅只可传入一种事件数据类。
## 事件列表

如果事件以`Friend``Private`开头,则通过`lagrange.client.events.friend`导入。

反之,如果以`Group`开头,则通过`lagrange.client.events.group`导入。

|事件名称|备注|
|-----|-----|
|`GroupMessage`|群消息|
|`GroupRecall`|群消息撤回|
|`GroupNudge`|群戳一戳|
|`GroupSign`|群打卡|
|`GroupMuteMember`|群禁言|
|`GroupMemberJoinRequest`|加群申请|
|`GroupMemberJoined`|群成员增加|
|`GroupMemberQuit`|群成员减少|
|`GroupMemberGotSpecialTitle`|群成员获得特殊头衔|
|`GroupNameChanged`|群名变动|
|`GroupReaction`|群消息回应|
|`GroupAlbumUpdate`|群相册更新(上传)|
|`GroupInvite`|邀请入群|
|`GroupMemberJoinedByInvite`|群成员邀请入群|
|`FriendMessage`|私聊消息|
|`FriendRecall`|私聊撤回|
|`FriendRequest`|好友申请|
15 changes: 15 additions & 0 deletions docs/lagrange-python/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# lagrange-python

## 快速开始

lagrange-python 有两种下载方式可供选择:

-`PyPI`拉取最新`Release`;
- 直接从[项目 GitHub 主页](https://github.com/LagrangeDev/lagrange-python)拉取最新`commit`

社区内也有基于纯协议进行开发的标准适配,如 [nekobox](https://github.com/wyapx/nekobox)(Satori)等。

步骤如下:

1. [创建 Bot 实例并登录](CreateBot/)
3. [订阅事件](Event/)

0 comments on commit 464aea7

Please sign in to comment.