Skymatrix-Server-IRC
大约 4 分钟模组定义Api
网络包定义
所有网络包都使用JSON格式发送,格式如下:
{
"type": "",
"action_id": "#1",
"data": {
}
}
你可以请求一个action_id如果这个包会有回复,则会返回先前设置的action_id
C2S
Header
在建立WebSocket连接时,请提供如下请求头:
{
"Authorization": "Bearer token",
"Client-Name": "clientName",
"Client-Api": "clientVersion"
}
Token 为Jwt payload包含以下内容 从Skymatrix-server获取:
{
"userid": "用户id",
"username": "用户名",
"client_name": "客户端名称",
"guest": "是否为访客"
}
Type: common:heartbeat
服务端总是会像你发送Heartbeat包,你需要回复一个Heartbeat包,否则服务器会主动断开连接。 例如服务器向你发送了一个flag为0的Heartbeat包,你需要回复一个flag为0+1的Heartbeat包。服务器会进行比对两者的flag差值超过10则会断开连接。
字段 | 类型 | 描述 |
---|---|---|
flag | int | 0+1 |
{
"type": "common:heartbeat",
"data": {
"flag": 0
}
}
Type: common:message
发送一个消息给服务器
字段 | 类型 | 描述 |
---|---|---|
message | string | 消息内容 |
channel | string | 频道 |
to | string | 接收者id如果为all表示群发 |
例如发送一个消息给频道default
的用户seiua
{
"type": "common:message",
"data": {
"message": "你好",
"channel": "default",
"to": "seiua"
}
}
Type: common:join_channel
切换频道
字段 | 类型 | 描述 |
---|---|---|
channel | string | 频道 |
例如加入到频道default
{
"type": "common:join_channel",
"data": {
"channel": "default"
}
}
Type: common:leave_channel
离开频道
字段 | 类型 | 描述 |
---|---|---|
channel | string | 频道 |
例如离开频道info
禁止频道为default
{
"type": "common:leave_channel",
"data": {
"channel": "info"
}
}
Type: common:create_channel
创建频道 如果你可以创建频道
字段 | 类型 | 描述 |
---|---|---|
channel | string | 频道名 |
例如创建一个频道test
{
"type": "common:create_channel",
"data": {
"channel": "test"
}
}
Type: common:delete_channel
删除频道 如果你可以删除频道
字段 | 类型 | 描述 |
---|---|---|
channel | string | 频道名 |
例如删除一个频道test
{
"type": "common:delete_channel",
"data": {
"channel": "test"
}
}
Type: common:update
更新信息 对应action:update的消息
字段 | 类型 | 描述 |
---|---|---|
type | string | info,channel,motd |
例如更新motd
{
"type": "common:update",
"data": {
"type": "motd"
}
}
例如更新频道列表
{
"type": "common:update",
"data": {
"type": "channel"
}
}
例如更新信息
{
"type": "common:update",
"data": {
"type": "info"
}
}
Type: admin:kick
踢出用户
字段 | 类型 | 描述 |
---|---|---|
userid | string | 用户id |
channel | string | 频道名字 为空踢出出服务器 不为空踢到default |
reason | string | 原因 |
例如踢出用户seiua
{
"type": "admin:kick",
"data": {
"userid": "seiua",
"channel": "",
"reason": ""
}
}
Type: admin:ban
封禁用户
字段 | 类型 | 描述 |
---|---|---|
userid | string | 用户id |
channel | string | 频道名字 禁止加入指定频道 为空禁止加入服务器 |
reason | string | 原因 |
time | int | 封禁时间 单位秒 0为永久 |
例如封禁用户seiua
{
"type": "admin:ban",
"data": {
"userid": "seiua",
"channel": "",
"reason": "",
"time": 0
}
}
Type: admin:unban
解封用户
字段 | 类型 | 描述 |
---|---|---|
userid | string | 用户id |
channel | string | 频道名字 |
例如解封用户seiua
{
"type": "admin:unban",
"data": {
"userid": "seiua",
"channel": "test"
}
}
Type: admin:join_channel
将用户加入频道
字段 | 类型 | 描述 |
---|---|---|
userid | string | 用户id |
channel | string | 频道 |
例如将用户seiua
加入到频道notification
{
"type": "admin:join_channel",
"data": {
"userid": "seiua",
"channel": "notification"
}
}
Type: admin:mute
禁言用户
字段 | 类型 | 描述 |
---|---|---|
userid | string | 用户id |
channel | string | 频道 |
time | int | 禁言时间 单位秒 0为永久 -1为unmute |
例如禁言用户seiua
{
"type": "admin:mute",
"data": {
"userid": "seiua",
"channel": "default",
"time": 0
}
}
S2C
Type: common:heartbeat
服务器端发送的心跳包
字段 | 类型 | 描述 |
---|---|---|
flag | int | 0 |
{
"type": "common:heartbeat",
"data": {
"flag": 0
}
}
Type: common:message
服务器端收到的消息转发给客户端
字段 | 类型 | 描述 |
---|---|---|
message | string | 消息内容 |
channel | string | 频道 |
from | string | 发送者id |
to | string | 接收者id |
prefix | string | 前缀 |
例如这是一个从服务器收到的消息
- 如果你没有加入default频道,你将不会收到这个消息
- 如果to为all,则表示这个消息是群发消息
- 如果to为你的id,则表示这个消息是私聊消息
{
"type": "common:message",
"data": {
"message": "你好",
"channel": "default",
"from": "seiua",
"to": "all",
"prefix": "admin"
}
}
Type: action:info
服务器通知客户端消息 可能是一些错误信息,或者一些提示信息
字段 | 类型 | 描述 |
---|---|---|
message | string | 消息内容 |
type | string | 消息类型 |
例如权限不足
{
"type": "action:info",
"data": {
"message": "permission denied",
"type": "fail"
}
}
例如频道不存在
{
"type": "action:info",
"data": {
"message": "channel not exist",
"type": "fail"
}
}
例如成功
{
"type": "action:info",
"action_id": "#1",
"data": {
"message": "success",
"type": "success"
}
}
例如你被踢出
{
"type": "action:info",
"action_id": "#1",
"data": {
"message": "you are kicked",
"type": "fail"
}
}
Type: action:update
服务器通知客户端更新信息
字段 | 类型 | 描述 |
---|---|---|
channels | array | 频道列表 |
your_channels | array | 你加入的频道列表 |
users | array | 在线用户列表 |
motd | string | 服务器公告 |
{
"type": "action:update",
"data": {
"motd": "hello",
"channels": [
"default",
"info"
] ,
"your_channels": [
"default"
],
"users": [
"seiua",
"admin"
]
}
}