mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-30 11:53:25 +00:00
Compare commits
60 Commits
v0.9.40-fi
...
release.0.
Author | SHA1 | Date | |
---|---|---|---|
4526e00d79 | |||
f6280baa0c | |||
8974adb009 | |||
2226be777a | |||
127d636b8a | |||
f1a480c01d | |||
2f227842f7 | |||
c24a2b327a | |||
5f247715b9 | |||
ae73451677 | |||
2aed5d5a16 | |||
190eb00143 | |||
84fef8f0c0 | |||
5049a8f697 | |||
c0260bc82d | |||
8185c4cdf1 | |||
0bcd16b252 | |||
b2738d909b | |||
95f2227898 | |||
cdb700c92f | |||
626de1cb17 | |||
bfc3958f34 | |||
9a2b69ccf0 | |||
5854f51506 | |||
cf5d3cef95 | |||
6864dc449b | |||
b781c3b43b | |||
e36a9a95c5 | |||
a639b60155 | |||
77e0363e32 | |||
5d0d8f3908 | |||
a90af94eda | |||
93da16897a | |||
604a05b625 | |||
af9e130273 | |||
3719ef1fe8 | |||
45102614b8 | |||
b385ed20b5 | |||
ca826f67b3 | |||
49a6cfd50a | |||
d2fb26da10 | |||
80517e25ad | |||
d4e2e2fb69 | |||
f86bb69536 | |||
a0d4dfd0eb | |||
8ef877777d | |||
b7991fc229 | |||
5b24492702 | |||
e88854a058 | |||
52a0061360 | |||
dd13fe6847 | |||
3bb3000e79 | |||
550e8d3531 | |||
42e5b0564c | |||
62024a4403 | |||
65112f8752 | |||
36c0aaae6b | |||
976f2233b4 | |||
f1a1b0ec30 | |||
3cc0453958 |
33
.github/ISSUE_TEMPLATE/bug--.md
vendored
33
.github/ISSUE_TEMPLATE/bug--.md
vendored
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: Bug汇报
|
name: Bug汇报
|
||||||
about: Create a report to help us improve
|
about: 遇到了bug? 你可以在这里开始汇报
|
||||||
title: ''
|
title: ''
|
||||||
labels: ''
|
labels: ''
|
||||||
assignees: ''
|
assignees: ''
|
||||||
@ -8,25 +8,34 @@ assignees: ''
|
|||||||
---
|
---
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
在提出ISSUE前,希望您能花费一定的时间执行以下几个步骤以方便我们定位BUG.
|
在您发布此Issue前, 请您花一点时间查看下面几条指引🔽
|
||||||
1: 确定没有相同问题的ISSUE已被提出.
|
|
||||||
2: 准确填写环境信息.
|
1: ❗ | 确定没有相同问题的ISSUE已被提出. (教程: https://github.com/Mrs4s/go-cqhttp/issues/633)
|
||||||
3: 最好能打开DEBUG模式并复现相关问题.
|
2: 🌎| 请准确填写环境信息.
|
||||||
4: 如果涉及内存泄漏/CPU占用异常请打开DEBUG模式并下载pprof性能分析.
|
3: ❔ | 打开DEBUG模式复现,并提供出现问题前后至少 10 秒的完整日志内容。请自行删除日志内存在的个人信息及敏感内容。
|
||||||
注: 如果您不知道如何有效、精准地表述,我们建议您先阅读《提问的智慧》 -> https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md
|
4: ⚠ | 如果涉及内存泄漏/CPU占用异常请打开DEBUG模式并下载pprof性能分析.
|
||||||
|
|
||||||
|
注: 如果您不知道如何有效、精准地表述,我们建议您先阅读《提问的智慧》
|
||||||
|
(链接: https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md)
|
||||||
|
|
||||||
|
请确保您已经仔细阅读此教程,并勾选下方的确认框。(将 [ ] 修改为 [x])
|
||||||
|
--------
|
||||||
|
- [ ] 我已经仔细阅读上述教程和"提问前需知 [图+文]": https://github.com/Mrs4s/go-cqhttp/issues/633
|
||||||
|
- [ ] 我已知晓并同意,如果我不遵循以下格式提交 Issue,或者我使用的并非最新版本,或者我没有提供足够的环境信息,则我的 Issue 可能会被无条件自动关闭和锁定。
|
||||||
|
- [ ] 我已知晓并同意,我仅需要把选项前的 [ ] 替换为 [x]。如果我删除、修改这些复选框的其他部分,或是在 x 之前或之后留了空格,则我的 Issue 可能会被无条件自动关闭和锁定。
|
||||||
|
- [ ] 我已知晓并同意,此处仅用于汇报程序中存在的问题。若这个 Issue 是关于其他非程序本身问题或是新功能需求,则我的 Issue 可能会被无条件自动关闭和锁定。(这些问题应当在 Discussion 板块提出。)
|
||||||
|
--------
|
||||||
-->
|
-->
|
||||||
|
|
||||||
- [ ] 我已经阅读"提问前需知 [图+文]": `Mrs4s/go-cqhttp/issues/633`
|
|
||||||
|
|
||||||
**环境信息**
|
**环境信息**
|
||||||
请根据实际使用环境修改以下信息
|
<!-- 请根据实际使用环境修改以下信息。请勿留空。 -->
|
||||||
go-cqhttp版本:
|
go-cqhttp版本:
|
||||||
运行环境:
|
运行环境:
|
||||||
连接方式:
|
连接方式:
|
||||||
使用协议:
|
使用协议:
|
||||||
|
|
||||||
**bug内容**
|
**bug内容**
|
||||||
请在这里详细描述bug的内容
|
<!-- 请在这里详细描述bug的内容 -->
|
||||||
|
|
||||||
**复现方法**
|
**复现方法**
|
||||||
请在这里分步骤的描述如何复现这个bug
|
<!-- 请在这里分步骤的描述如何复现这个bug -->
|
||||||
|
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: 提出新建议/功能
|
||||||
|
url: https://github.com/Mrs4s/go-cqhttp/discussions/new
|
||||||
|
about: 请在这里提出你的建议或功能
|
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -41,7 +41,7 @@ jobs:
|
|||||||
if $IS_PR ; then echo $PR_PROMPT; fi
|
if $IS_PR ; then echo $PR_PROMPT; fi
|
||||||
export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX"
|
export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX"
|
||||||
export CGO_ENABLED=0
|
export CGO_ENABLED=0
|
||||||
go build -o "output/$BINARY_NAME" -ldflags "$LD_FLAGS" .
|
go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" .
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
if: ${{ !github.head_ref }}
|
if: ${{ !github.head_ref }}
|
||||||
|
12
.github/workflows/issuebot.yml
vendored
Normal file
12
.github/workflows/issuebot.yml
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
name: Issuebot
|
||||||
|
|
||||||
|
on:
|
||||||
|
issues:
|
||||||
|
types: [opened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
new_issue:
|
||||||
|
name: Run Issuebot on new Issue
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: wfjsw/actions-gocqhttp-issue-prefilter@master
|
49
.github/workflows/release.yml
vendored
49
.github/workflows/release.yml
vendored
@ -1,35 +1,28 @@
|
|||||||
|
name: release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
push:
|
||||||
types: [created]
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
releases-matrix:
|
goreleaser:
|
||||||
name: Release Go Binary
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/386, darwin/amd64, darwin/arm64
|
|
||||||
goos: [linux, windows, darwin]
|
|
||||||
goarch: ["386", amd64, arm, arm64]
|
|
||||||
exclude:
|
|
||||||
- goos: darwin
|
|
||||||
goarch: arm
|
|
||||||
- goos: darwin
|
|
||||||
goarch: "386"
|
|
||||||
- goos: windows
|
|
||||||
goarch: arm64
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- name: Checkout
|
||||||
- name: Set RELEASE_VERSION env
|
uses: actions/checkout@v2.3.4
|
||||||
run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV
|
|
||||||
- uses: pcrbot/go-release-action@master
|
|
||||||
env:
|
|
||||||
CGO_ENABLED: 0
|
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
fetch-depth: 0
|
||||||
goos: ${{ matrix.goos }}
|
|
||||||
goarch: ${{ matrix.goarch }}
|
|
||||||
goversion: "https://golang.org/dl/go1.16.linux-amd64.tar.gz"
|
|
||||||
ldflags: -w -s -X "github.com/Mrs4s/go-cqhttp/coolq.Version=${{ env.RELEASE_VERSION }}"
|
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: '1.16.2'
|
||||||
|
|
||||||
|
- name: Run GoReleaser
|
||||||
|
uses: goreleaser/goreleaser-action@v2
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
args: release --rm-dist
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
85
.goreleaser.yml
Normal file
85
.goreleaser.yml
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
env:
|
||||||
|
- GO111MODULE=on
|
||||||
|
before:
|
||||||
|
hooks:
|
||||||
|
- go mod tidy
|
||||||
|
builds:
|
||||||
|
- id: nowin
|
||||||
|
env:
|
||||||
|
- CGO_ENABLED=0
|
||||||
|
- GO111MODULE=on
|
||||||
|
goos:
|
||||||
|
- linux
|
||||||
|
- darwin
|
||||||
|
goarch:
|
||||||
|
- 386
|
||||||
|
- amd64
|
||||||
|
- arm
|
||||||
|
- arm64
|
||||||
|
ignore:
|
||||||
|
- goos: darwin
|
||||||
|
goarch: arm
|
||||||
|
- goos: darwin
|
||||||
|
goarch: 386
|
||||||
|
mod_timestamp: "{{ .CommitTimestamp }}"
|
||||||
|
flags:
|
||||||
|
- -trimpath
|
||||||
|
ldflags:
|
||||||
|
- -s -w -X github.com/Mrs4s/go-cqhttp/coolq.Version=v{{.Version}}
|
||||||
|
- id: win
|
||||||
|
env:
|
||||||
|
- CGO_ENABLED=0
|
||||||
|
- GO111MODULE=on
|
||||||
|
goos:
|
||||||
|
- windows
|
||||||
|
goarch:
|
||||||
|
- 386
|
||||||
|
- amd64
|
||||||
|
- arm
|
||||||
|
goarm:
|
||||||
|
- 7
|
||||||
|
mod_timestamp: "{{ .CommitTimestamp }}"
|
||||||
|
flags:
|
||||||
|
- -trimpath
|
||||||
|
ldflags:
|
||||||
|
- -s -w -X github.com/Mrs4s/go-cqhttp/coolq.Version=v{{.Version}}
|
||||||
|
|
||||||
|
checksum:
|
||||||
|
name_template: "{{ .ProjectName }}_checksums.txt"
|
||||||
|
changelog:
|
||||||
|
sort: asc
|
||||||
|
filters:
|
||||||
|
exclude:
|
||||||
|
- "^docs:"
|
||||||
|
- "^test:"
|
||||||
|
- fix typo
|
||||||
|
- Merge pull request
|
||||||
|
- Merge branch
|
||||||
|
- Merge remote-tracking
|
||||||
|
- go mod tidy
|
||||||
|
|
||||||
|
archives:
|
||||||
|
- id: binary
|
||||||
|
builds:
|
||||||
|
- win
|
||||||
|
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
|
||||||
|
format_overrides:
|
||||||
|
- goos: windows
|
||||||
|
format: binary
|
||||||
|
- id: nowin
|
||||||
|
builds:
|
||||||
|
- nowin
|
||||||
|
- win
|
||||||
|
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
|
||||||
|
format_overrides:
|
||||||
|
- goos: windows
|
||||||
|
format: zip
|
||||||
|
|
||||||
|
nfpms:
|
||||||
|
- license: AGPL 3.0
|
||||||
|
homepage: https://go-cqhttp.org
|
||||||
|
file_name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
|
||||||
|
formats:
|
||||||
|
- deb
|
||||||
|
- rpm
|
||||||
|
maintainer: Mrs4s
|
@ -279,4 +279,4 @@ go-cqhttp兼容[OneBot-v11](https://github.com/howmanybots/onebot/tree/master/v1
|
|||||||
|
|
||||||
## 性能
|
## 性能
|
||||||
|
|
||||||
在关闭数据库的情况下, 加载 25 个好友 128 个群运行 24 小时后内存使用为 10MB 左右. 开启数据库后内存使用将根据消息量增加 10-20MB, 如果系统内存小于 128M 建议关闭数据库使用.
|
在关闭数据库的情况下, 加载 25 个好友 128 个群运行 24 小时后内存使用为 15MB 左右. 开启数据库后内存使用将根据消息量增加 10-20MB, 如果系统内存小于 128M 建议关闭数据库使用.
|
||||||
|
64
coolq/api.go
64
coolq/api.go
@ -4,27 +4,41 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Mrs4s/MiraiGo/binary"
|
|
||||||
"github.com/Mrs4s/MiraiGo/client"
|
|
||||||
"github.com/Mrs4s/MiraiGo/message"
|
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/debug"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"github.com/Mrs4s/MiraiGo/binary"
|
||||||
|
"github.com/Mrs4s/MiraiGo/client"
|
||||||
|
"github.com/Mrs4s/MiraiGo/message"
|
||||||
|
"github.com/Mrs4s/MiraiGo/utils"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version go-cqhttp的版本信息,在编译时使用ldfalgs进行覆盖
|
// Version go-cqhttp的版本信息,在编译时使用ldflags进行覆盖
|
||||||
var Version = "unknown"
|
var Version = "unknown"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if Version != "unknown" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
info, ok := debug.ReadBuildInfo()
|
||||||
|
if ok {
|
||||||
|
Version = info.Main.Version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CQGetLoginInfo 获取登录号信息
|
// CQGetLoginInfo 获取登录号信息
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1I
|
// https://git.io/Jtz1I
|
||||||
@ -423,9 +437,13 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
|
|||||||
sendNodes = convert(m)
|
sendNodes = convert(m)
|
||||||
}
|
}
|
||||||
if len(sendNodes) > 0 {
|
if len(sendNodes) > 0 {
|
||||||
gm := bot.Client.SendGroupForwardMessage(groupID, &message.ForwardMessage{Nodes: sendNodes})
|
ret := bot.Client.SendGroupForwardMessage(groupID, &message.ForwardMessage{Nodes: sendNodes})
|
||||||
|
if ret == nil || ret.Id == -1 {
|
||||||
|
log.Warnf("合并转发(群)消息发送失败: 账号可能被风控.")
|
||||||
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||||
|
}
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
"message_id": bot.InsertGroupMessage(gm),
|
"message_id": bot.InsertGroupMessage(ret),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
@ -434,12 +452,12 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
|
|||||||
// CQSendPrivateMessage 发送私聊消息
|
// CQSendPrivateMessage 发送私聊消息
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1l
|
// https://git.io/Jtz1l
|
||||||
func (bot *CQBot) CQSendPrivateMessage(userID int64, i interface{}, autoEscape bool) MSG {
|
func (bot *CQBot) CQSendPrivateMessage(userID int64, groupId int64, i interface{}, autoEscape bool) MSG {
|
||||||
var str string
|
var str string
|
||||||
if m, ok := i.(gjson.Result); ok {
|
if m, ok := i.(gjson.Result); ok {
|
||||||
if m.Type == gjson.JSON {
|
if m.Type == gjson.JSON {
|
||||||
elem := bot.ConvertObjectMessage(m, false)
|
elem := bot.ConvertObjectMessage(m, false)
|
||||||
mid := bot.SendPrivateMessage(userID, &message.SendingMessage{Elements: elem})
|
mid := bot.SendPrivateMessage(userID, groupId, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||||
}
|
}
|
||||||
@ -464,7 +482,7 @@ func (bot *CQBot) CQSendPrivateMessage(userID int64, i interface{}, autoEscape b
|
|||||||
} else {
|
} else {
|
||||||
elem = bot.ConvertStringMessage(str, false)
|
elem = bot.ConvertStringMessage(str, false)
|
||||||
}
|
}
|
||||||
mid := bot.SendPrivateMessage(userID, &message.SendingMessage{Elements: elem})
|
mid := bot.SendPrivateMessage(userID, groupId, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||||
}
|
}
|
||||||
@ -547,7 +565,7 @@ func (bot *CQBot) CQSetGroupBan(groupID, userID int64, duration uint32) MSG {
|
|||||||
if m := g.FindMember(userID); m != nil {
|
if m := g.FindMember(userID); m != nil {
|
||||||
err := m.Mute(duration)
|
err := m.Mute(duration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if duration >= 2592000 {
|
if duration > 2592000 {
|
||||||
return Failed(100, "DURATION_IS_NOT_IN_RANGE", "非法的禁言时长")
|
return Failed(100, "DURATION_IS_NOT_IN_RANGE", "非法的禁言时长")
|
||||||
}
|
}
|
||||||
return Failed(100, "NOT_MANAGEABLE", "机器人权限不足")
|
return Failed(100, "NOT_MANAGEABLE", "机器人权限不足")
|
||||||
@ -663,6 +681,11 @@ func (bot *CQBot) CQDeleteMessage(messageID int32) MSG {
|
|||||||
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
|
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
|
||||||
}
|
}
|
||||||
if _, ok := msg["group"]; ok {
|
if _, ok := msg["group"]; ok {
|
||||||
|
if msg["internal-id"] == nil {
|
||||||
|
// TODO 撤回临时对话消息
|
||||||
|
log.Warnf("撤回 %v 失败: 无法撤回临时对话消息", messageID)
|
||||||
|
return Failed(100, "CANNOT_RECALL_TEMP_MSG", "无法撤回临时对话消息")
|
||||||
|
}
|
||||||
if err := bot.Client.RecallGroupMessage(msg["group"].(int64), msg["message-id"].(int32), msg["internal-id"].(int32)); err != nil {
|
if err := bot.Client.RecallGroupMessage(msg["group"].(int64), msg["message-id"].(int32), msg["internal-id"].(int32)); err != nil {
|
||||||
log.Warnf("撤回 %v 失败: %v", messageID, err)
|
log.Warnf("撤回 %v 失败: %v", messageID, err)
|
||||||
return Failed(100, "RECALL_API_ERROR", err.Error())
|
return Failed(100, "RECALL_API_ERROR", err.Error())
|
||||||
@ -822,9 +845,9 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
|||||||
if reply.Exists() {
|
if reply.Exists() {
|
||||||
autoEscape := global.EnsureBool(operation.Get("auto_escape"), false)
|
autoEscape := global.EnsureBool(operation.Get("auto_escape"), false)
|
||||||
|
|
||||||
at := !isAnonymous // 除匿名消息场合外默认 true
|
at := !isAnonymous && msgType == "group" // 除匿名消息场合外默认 true
|
||||||
if operation.Get("at_sender").Exists() {
|
if operation.Get("at_sender").Exists() {
|
||||||
at = operation.Get("at_sender").Bool() && !isAnonymous
|
at = operation.Get("at_sender").Bool() && !isAnonymous && msgType == "group"
|
||||||
}
|
}
|
||||||
|
|
||||||
if at && reply.IsArray() {
|
if at && reply.IsArray() {
|
||||||
@ -865,7 +888,7 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
|||||||
bot.CQSendGroupMessage(context.Get("group_id").Int(), reply, autoEscape)
|
bot.CQSendGroupMessage(context.Get("group_id").Int(), reply, autoEscape)
|
||||||
}
|
}
|
||||||
if msgType == "private" {
|
if msgType == "private" {
|
||||||
bot.CQSendPrivateMessage(context.Get("user_id").Int(), reply, autoEscape)
|
bot.CQSendPrivateMessage(context.Get("user_id").Int(), context.Get("group_id").Int(), reply, autoEscape)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if msgType == "group" {
|
if msgType == "group" {
|
||||||
@ -1345,10 +1368,15 @@ func convertGroupMemberInfo(groupID int64, m *client.GroupMemberInfo) MSG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func limitedString(str string) string {
|
func limitedString(str string) string {
|
||||||
if strings.Count(str, "") <= 10 {
|
if utf8.RuneCountInString(str) <= 10 {
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
limited := []rune(str)
|
b := utils.S2B(str)
|
||||||
limited = limited[:10]
|
limited := make([]rune, 0, 10)
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
decodeRune, size := utf8.DecodeRune(b)
|
||||||
|
b = b[size:]
|
||||||
|
limited = append(limited, decodeRune)
|
||||||
|
}
|
||||||
return string(limited) + " ..."
|
return string(limited) + " ..."
|
||||||
}
|
}
|
||||||
|
69
coolq/bot.go
69
coolq/bot.go
@ -17,10 +17,11 @@ import (
|
|||||||
"github.com/Mrs4s/MiraiGo/client"
|
"github.com/Mrs4s/MiraiGo/client"
|
||||||
"github.com/Mrs4s/MiraiGo/message"
|
"github.com/Mrs4s/MiraiGo/message"
|
||||||
"github.com/Mrs4s/MiraiGo/utils"
|
"github.com/Mrs4s/MiraiGo/utils"
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
|
|
||||||
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
)
|
)
|
||||||
|
|
||||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
@ -61,7 +62,9 @@ func NewQQBot(cli *client.QQClient, conf *global.JSONConfig) *CQBot {
|
|||||||
}
|
}
|
||||||
bot.Client.OnPrivateMessage(bot.privateMessageEvent)
|
bot.Client.OnPrivateMessage(bot.privateMessageEvent)
|
||||||
bot.Client.OnGroupMessage(bot.groupMessageEvent)
|
bot.Client.OnGroupMessage(bot.groupMessageEvent)
|
||||||
|
if conf.EnableSelfMessage {
|
||||||
bot.Client.OnSelfGroupMessage(bot.groupMessageEvent)
|
bot.Client.OnSelfGroupMessage(bot.groupMessageEvent)
|
||||||
|
}
|
||||||
bot.Client.OnTempMessage(bot.tempMessageEvent)
|
bot.Client.OnTempMessage(bot.tempMessageEvent)
|
||||||
bot.Client.OnGroupMuted(bot.groupMutedEvent)
|
bot.Client.OnGroupMuted(bot.groupMutedEvent)
|
||||||
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
|
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
|
||||||
@ -240,7 +243,7 @@ func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) int
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SendPrivateMessage 发送私聊消息
|
// SendPrivateMessage 发送私聊消息
|
||||||
func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) int32 {
|
func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.SendingMessage) int32 {
|
||||||
var newElem []message.IMessageElement
|
var newElem []message.IMessageElement
|
||||||
for _, elem := range m.Elements {
|
for _, elem := range m.Elements {
|
||||||
if i, ok := elem.(*LocalImageElement); ok {
|
if i, ok := elem.(*LocalImageElement); ok {
|
||||||
@ -257,7 +260,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
if i, ok := elem.(*message.VoiceElement); ok {
|
if i, ok := elem.(*message.VoiceElement); ok {
|
||||||
fv, err := bot.Client.UploadPrivatePtt(target, i.Data)
|
fv, err := bot.Client.UploadPrivatePtt(target, bytes.NewReader(i.Data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告: 私聊 %v 消息语音上传失败: %v", target, err)
|
log.Warnf("警告: 私聊 %v 消息语音上传失败: %v", target, err)
|
||||||
continue
|
continue
|
||||||
@ -292,16 +295,37 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in
|
|||||||
if msg != nil {
|
if msg != nil {
|
||||||
id = bot.InsertPrivateMessage(msg)
|
id = bot.InsertPrivateMessage(msg)
|
||||||
}
|
}
|
||||||
} else if code, ok := bot.tempMsgCache.Load(target); ok { // 临时会话
|
} else if code, ok := bot.tempMsgCache.Load(target); ok || groupID != 0 { // 临时会话
|
||||||
msg := bot.Client.SendTempMessage(code.(int64), target, m)
|
switch {
|
||||||
|
case groupID != 0 && bot.Client.FindGroup(groupID) == nil:
|
||||||
|
log.Errorf("错误: 找不到群(%v)", groupID)
|
||||||
|
id = -1
|
||||||
|
case groupID != 0 && !bot.Client.FindGroup(groupID).AdministratorOrOwner():
|
||||||
|
log.Errorf("错误: 机器人在群(%v) 为非管理员或群主, 无法主动发起临时会话", groupID)
|
||||||
|
id = -1
|
||||||
|
case groupID != 0 && bot.Client.FindGroup(groupID).FindMember(target) == nil:
|
||||||
|
log.Errorf("错误: 群员(%v) 不在 群(%v), 无法发起临时会话", target, groupID)
|
||||||
|
id = -1
|
||||||
|
default:
|
||||||
|
if code != nil && groupID == 0 {
|
||||||
|
groupID = code.(int64)
|
||||||
|
}
|
||||||
|
msg := bot.Client.SendGroupTempMessage(groupID, target, m)
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
id = msg.Id
|
id = bot.InsertTempMessage(target, msg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if _, ok := bot.oneWayMsgCache.Load(target); ok { // 单向好友
|
} else if _, ok := bot.oneWayMsgCache.Load(target); ok { // 单向好友
|
||||||
msg := bot.Client.SendPrivateMessage(target, m)
|
msg := bot.Client.SendPrivateMessage(target, m)
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
id = bot.InsertPrivateMessage(msg)
|
id = bot.InsertPrivateMessage(msg)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
nickname := "Unknown"
|
||||||
|
if summaryInfo, _ := bot.Client.GetSummaryInfo(target); summaryInfo != nil {
|
||||||
|
nickname = summaryInfo.Nickname
|
||||||
|
}
|
||||||
|
log.Errorf("错误: 请先添加 %v(%v) 为好友", nickname, target)
|
||||||
}
|
}
|
||||||
if id == -1 {
|
if id == -1 {
|
||||||
return -1
|
return -1
|
||||||
@ -360,6 +384,33 @@ func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 {
|
|||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InsertTempMessage 临时消息入数据库
|
||||||
|
func (bot *CQBot) InsertTempMessage(target int64, m *message.TempMessage) int32 {
|
||||||
|
val := MSG{
|
||||||
|
"message-id": m.Id,
|
||||||
|
// FIXME(InsertTempMessage) InternalId missing
|
||||||
|
"group": m.GroupCode,
|
||||||
|
"group-name": m.GroupName,
|
||||||
|
"target": target,
|
||||||
|
"sender": m.Sender,
|
||||||
|
"time": time.Now().Unix(),
|
||||||
|
"message": ToStringMessage(m.Elements, m.Sender.Uin, true),
|
||||||
|
}
|
||||||
|
id := toGlobalID(m.Sender.Uin, m.Id)
|
||||||
|
if bot.db != nil {
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
if err := gob.NewEncoder(buf).Encode(val); err != nil {
|
||||||
|
log.Warnf("记录聊天数据时出现错误: %v", err)
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if err := bot.db.Put(binary.ToBytes(id), binary.GZipCompress(buf.Bytes()), nil); err != nil {
|
||||||
|
log.Warnf("记录聊天数据时出现错误: %v", err)
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
// toGlobalID 构建`code`-`msgID`的字符串并返回其CRC32 Checksum的值
|
// toGlobalID 构建`code`-`msgID`的字符串并返回其CRC32 Checksum的值
|
||||||
func toGlobalID(code int64, msgID int32) int32 {
|
func toGlobalID(code int64, msgID int32) int32 {
|
||||||
return int32(crc32.ChecksumIEEE([]byte(fmt.Sprintf("%d-%d", code, msgID))))
|
return int32(crc32.ChecksumIEEE([]byte(fmt.Sprintf("%d-%d", code, msgID))))
|
||||||
@ -438,12 +489,12 @@ func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) MSG {
|
|||||||
t, err := bot.Client.GetGroupMembers(group)
|
t, err := bot.Client.GetGroupMembers(group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("刷新群 %v 成员列表失败: %v", group.Uin, err)
|
log.Warnf("刷新群 %v 成员列表失败: %v", group.Uin, err)
|
||||||
return Failed(100, "GET_MEMBERS_API_ERROR", err.Error())
|
return nil
|
||||||
}
|
}
|
||||||
group.Members = t
|
group.Members = t
|
||||||
mem = group.FindMember(m.Sender.Uin)
|
mem = group.FindMember(m.Sender.Uin)
|
||||||
if mem != nil {
|
if mem == nil {
|
||||||
return Failed(100, "MEMBER_NOT_FOUND", "群员不存在")
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ms := gm["sender"].(MSG)
|
ms := gm["sender"].(MSG)
|
||||||
|
251
coolq/cqcode.go
251
coolq/cqcode.go
@ -10,22 +10,25 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
"github.com/Mrs4s/MiraiGo/binary"
|
"github.com/Mrs4s/MiraiGo/binary"
|
||||||
"github.com/Mrs4s/MiraiGo/message"
|
"github.com/Mrs4s/MiraiGo/message"
|
||||||
"github.com/Mrs4s/MiraiGo/utils"
|
"github.com/Mrs4s/MiraiGo/utils"
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
|
"github.com/Mrs4s/go-cqhttp/global/codec"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -40,6 +43,19 @@ var IgnoreInvalidCQCode = false
|
|||||||
// SplitURL 是否分割URL
|
// SplitURL 是否分割URL
|
||||||
var SplitURL = false
|
var SplitURL = false
|
||||||
|
|
||||||
|
// magicCQ 代表 uint32([]byte("[CQ:"))
|
||||||
|
var magicCQ = uint32(0)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
var CQHeader = "[CQ:"
|
||||||
|
magicCQ = *(*uint32)(unsafe.Pointer((*reflect.StringHeader)(unsafe.Pointer(&CQHeader)).Data))
|
||||||
|
}
|
||||||
|
|
||||||
|
// add 指针运算
|
||||||
|
func add(ptr unsafe.Pointer, offset uintptr) unsafe.Pointer {
|
||||||
|
return unsafe.Pointer(uintptr(ptr) + offset)
|
||||||
|
}
|
||||||
|
|
||||||
const maxImageSize = 1024 * 1024 * 30 // 30MB
|
const maxImageSize = 1024 * 1024 * 30 // 30MB
|
||||||
const maxVideoSize = 1024 * 1024 * 100 // 100MB
|
const maxVideoSize = 1024 * 1024 * 100 // 100MB
|
||||||
// PokeElement 拍一拍
|
// PokeElement 拍一拍
|
||||||
@ -210,7 +226,7 @@ func ToArrayMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r []M
|
|||||||
} else {
|
} else {
|
||||||
m = MSG{
|
m = MSG{
|
||||||
"type": "image",
|
"type": "image",
|
||||||
"data": map[string]string{"file": hex.EncodeToString(o.Md5) + ".image", "url": CQCodeEscapeText(o.Url)},
|
"data": map[string]string{"file": hex.EncodeToString(o.Md5) + ".image", "url": o.Url},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case *message.FriendImageElement:
|
case *message.FriendImageElement:
|
||||||
@ -222,7 +238,7 @@ func ToArrayMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r []M
|
|||||||
} else {
|
} else {
|
||||||
m = MSG{
|
m = MSG{
|
||||||
"type": "image",
|
"type": "image",
|
||||||
"data": map[string]string{"file": hex.EncodeToString(o.Md5) + ".image", "url": CQCodeEscapeText(o.Url)},
|
"data": map[string]string{"file": hex.EncodeToString(o.Md5) + ".image", "url": o.Url},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case *message.GroupFlashImgElement:
|
case *message.GroupFlashImgElement:
|
||||||
@ -308,13 +324,13 @@ func ToStringMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r st
|
|||||||
if ur {
|
if ur {
|
||||||
r += fmt.Sprintf("[CQ:image,file=%s]", hex.EncodeToString(o.Md5)+".image")
|
r += fmt.Sprintf("[CQ:image,file=%s]", hex.EncodeToString(o.Md5)+".image")
|
||||||
} else {
|
} else {
|
||||||
r += fmt.Sprintf("[CQ:image,file=%s,url=%s]", hex.EncodeToString(o.Md5)+".image", CQCodeEscapeText(o.Url))
|
r += fmt.Sprintf("[CQ:image,file=%s,url=%s]", hex.EncodeToString(o.Md5)+".image", CQCodeEscapeValue(o.Url))
|
||||||
}
|
}
|
||||||
case *message.FriendImageElement:
|
case *message.FriendImageElement:
|
||||||
if ur {
|
if ur {
|
||||||
r += fmt.Sprintf("[CQ:image,file=%s]", hex.EncodeToString(o.Md5)+".image")
|
r += fmt.Sprintf("[CQ:image,file=%s]", hex.EncodeToString(o.Md5)+".image")
|
||||||
} else {
|
} else {
|
||||||
r += fmt.Sprintf("[CQ:image,file=%s,url=%s]", hex.EncodeToString(o.Md5)+".image", CQCodeEscapeText(o.Url))
|
r += fmt.Sprintf("[CQ:image,file=%s,url=%s]", hex.EncodeToString(o.Md5)+".image", CQCodeEscapeValue(o.Url))
|
||||||
}
|
}
|
||||||
case *message.GroupFlashImgElement:
|
case *message.GroupFlashImgElement:
|
||||||
return fmt.Sprintf("[CQ:image,type=flash,file=%s]", o.Filename)
|
return fmt.Sprintf("[CQ:image,type=flash,file=%s]", o.Filename)
|
||||||
@ -335,66 +351,14 @@ func ToStringMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ConvertStringMessage 将消息字符串转为消息元素数组
|
// ConvertStringMessage 将消息字符串转为消息元素数组
|
||||||
func (bot *CQBot) ConvertStringMessage(msg string, isGroup bool) (r []message.IMessageElement) {
|
func (bot *CQBot) ConvertStringMessage(s string, isGroup bool) (r []message.IMessageElement) {
|
||||||
index := 0
|
var t, key string
|
||||||
stat := 0
|
var d = map[string]string{}
|
||||||
rMsg := []rune(msg)
|
ptr := unsafe.Pointer((*reflect.StringHeader)(unsafe.Pointer(&s)).Data)
|
||||||
var tempText, cqCode []rune
|
l := len(s)
|
||||||
hasNext := func() bool {
|
i, j, CQBegin := 0, 0, 0
|
||||||
return index < len(rMsg)
|
|
||||||
}
|
|
||||||
next := func() rune {
|
|
||||||
r := rMsg[index]
|
|
||||||
index++
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
move := func(steps int) {
|
|
||||||
index += steps
|
|
||||||
}
|
|
||||||
peekN := func(count int) string {
|
|
||||||
lastIdx := int(math.Min(float64(index+count), float64(len(rMsg))))
|
|
||||||
return string(rMsg[index:lastIdx])
|
|
||||||
}
|
|
||||||
isCQCodeBegin := func(r rune) bool {
|
|
||||||
return r == '[' && peekN(3) == "CQ:"
|
|
||||||
}
|
|
||||||
saveTempText := func() {
|
|
||||||
if len(tempText) != 0 {
|
|
||||||
if SplitURL {
|
|
||||||
for _, t := range global.SplitURL(CQCodeUnescapeText(string(tempText))) {
|
|
||||||
r = append(r, message.NewText(t))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
r = append(r, message.NewText(CQCodeUnescapeText(string(tempText))))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tempText = []rune{}
|
|
||||||
cqCode = []rune{}
|
|
||||||
}
|
|
||||||
saveCQCode := func() {
|
saveCQCode := func() {
|
||||||
defer func() {
|
|
||||||
cqCode = []rune{}
|
|
||||||
tempText = []rune{}
|
|
||||||
}()
|
|
||||||
s := strings.SplitN(string(cqCode), ",", -1)
|
|
||||||
if len(s) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
t := s[0]
|
|
||||||
params := make(map[string]string)
|
|
||||||
for i := 1; i < len(s); i++ {
|
|
||||||
p := s[i]
|
|
||||||
p = strings.TrimSpace(p)
|
|
||||||
if p == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
data := strings.SplitN(p, "=", 2)
|
|
||||||
if len(data) == 2 {
|
|
||||||
params[data[0]] = CQCodeUnescapeValue(data[1])
|
|
||||||
} else {
|
|
||||||
params[p] = ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if t == "reply" { // reply 特殊处理
|
if t == "reply" { // reply 特殊处理
|
||||||
if len(r) > 0 {
|
if len(r) > 0 {
|
||||||
if _, ok := r[0].(*message.ReplyElement); ok {
|
if _, ok := r[0].(*message.ReplyElement); ok {
|
||||||
@ -402,8 +366,8 @@ func (bot *CQBot) ConvertStringMessage(msg string, isGroup bool) (r []message.IM
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mid, err := strconv.Atoi(params["id"])
|
mid, err := strconv.Atoi(d["id"])
|
||||||
customText := params["text"]
|
customText := d["text"]
|
||||||
if err == nil {
|
if err == nil {
|
||||||
org := bot.GetMessage(int32(mid))
|
org := bot.GetMessage(int32(mid))
|
||||||
if org != nil {
|
if org != nil {
|
||||||
@ -418,18 +382,19 @@ func (bot *CQBot) ConvertStringMessage(msg string, isGroup bool) (r []message.IM
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if customText != "" {
|
} else if customText != "" {
|
||||||
sender, err := strconv.ParseInt(params["qq"], 10, 64)
|
sender, err := strconv.ParseInt(d["qq"], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告:自定义 Reply 元素中必须包含Uin")
|
log.Warnf("警告:自定义 Reply 元素中必须包含 Uin")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
msgTime, err := strconv.ParseInt(params["time"], 10, 64)
|
msgTime, err := strconv.ParseInt(d["time"], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msgTime = time.Now().Unix()
|
msgTime = time.Now().Unix()
|
||||||
}
|
}
|
||||||
|
messageSeq, _ := strconv.ParseInt(d["seq"], 10, 64)
|
||||||
r = append([]message.IMessageElement{
|
r = append([]message.IMessageElement{
|
||||||
&message.ReplyElement{
|
&message.ReplyElement{
|
||||||
ReplySeq: int32(0),
|
ReplySeq: int32(messageSeq),
|
||||||
Sender: sender,
|
Sender: sender,
|
||||||
Time: int32(msgTime),
|
Time: int32(msgTime),
|
||||||
Elements: bot.ConvertStringMessage(customText, isGroup),
|
Elements: bot.ConvertStringMessage(customText, isGroup),
|
||||||
@ -439,14 +404,20 @@ func (bot *CQBot) ConvertStringMessage(msg string, isGroup bool) (r []message.IM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if t == "forward" { // 单独处理转发
|
if t == "forward" { // 单独处理转发
|
||||||
if id, ok := params["id"]; ok {
|
if id, ok := d["id"]; ok {
|
||||||
r = []message.IMessageElement{bot.Client.DownloadForwardMessage(id)}
|
if fwdMsg := bot.Client.DownloadForwardMessage(id); fwdMsg == nil {
|
||||||
|
log.Warnf("警告: Forward 信息不存在或已过期")
|
||||||
|
} else {
|
||||||
|
r = []message.IMessageElement{fwdMsg}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Warnf("警告: Forward 元素中必须包含 id")
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
elem, err := bot.ToElement(t, d, isGroup)
|
||||||
elem, err := bot.ToElement(t, params, isGroup)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
org := "[CQ:" + string(cqCode) + "]"
|
org := s[CQBegin:i]
|
||||||
if !IgnoreInvalidCQCode {
|
if !IgnoreInvalidCQCode {
|
||||||
log.Warnf("转换CQ码 %v 时出现错误: %v 将原样发送.", org, err)
|
log.Warnf("转换CQ码 %v 时出现错误: %v 将原样发送.", org, err)
|
||||||
r = append(r, message.NewText(org))
|
r = append(r, message.NewText(org))
|
||||||
@ -462,32 +433,84 @@ func (bot *CQBot) ConvertStringMessage(msg string, isGroup bool) (r []message.IM
|
|||||||
r = append(r, i...)
|
r = append(r, i...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for hasNext() {
|
|
||||||
ch := next()
|
S1: // Plain Text
|
||||||
switch stat {
|
for ; i < l; i++ {
|
||||||
case 0:
|
if *(*byte)(add(ptr, uintptr(i))) == '[' && i+4 < l &&
|
||||||
if isCQCodeBegin(ch) {
|
*(*uint32)(add(ptr, uintptr(i))) == magicCQ { // Magic :uint32([]byte("[CQ:"))
|
||||||
saveTempText()
|
if i > j {
|
||||||
tempText = append(tempText, []rune("[CQ:")...)
|
if SplitURL {
|
||||||
move(3)
|
for _, str := range global.SplitURL(CQCodeUnescapeText(s[j:i])) {
|
||||||
stat = 1
|
r = append(r, message.NewText(str))
|
||||||
} else {
|
|
||||||
tempText = append(tempText, ch)
|
|
||||||
}
|
}
|
||||||
case 1:
|
} else {
|
||||||
if isCQCodeBegin(ch) {
|
r = append(r, message.NewText(CQCodeUnescapeText(s[j:i])))
|
||||||
move(-1)
|
}
|
||||||
stat = 0
|
}
|
||||||
} else if ch == ']' {
|
CQBegin = i
|
||||||
|
i += 4
|
||||||
|
j = i
|
||||||
|
goto S2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goto End
|
||||||
|
S2: // CQCode Type
|
||||||
|
for k := range d { // 内存复用,减小GC压力
|
||||||
|
delete(d, k)
|
||||||
|
}
|
||||||
|
for ; i < l; i++ {
|
||||||
|
switch *(*byte)(add(ptr, uintptr(i))) {
|
||||||
|
case ',': // CQ Code with params
|
||||||
|
t = s[j:i]
|
||||||
|
i++
|
||||||
|
j = i
|
||||||
|
goto S3
|
||||||
|
case ']': // CQ Code without params
|
||||||
|
t = s[j:i]
|
||||||
|
i++
|
||||||
|
j = i
|
||||||
saveCQCode()
|
saveCQCode()
|
||||||
stat = 0
|
goto S1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goto End
|
||||||
|
S3: // CQCode param key
|
||||||
|
for ; i < l; i++ {
|
||||||
|
if *(*byte)(add(ptr, uintptr(i))) == '=' {
|
||||||
|
key = s[j:i]
|
||||||
|
i++
|
||||||
|
j = i
|
||||||
|
goto S4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goto End
|
||||||
|
S4: // CQCode param value
|
||||||
|
for ; i < l; i++ {
|
||||||
|
switch *(*byte)(add(ptr, uintptr(i))) {
|
||||||
|
case ',': // more param
|
||||||
|
d[key] = CQCodeUnescapeValue(s[j:i])
|
||||||
|
i++
|
||||||
|
j = i
|
||||||
|
goto S3
|
||||||
|
case ']':
|
||||||
|
d[key] = CQCodeUnescapeValue(s[j:i])
|
||||||
|
i++
|
||||||
|
j = i
|
||||||
|
saveCQCode()
|
||||||
|
goto S1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goto End
|
||||||
|
End:
|
||||||
|
if i > j {
|
||||||
|
if SplitURL {
|
||||||
|
for _, str := range global.SplitURL(CQCodeUnescapeText(s[j:i])) {
|
||||||
|
r = append(r, message.NewText(str))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
cqCode = append(cqCode, ch)
|
r = append(r, message.NewText(CQCodeUnescapeText(s[j:i])))
|
||||||
tempText = append(tempText, ch)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
saveTempText()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -520,16 +543,17 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, isGroup bool) (r []messag
|
|||||||
} else if customText != "" {
|
} else if customText != "" {
|
||||||
sender, err := strconv.ParseInt(e.Get("data").Get("qq").String(), 10, 64)
|
sender, err := strconv.ParseInt(e.Get("data").Get("qq").String(), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告:自定义 Reply 元素中必须包含Uin")
|
log.Warnf("警告:自定义 Reply 元素中必须包含 Uin")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
msgTime, err := strconv.ParseInt(e.Get("data").Get("time").String(), 10, 64)
|
msgTime, err := strconv.ParseInt(e.Get("data").Get("time").String(), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msgTime = time.Now().Unix()
|
msgTime = time.Now().Unix()
|
||||||
}
|
}
|
||||||
|
messageSeq, _ := strconv.ParseInt(e.Get("data").Get("seq").String(), 10, 64)
|
||||||
r = append([]message.IMessageElement{
|
r = append([]message.IMessageElement{
|
||||||
&message.ReplyElement{
|
&message.ReplyElement{
|
||||||
ReplySeq: int32(0),
|
ReplySeq: int32(messageSeq),
|
||||||
Sender: sender,
|
Sender: sender,
|
||||||
Time: int32(msgTime),
|
Time: int32(msgTime),
|
||||||
Elements: bot.ConvertStringMessage(customText, isGroup),
|
Elements: bot.ConvertStringMessage(customText, isGroup),
|
||||||
@ -539,7 +563,16 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, isGroup bool) (r []messag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if t == "forward" {
|
if t == "forward" {
|
||||||
r = []message.IMessageElement{bot.Client.DownloadForwardMessage(e.Get("data.id").String())}
|
id := e.Get("data.id").String()
|
||||||
|
if id == "" {
|
||||||
|
log.Warnf("警告: Forward 元素中必须包含 id")
|
||||||
|
} else {
|
||||||
|
if fwdMsg := bot.Client.DownloadForwardMessage(id); fwdMsg == nil {
|
||||||
|
log.Warnf("警告: Forward 信息不存在或已过期")
|
||||||
|
} else {
|
||||||
|
r = []message.IMessageElement{fwdMsg}
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
d := make(map[string]string)
|
d := make(map[string]string)
|
||||||
@ -651,7 +684,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &message.VoiceElement{Data: data}, nil
|
return &message.VoiceElement{Data: codec.RecodeTo24K(data)}, nil
|
||||||
case "record":
|
case "record":
|
||||||
f := d["file"]
|
f := d["file"]
|
||||||
data, err := global.FindFile(f, d["cache"], global.VoicePath)
|
data, err := global.FindFile(f, d["cache"], global.VoicePath)
|
||||||
@ -792,6 +825,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte
|
|||||||
case "cardimage":
|
case "cardimage":
|
||||||
source := d["source"]
|
source := d["source"]
|
||||||
icon := d["icon"]
|
icon := d["icon"]
|
||||||
|
brief := d["brief"]
|
||||||
minWidth, _ := strconv.ParseInt(d["minwidth"], 10, 64)
|
minWidth, _ := strconv.ParseInt(d["minwidth"], 10, 64)
|
||||||
if minWidth == 0 {
|
if minWidth == 0 {
|
||||||
minWidth = 200
|
minWidth = 200
|
||||||
@ -812,7 +846,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("send cardimage faild")
|
return nil, errors.New("send cardimage faild")
|
||||||
}
|
}
|
||||||
return bot.makeShowPic(img, source, icon, minWidth, minHeight, maxWidth, maxHeight, isGroup)
|
return bot.makeShowPic(img, source, brief, icon, minWidth, minHeight, maxWidth, maxHeight, isGroup)
|
||||||
case "video":
|
case "video":
|
||||||
cache := d["cache"]
|
cache := d["cache"]
|
||||||
if cache == "" {
|
if cache == "" {
|
||||||
@ -1102,9 +1136,12 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// makeShowPic 一种xml 方式发送的群消息图片
|
// makeShowPic 一种xml 方式发送的群消息图片
|
||||||
func (bot *CQBot) makeShowPic(elem message.IMessageElement, source string, icon string, minWidth int64, minHeight int64, maxWidth int64, maxHeight int64, group bool) ([]message.IMessageElement, error) {
|
func (bot *CQBot) makeShowPic(elem message.IMessageElement, source string, brief string, icon string, minWidth int64, minHeight int64, maxWidth int64, maxHeight int64, group bool) ([]message.IMessageElement, error) {
|
||||||
xml := ""
|
xml := ""
|
||||||
var suf message.IMessageElement
|
var suf message.IMessageElement
|
||||||
|
if brief == "" {
|
||||||
|
brief = "[分享]我看到一张很赞的图片,分享给你,快来看!"
|
||||||
|
}
|
||||||
if i, ok := elem.(*LocalImageElement); ok {
|
if i, ok := elem.(*LocalImageElement); ok {
|
||||||
if !group {
|
if !group {
|
||||||
gm, err := bot.UploadLocalImageAsPrivate(1, i)
|
gm, err := bot.UploadLocalImageAsPrivate(1, i)
|
||||||
@ -1113,7 +1150,7 @@ func (bot *CQBot) makeShowPic(elem message.IMessageElement, source string, icon
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
suf = gm
|
suf = gm
|
||||||
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="[分享]我看到一张很赞的图片,分享给你,快来看!" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, "", gm.Md5, gm.Md5, len(i.Data), "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="%s" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, brief, "", gm.Md5, gm.Md5, len(i.Data), "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
||||||
} else {
|
} else {
|
||||||
gm, err := bot.UploadLocalImageAsGroup(1, i)
|
gm, err := bot.UploadLocalImageAsGroup(1, i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1121,16 +1158,16 @@ func (bot *CQBot) makeShowPic(elem message.IMessageElement, source string, icon
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
suf = gm
|
suf = gm
|
||||||
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="[分享]我看到一张很赞的图片,分享给你,快来看!" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, "", gm.Md5, gm.Md5, len(i.Data), "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="%s" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, brief, "", gm.Md5, gm.Md5, len(i.Data), "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if i, ok := elem.(*message.GroupImageElement); ok {
|
if i, ok := elem.(*message.GroupImageElement); ok {
|
||||||
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="[分享]我看到一张很赞的图片,分享给你,快来看!" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, "", i.Md5, i.Md5, 0, "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="%s" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, brief, "", i.Md5, i.Md5, 0, "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
||||||
suf = i
|
suf = i
|
||||||
}
|
}
|
||||||
if i, ok := elem.(*message.FriendImageElement); ok {
|
if i, ok := elem.(*message.FriendImageElement); ok {
|
||||||
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="[分享]我看到一张很赞的图片,分享给你,快来看!" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, "", i.Md5, i.Md5, 0, "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="%s" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, brief, "", i.Md5, i.Md5, 0, "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
||||||
suf = i
|
suf = i
|
||||||
}
|
}
|
||||||
if xml != "" {
|
if xml != "" {
|
||||||
|
25
coolq/cqcode_test.go
Normal file
25
coolq/cqcode_test.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package coolq
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Mrs4s/MiraiGo/client"
|
||||||
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
|
)
|
||||||
|
|
||||||
|
var bot = NewQQBot(client.NewClient(1, ""), global.DefaultConfig())
|
||||||
|
|
||||||
|
func TestCQBot_ConvertStringMessage(t *testing.T) {
|
||||||
|
for _, v := range bot.ConvertStringMessage(`[CQ:face,id=115,text=111][CQ:face,id=217]] [CQ:text,text=123] [`, false) {
|
||||||
|
fmt.Println(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var bench = `asdfqwerqwerqwer[CQ:face,id=115,text=111]asdfasdfasdfasdfasdfasdfasd[CQ:face,id=217]] [CQ:text,text=123] [`
|
||||||
|
|
||||||
|
func BenchmarkCQBot_ConvertStringMessage(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
bot.ConvertStringMessage(bench, false)
|
||||||
|
}
|
||||||
|
}
|
@ -11,8 +11,9 @@ import (
|
|||||||
"github.com/Mrs4s/MiraiGo/binary"
|
"github.com/Mrs4s/MiraiGo/binary"
|
||||||
"github.com/Mrs4s/MiraiGo/client"
|
"github.com/Mrs4s/MiraiGo/client"
|
||||||
"github.com/Mrs4s/MiraiGo/message"
|
"github.com/Mrs4s/MiraiGo/message"
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
)
|
)
|
||||||
|
|
||||||
var format = "string"
|
var format = "string"
|
||||||
@ -94,28 +95,37 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
|
|||||||
}
|
}
|
||||||
log.Infof("收到群 %v(%v) 内 %v(%v) 的消息: %v (%v)", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, cqm, id)
|
log.Infof("收到群 %v(%v) 内 %v(%v) 的消息: %v (%v)", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, cqm, id)
|
||||||
gm := bot.formatGroupMessage(m)
|
gm := bot.formatGroupMessage(m)
|
||||||
|
if gm == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
gm["message_id"] = id
|
gm["message_id"] = id
|
||||||
bot.dispatchEventMessage(gm)
|
bot.dispatchEventMessage(gm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) tempMessageEvent(c *client.QQClient, m *message.TempMessage) {
|
func (bot *CQBot) tempMessageEvent(c *client.QQClient, m1 *client.TempMessageEvent) {
|
||||||
|
m := m1.Message
|
||||||
bot.checkMedia(m.Elements)
|
bot.checkMedia(m.Elements)
|
||||||
cqm := ToStringMessage(m.Elements, 0, true)
|
cqm := ToStringMessage(m.Elements, m.Sender.Uin, true)
|
||||||
bot.tempMsgCache.Store(m.Sender.Uin, m.GroupCode)
|
bot.tempMsgCache.Store(m.Sender.Uin, m.GroupCode)
|
||||||
|
id := m.Id
|
||||||
|
if bot.db != nil {
|
||||||
|
id = bot.InsertTempMessage(m.Sender.Uin, m)
|
||||||
|
}
|
||||||
log.Infof("收到来自群 %v(%v) 内 %v(%v) 的临时会话消息: %v", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, cqm)
|
log.Infof("收到来自群 %v(%v) 内 %v(%v) 的临时会话消息: %v", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, cqm)
|
||||||
tm := MSG{
|
tm := MSG{
|
||||||
"post_type": "message",
|
"post_type": "message",
|
||||||
"message_type": "private",
|
"message_type": "private",
|
||||||
"sub_type": "group",
|
"sub_type": "group",
|
||||||
"message_id": m.Id,
|
"message_id": id,
|
||||||
"user_id": m.Sender.Uin,
|
"user_id": m.Sender.Uin,
|
||||||
"message": ToFormattedMessage(m.Elements, 0, false),
|
"message": ToFormattedMessage(m.Elements, m.Sender.Uin, false),
|
||||||
"raw_message": cqm,
|
"raw_message": cqm,
|
||||||
"font": 0,
|
"font": 0,
|
||||||
"self_id": c.Uin,
|
"self_id": c.Uin,
|
||||||
"time": time.Now().Unix(),
|
"time": time.Now().Unix(),
|
||||||
"sender": MSG{
|
"sender": MSG{
|
||||||
"user_id": m.Sender.Uin,
|
"user_id": m.Sender.Uin,
|
||||||
|
"group_id": m.GroupCode,
|
||||||
"nickname": m.Sender.Nickname,
|
"nickname": m.Sender.Nickname,
|
||||||
"sex": "unknown",
|
"sex": "unknown",
|
||||||
"age": 0,
|
"age": 0,
|
||||||
|
@ -21,6 +21,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
|
|||||||
"encrypt_password": false,
|
"encrypt_password": false,
|
||||||
"password_encrypted": "",
|
"password_encrypted": "",
|
||||||
"enable_db": true,
|
"enable_db": true,
|
||||||
|
"enable_self_message": false,
|
||||||
"access_token": "",
|
"access_token": "",
|
||||||
"relogin": {
|
"relogin": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
@ -42,7 +43,9 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
|
|||||||
"host": "0.0.0.0",
|
"host": "0.0.0.0",
|
||||||
"port": 5700,
|
"port": 5700,
|
||||||
"timeout": 5,
|
"timeout": 5,
|
||||||
"post_urls": {"url:port": "secret"}
|
"post_urls": {
|
||||||
|
"url:port": "secret"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"ws_config": {
|
"ws_config": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
@ -68,6 +71,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
|
|||||||
| encrypt_password | bool | 是否对密码进行加密. |
|
| encrypt_password | bool | 是否对密码进行加密. |
|
||||||
| password_encrypted | string | 加密后的密码(请勿修改) |
|
| password_encrypted | string | 加密后的密码(请勿修改) |
|
||||||
| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用 **回复/撤回** 等上下文相关接口 |
|
| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用 **回复/撤回** 等上下文相关接口 |
|
||||||
|
| enable_self_message | bool | 是否启用 `message_sent` 事件 |
|
||||||
| access_token | string | 同CQHTTP的 `access_token` 用于身份验证 |
|
| access_token | string | 同CQHTTP的 `access_token` 用于身份验证 |
|
||||||
| relogin | bool | 是否自动重新登录 |
|
| relogin | bool | 是否自动重新登录 |
|
||||||
| relogin_delay | int | 重登录延时(秒) |
|
| relogin_delay | int | 重登录延时(秒) |
|
||||||
@ -127,6 +131,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
|
|||||||
将文件 `address.txt` 创建到 `go-cqhttp` 工作目录, 并键入 `IP:PORT` 以换行符为分割即可.
|
将文件 `address.txt` 创建到 `go-cqhttp` 工作目录, 并键入 `IP:PORT` 以换行符为分割即可.
|
||||||
|
|
||||||
示例:
|
示例:
|
||||||
|
|
||||||
````
|
````
|
||||||
1.1.1.1:53
|
1.1.1.1:53
|
||||||
1.1.2.2:8899
|
1.1.2.2:8899
|
||||||
|
@ -111,12 +111,13 @@ Type : `reply`
|
|||||||
| `text` | string | 自定义回复的信息 |
|
| `text` | string | 自定义回复的信息 |
|
||||||
| `qq` | int64 | 自定义回复时的自定义QQ, 如果使用自定义信息必须指定. |
|
| `qq` | int64 | 自定义回复时的自定义QQ, 如果使用自定义信息必须指定. |
|
||||||
| `time` | int64 | 可选. 自定义回复时的时间, 格式为Unix时间 |
|
| `time` | int64 | 可选. 自定义回复时的时间, 格式为Unix时间 |
|
||||||
|
| `seq` | int64 | 起始消息序号, 可通过 `get_msg` 获得 |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
示例: `[CQ:reply,id=123456]`
|
示例: `[CQ:reply,id=123456]`
|
||||||
\
|
\
|
||||||
自定义回复示例: `[CQ:reply,text=Hello World,qq=10086,time=3376656000]`
|
自定义回复示例: `[CQ:reply,text=Hello World,qq=10086,time=3376656000,seq=5123]`
|
||||||
|
|
||||||
### 音乐分享 <Badge text="发"/>
|
### 音乐分享 <Badge text="发"/>
|
||||||
|
|
||||||
@ -263,8 +264,9 @@ Type: `node`
|
|||||||
| `name` | string | 发送者显示名字 | 用于自定义消息 (自定义消息并合并转发,实际查看顺序为自定义消息段顺序) |
|
| `name` | string | 发送者显示名字 | 用于自定义消息 (自定义消息并合并转发,实际查看顺序为自定义消息段顺序) |
|
||||||
| `uin` | int64 | 发送者QQ号 | 用于自定义消息 |
|
| `uin` | int64 | 发送者QQ号 | 用于自定义消息 |
|
||||||
| `content` | message | 具体消息 | 用于自定义消息 |
|
| `content` | message | 具体消息 | 用于自定义消息 |
|
||||||
|
| `seq` | message | 具体消息 | 用于自定义消息 |
|
||||||
|
|
||||||
特殊说明: **需要使用单独的API `/send_group_forward_msg` 发送,并且由于消息段较为复杂,仅支持Array形式入参。 如果引用消息和自定义消息同时出现,实际查看顺序将取消息段顺序. 另外按 [CQHTTP](https://cqhttp.cc/docs/4.15/#/Message?id=格式) 文档说明, `data` 应全为字符串, 但由于需要接收`message` 类型的消息, 所以 *仅限此Type的content字段* 支持Array套娃**
|
特殊说明: **需要使用单独的API `/send_group_forward_msg` 发送,并且由于消息段较为复杂,仅支持Array形式入参。 如果引用消息和自定义消息同时出现,实际查看顺序将取消息段顺序. 另外按 [CQHTTP](https://git.io/JtxtN) 文档说明, `data` 应全为字符串, 但由于需要接收`message` 类型的消息, 所以 *仅限此Type的content字段* 支持Array套娃**
|
||||||
|
|
||||||
示例:
|
示例:
|
||||||
|
|
||||||
@ -325,6 +327,7 @@ Type: `node`
|
|||||||
"name": "自定义发送者",
|
"name": "自定义发送者",
|
||||||
"uin": "10086",
|
"uin": "10086",
|
||||||
"content": "我是自定义消息",
|
"content": "我是自定义消息",
|
||||||
|
"seq": "5123",
|
||||||
"time": "3376656000"
|
"time": "3376656000"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -603,7 +606,7 @@ Type: `tts`
|
|||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | -------------- | ---------------------------- |
|
| ---------- | -------------- | ---------------------------- |
|
||||||
| `group_id` | int64 | 群号 |
|
| `group_id` | int64 | 群号 |
|
||||||
| `messages` | forward node[] | 自定义转发消息, 具体看CQCode |
|
| `messages` | forward node[] | 自定义转发消息, 具体看 [CQCode](https://github.com/Mrs4s/go-cqhttp/blob/master/docs/cqhttp.md#%E5%90%88%E5%B9%B6%E8%BD%AC%E5%8F%91%E6%B6%88%E6%81%AF%E8%8A%82%E7%82%B9) |
|
||||||
|
|
||||||
响应数据
|
响应数据
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// +build linux windows,!arm darwin,!arm64
|
// +build linux windows,!arm darwin
|
||||||
// +build 386 amd64 arm arm64
|
// +build 386 amd64 arm arm64
|
||||||
|
|
||||||
// Package codec Slik编码核心模块
|
// Package codec Slik编码核心模块
|
||||||
@ -51,3 +51,16 @@ func EncodeToSilk(record []byte, tempName string, useCache bool) (silkWav []byte
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RecodeTo24K 将silk重新编码为 24000 bit rate
|
||||||
|
func RecodeTo24K(data []byte) []byte {
|
||||||
|
pcm, err := silk.DecodeSilkBuffToPcm(data, 24000)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
data, err = silk.EncodePcmBuffToSilk(pcm, 24000, 24000, true)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
package codec
|
|
||||||
|
|
||||||
import "github.com/pkg/errors"
|
|
||||||
|
|
||||||
//EncodeToSilk 将音频编码为Silk
|
|
||||||
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
|
|
||||||
return nil, errors.New("not supported now")
|
|
||||||
}
|
|
@ -8,3 +8,8 @@ import "errors"
|
|||||||
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
|
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
|
||||||
return nil, errors.New("not supported now")
|
return nil, errors.New("not supported now")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RecodeTo24K 将silk重新编码为 24000 bit rate
|
||||||
|
func RecodeTo24K(data []byte) []byte {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
@ -8,3 +8,8 @@ import "errors"
|
|||||||
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
|
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
|
||||||
return nil, errors.New("not supported now")
|
return nil, errors.New("not supported now")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RecodeTo24K 将silk重新编码为 24000 bit rate
|
||||||
|
func RecodeTo24K(data []byte) []byte {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
@ -6,3 +6,8 @@ import "errors"
|
|||||||
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
|
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
|
||||||
return nil, errors.New("not supported now")
|
return nil, errors.New("not supported now")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RecodeTo24K 将silk重新编码为 24000 bit rate
|
||||||
|
func RecodeTo24K(data []byte) []byte {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
@ -145,6 +145,7 @@ type JSONConfig struct {
|
|||||||
EncryptPassword bool `json:"encrypt_password"`
|
EncryptPassword bool `json:"encrypt_password"`
|
||||||
PasswordEncrypted string `json:"password_encrypted"`
|
PasswordEncrypted string `json:"password_encrypted"`
|
||||||
EnableDB bool `json:"enable_db"`
|
EnableDB bool `json:"enable_db"`
|
||||||
|
EnableSelfMessage bool `json:"enable_self_message"`
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
ReLogin struct {
|
ReLogin struct {
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
|
7
global/terminal/double_click.go
Normal file
7
global/terminal/double_click.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package terminal
|
||||||
|
|
||||||
|
func RunningByDoubleClick() bool {
|
||||||
|
return false
|
||||||
|
}
|
23
global/terminal/double_click_windows.go
Normal file
23
global/terminal/double_click_windows.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package terminal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RunningByDoubleClick 检查是否通过双击直接运行
|
||||||
|
func RunningByDoubleClick() bool {
|
||||||
|
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
||||||
|
lp := kernel32.NewProc("GetConsoleProcessList")
|
||||||
|
if lp != nil {
|
||||||
|
var ids [2]uint32
|
||||||
|
var maxCount uint32 = 2
|
||||||
|
ret, _, _ := lp.Call(uintptr(unsafe.Pointer(&ids)), uintptr(maxCount))
|
||||||
|
if ret > 1 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
5
go.mod
5
go.mod
@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
|
|||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20210220103625-420583e1c56a
|
github.com/Mrs4s/MiraiGo v0.0.0-20210429065541-8f474db6a37e
|
||||||
github.com/dustin/go-humanize v1.0.0
|
github.com/dustin/go-humanize v1.0.0
|
||||||
github.com/gin-contrib/pprof v1.3.0
|
github.com/gin-contrib/pprof v1.3.0
|
||||||
github.com/gin-gonic/gin v1.6.3
|
github.com/gin-gonic/gin v1.6.3
|
||||||
@ -20,11 +20,10 @@ require (
|
|||||||
github.com/syndtr/goleveldb v1.0.0
|
github.com/syndtr/goleveldb v1.0.0
|
||||||
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
|
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
|
||||||
github.com/tidwall/gjson v1.6.8
|
github.com/tidwall/gjson v1.6.8
|
||||||
github.com/wdvxdr1123/go-silk v0.0.0-20210207032612-169bbdf8861d
|
github.com/wdvxdr1123/go-silk v0.0.0-20210316130616-d47b553def60
|
||||||
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
|
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
|
||||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
|
||||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf
|
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf
|
||||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
|
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
|
||||||
)
|
)
|
||||||
|
18
go.sum
18
go.sum
@ -1,7 +1,7 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20210220103625-420583e1c56a h1:pBIkeU4bjC9IYC9Noftm6uNxRivnekKWkxYmgEK6+Nc=
|
github.com/Mrs4s/MiraiGo v0.0.0-20210429065541-8f474db6a37e h1:MEBnCfoVolYSsO/KZ5IbU1l/WV+yMuucgbOxwSwEaRM=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20210220103625-420583e1c56a/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU=
|
github.com/Mrs4s/MiraiGo v0.0.0-20210429065541-8f474db6a37e/go.mod h1:NjiWhlvGxwv1ftOWIoiFa/OzklnAYI4YqNexFOKSZKw=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
@ -80,8 +80,9 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX
|
|||||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
|
|
||||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
|
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||||
|
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
@ -121,8 +122,8 @@ github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
|||||||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||||
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
||||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||||
github.com/wdvxdr1123/go-silk v0.0.0-20210207032612-169bbdf8861d h1:gJTKbjZtlMt/almOeFi/UpVtT3RHqRWscgEuDtnF5TU=
|
github.com/wdvxdr1123/go-silk v0.0.0-20210316130616-d47b553def60 h1:lRKf10iIOW0VsH5WDF621ihzR+R2wEBZVtNRHuLLCb4=
|
||||||
github.com/wdvxdr1123/go-silk v0.0.0-20210207032612-169bbdf8861d/go.mod h1:twOxzexmM2Il1ReUu1fB5tnUotOq/dp56xjk/ZHwb1I=
|
github.com/wdvxdr1123/go-silk v0.0.0-20210316130616-d47b553def60/go.mod h1:ecFKZPX81BaB70I6ruUgEwYcDOtuNgJGnjdK+MIl5ko=
|
||||||
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 h1:4UJw9if55Fu3HOwbfcaQlJ27p3oeJU2JZqoeT3ITJQk=
|
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 h1:4UJw9if55Fu3HOwbfcaQlJ27p3oeJU2JZqoeT3ITJQk=
|
||||||
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:rIrm5geMiBhPQkdfUm8gDFi/WiHneOp1i9KjmJqc+9I=
|
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:rIrm5geMiBhPQkdfUm8gDFi/WiHneOp1i9KjmJqc+9I=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
@ -169,9 +170,8 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm
|
|||||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||||
@ -204,8 +204,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie
|
|||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
modernc.org/libc v1.7.6 h1:P0qDJAlSR6hSAuE8mQgz9eH/GzigfEd3IIn7HmTQgT0=
|
modernc.org/libc v1.8.1 h1:y9oPIhwcaFXxX7kMp6Qb2ZLKzr0mDkikWN3CV5GS63o=
|
||||||
modernc.org/libc v1.7.6/go.mod h1:U1eq8YWr/Kc1RWCMFUWEdkTg8OTcfLw2kY8EDwl039w=
|
modernc.org/libc v1.8.1/go.mod h1:U1eq8YWr/Kc1RWCMFUWEdkTg8OTcfLw2kY8EDwl039w=
|
||||||
modernc.org/mathutil v1.1.1/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
modernc.org/mathutil v1.1.1/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
||||||
modernc.org/mathutil v1.2.2 h1:+yFk8hBprV+4c0U9GjFtL+dV3N8hOJ8JCituQcMShFY=
|
modernc.org/mathutil v1.2.2 h1:+yFk8hBprV+4c0U9GjFtL+dV3N8hOJ8JCituQcMShFY=
|
||||||
modernc.org/mathutil v1.2.2/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
modernc.org/mathutil v1.2.2/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
||||||
|
72
main.go
72
main.go
@ -22,20 +22,21 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/server"
|
|
||||||
"github.com/guonaihong/gout"
|
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
"golang.org/x/crypto/pbkdf2"
|
|
||||||
"golang.org/x/term"
|
|
||||||
|
|
||||||
"github.com/Mrs4s/MiraiGo/binary"
|
"github.com/Mrs4s/MiraiGo/binary"
|
||||||
"github.com/Mrs4s/MiraiGo/client"
|
"github.com/Mrs4s/MiraiGo/client"
|
||||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
"github.com/guonaihong/gout"
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
easy "github.com/t-tomalak/logrus-easy-formatter"
|
easy "github.com/t-tomalak/logrus-easy-formatter"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
"golang.org/x/crypto/pbkdf2"
|
||||||
|
"golang.org/x/term"
|
||||||
|
|
||||||
|
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||||
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
|
"github.com/Mrs4s/go-cqhttp/global/terminal"
|
||||||
|
"github.com/Mrs4s/go-cqhttp/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
@ -43,6 +44,28 @@ var conf *global.JSONConfig
|
|||||||
var isFastStart = false
|
var isFastStart = false
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
logFormatter := &easy.Formatter{
|
||||||
|
TimestampFormat: "2006-01-02 15:04:05",
|
||||||
|
LogFormat: "[%time%] [%lvl%]: %msg% \n",
|
||||||
|
}
|
||||||
|
w, err := rotatelogs.New(path.Join("logs", "%Y-%m-%d.log"), rotatelogs.WithRotationTime(time.Hour*24))
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("rotatelogs init err: %v", err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
conf = getConfig()
|
||||||
|
if conf == nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 在debug模式下,将在标准输出中打印当前执行行数
|
||||||
|
if conf.Debug {
|
||||||
|
log.SetReportCaller(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.AddHook(global.NewLocalHook(w, logFormatter, global.GetLogLevel(conf.LogLevel)...))
|
||||||
|
|
||||||
if global.PathExists("cqhttp.json") {
|
if global.PathExists("cqhttp.json") {
|
||||||
log.Info("发现 cqhttp.json 将在五秒后尝试导入配置,按 Ctrl+C 取消.")
|
log.Info("发现 cqhttp.json 将在五秒后尝试导入配置,按 Ctrl+C 取消.")
|
||||||
log.Warn("警告: 该操作会删除 cqhttp.json 并覆盖 config.hjson 文件.")
|
log.Warn("警告: 该操作会删除 cqhttp.json 并覆盖 config.hjson 文件.")
|
||||||
@ -73,28 +96,6 @@ func init() {
|
|||||||
_ = os.Remove("cqhttp.json")
|
_ = os.Remove("cqhttp.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
conf = getConfig()
|
|
||||||
if conf == nil {
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
logFormatter := &easy.Formatter{
|
|
||||||
TimestampFormat: "2006-01-02 15:04:05",
|
|
||||||
LogFormat: "[%time%] [%lvl%]: %msg% \n",
|
|
||||||
}
|
|
||||||
w, err := rotatelogs.New(path.Join("logs", "%Y-%m-%d.log"), rotatelogs.WithRotationTime(time.Hour*24))
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("rotatelogs init err: %v", err)
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 在debug模式下,将在标准输出中打印当前执行行数
|
|
||||||
if conf.Debug {
|
|
||||||
log.SetReportCaller(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.AddHook(global.NewLocalHook(w, logFormatter, global.GetLogLevel(conf.LogLevel)...))
|
|
||||||
|
|
||||||
if !global.PathExists(global.ImagePath) {
|
if !global.PathExists(global.ImagePath) {
|
||||||
if err := os.MkdirAll(global.ImagePath, 0755); err != nil {
|
if err := os.MkdirAll(global.ImagePath, 0755); err != nil {
|
||||||
log.Fatalf("创建图片缓存文件夹失败: %v", err)
|
log.Fatalf("创建图片缓存文件夹失败: %v", err)
|
||||||
@ -118,7 +119,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
var byteKey []byte
|
var byteKey []byte
|
||||||
arg := os.Args
|
arg := os.Args
|
||||||
if len(arg) > 1 {
|
if len(arg) > 1 {
|
||||||
@ -140,7 +140,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if terminal.RunningByDoubleClick() && !isFastStart {
|
||||||
|
log.Warning("警告: 强烈不推荐通过双击直接运行本程序, 这将导致一些非预料的后果.")
|
||||||
|
log.Warning("将等待10s后启动")
|
||||||
|
time.Sleep(time.Second * 10)
|
||||||
|
}
|
||||||
if conf.Uin == 0 || (conf.Password == "" && conf.PasswordEncrypted == "") {
|
if conf.Uin == 0 || (conf.Password == "" && conf.PasswordEncrypted == "") {
|
||||||
log.Warnf("请修改 config.hjson 以添加账号密码.")
|
log.Warnf("请修改 config.hjson 以添加账号密码.")
|
||||||
if !isFastStart {
|
if !isFastStart {
|
||||||
@ -183,6 +187,7 @@ func main() {
|
|||||||
if len(byteKey) == 0 {
|
if len(byteKey) == 0 {
|
||||||
log.Infof("密码加密已启用, 请输入Key对密码进行解密以继续: (Enter 提交)")
|
log.Infof("密码加密已启用, 请输入Key对密码进行解密以继续: (Enter 提交)")
|
||||||
cancel := make(chan struct{}, 1)
|
cancel := make(chan struct{}, 1)
|
||||||
|
state, _ := term.GetState(int(os.Stdin.Fd()))
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-cancel:
|
case <-cancel:
|
||||||
@ -190,6 +195,7 @@ func main() {
|
|||||||
case <-time.After(time.Second * 45):
|
case <-time.After(time.Second * 45):
|
||||||
log.Infof("解密key输入超时")
|
log.Infof("解密key输入超时")
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
|
_ = term.Restore(int(os.Stdin.Fd()), state)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -345,7 +351,7 @@ func OldPasswordDecrypt(encryptedPassword string, key []byte) string {
|
|||||||
|
|
||||||
func checkUpdate() {
|
func checkUpdate() {
|
||||||
log.Infof("正在检查更新.")
|
log.Infof("正在检查更新.")
|
||||||
if coolq.Version == "unknown" {
|
if coolq.Version == "(devel)" {
|
||||||
log.Warnf("检查更新失败: 使用的 Actions 测试版或自编译版本.")
|
log.Warnf("检查更新失败: 使用的 Actions 测试版或自编译版本.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
382
server/api.go
Normal file
382
server/api.go
Normal file
@ -0,0 +1,382 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||||
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
)
|
||||||
|
|
||||||
|
type resultGetter interface {
|
||||||
|
Get(string) gjson.Result
|
||||||
|
}
|
||||||
|
|
||||||
|
type apiCaller struct {
|
||||||
|
bot *coolq.CQBot
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLoginInfo(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetLoginInfo()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFriendList(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetFriendList()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupList(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetGroupList(p.Get("no_cache").Bool())
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetGroupInfo(p.Get("group_id").Int(), p.Get("no_cache").Bool())
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupMemberList(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetGroupMemberList(p.Get("group_id").Int(), p.Get("no_cache").Bool())
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupMemberInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetGroupMemberInfo(
|
||||||
|
p.Get("group_id").Int(), p.Get("user_id").Int(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
func sendMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
autoEscape := global.EnsureBool(p.Get("auto_escape"), false)
|
||||||
|
if p.Get("message_type").Str == "private" {
|
||||||
|
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
||||||
|
}
|
||||||
|
if p.Get("message_type").Str == "group" {
|
||||||
|
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
||||||
|
}
|
||||||
|
if p.Get("user_id").Int() != 0 {
|
||||||
|
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
||||||
|
}
|
||||||
|
if p.Get("group_id").Int() != 0 {
|
||||||
|
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
||||||
|
}
|
||||||
|
return coolq.MSG{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendGroupMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"),
|
||||||
|
global.EnsureBool(p.Get("auto_escape"), false))
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendGroupForwardMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQSendGroupForwardMessage(p.Get("group_id").Int(), p.Get("messages"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendPrivateMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("group_id").Int(), p.Get("message"),
|
||||||
|
global.EnsureBool(p.Get("auto_escape"), false))
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQDeleteMessage(int32(p.Get("message_id").Int()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func setFriendAddRequest(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
apr := true
|
||||||
|
if p.Get("approve").Exists() {
|
||||||
|
apr = p.Get("approve").Bool()
|
||||||
|
}
|
||||||
|
return bot.CQProcessFriendRequest(p.Get("flag").Str, apr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setGroupAddRequest(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
subType := p.Get("sub_type").Str
|
||||||
|
apr := true
|
||||||
|
if subType == "" {
|
||||||
|
subType = p.Get("type").Str
|
||||||
|
}
|
||||||
|
if p.Get("approve").Exists() {
|
||||||
|
apr = p.Get("approve").Bool()
|
||||||
|
}
|
||||||
|
return bot.CQProcessGroupRequest(p.Get("flag").Str, subType, p.Get("reason").Str, apr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setGroupCard(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQSetGroupCard(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("card").Str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setGroupSpecialTitle(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQSetGroupSpecialTitle(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("special_title").Str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setGroupKick(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQSetGroupKick(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("message").Str, p.Get("reject_add_request").Bool())
|
||||||
|
}
|
||||||
|
|
||||||
|
func setGroupBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQSetGroupBan(p.Get("group_id").Int(), p.Get("user_id").Int(), func() uint32 {
|
||||||
|
if p.Get("duration").Exists() {
|
||||||
|
return uint32(p.Get("duration").Int())
|
||||||
|
}
|
||||||
|
return 1800
|
||||||
|
}())
|
||||||
|
}
|
||||||
|
|
||||||
|
func setGroupWholeBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQSetGroupWholeBan(p.Get("group_id").Int(), func() bool {
|
||||||
|
if p.Get("enable").Exists() {
|
||||||
|
return p.Get("enable").Bool()
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}())
|
||||||
|
}
|
||||||
|
|
||||||
|
func setGroupName(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQSetGroupName(p.Get("group_id").Int(), p.Get("group_name").Str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setGroupAdmin(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQSetGroupAdmin(p.Get("group_id").Int(), p.Get("user_id").Int(), func() bool {
|
||||||
|
if p.Get("enable").Exists() {
|
||||||
|
return p.Get("enable").Bool()
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}())
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendGroupNotice(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQSetGroupMemo(p.Get("group_id").Int(), p.Get("content").Str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setGroupLeave(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQSetGroupLeave(p.Get("group_id").Int())
|
||||||
|
}
|
||||||
|
|
||||||
|
func getImage(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetImage(p.Get("file").Str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getForwardMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
id := p.Get("message_id").Str
|
||||||
|
if id == "" {
|
||||||
|
id = p.Get("id").Str
|
||||||
|
}
|
||||||
|
return bot.CQGetForwardMessage(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetMessage(int32(p.Get("message_id").Int()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func downloadFile(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
headers := map[string]string{}
|
||||||
|
headersToken := p.Get("headers")
|
||||||
|
if headersToken.IsArray() {
|
||||||
|
for _, sub := range headersToken.Array() {
|
||||||
|
str := strings.SplitN(sub.String(), "=", 2)
|
||||||
|
if len(str) == 2 {
|
||||||
|
headers[str[0]] = str[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if headersToken.Type == gjson.String {
|
||||||
|
lines := strings.Split(headersToken.String(), "\r\n")
|
||||||
|
for _, sub := range lines {
|
||||||
|
str := strings.SplitN(sub, "=", 2)
|
||||||
|
if len(str) == 2 {
|
||||||
|
headers[str[0]] = str[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bot.CQDownloadFile(p.Get("url").Str, headers, int(p.Get("thread_count").Int()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupHonorInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetGroupHonorInfo(p.Get("group_id").Int(), p.Get("type").Str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setRestart(_ *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
var delay int64
|
||||||
|
delay = p.Get("delay").Int()
|
||||||
|
if delay < 0 {
|
||||||
|
delay = 0
|
||||||
|
}
|
||||||
|
defer func(delay int64) {
|
||||||
|
time.Sleep(time.Duration(delay) * time.Millisecond)
|
||||||
|
Restart <- struct{}{}
|
||||||
|
}(delay)
|
||||||
|
return coolq.MSG{"data": nil, "retcode": 0, "status": "async"}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func canSendImage(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
||||||
|
return bot.CQCanSendImage()
|
||||||
|
}
|
||||||
|
|
||||||
|
func canSendRecord(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
||||||
|
return bot.CQCanSendRecord()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getStrangerInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetStrangerInfo(p.Get("user_id").Int())
|
||||||
|
}
|
||||||
|
|
||||||
|
func getStatus(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetStatus()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getVersionInfo(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetVersionInfo()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupSystemMSG(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetGroupSystemMessages()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupFileSystemInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetGroupFileSystemInfo(p.Get("group_id").Int())
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupRootFiles(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetGroupRootFiles(p.Get("group_id").Int())
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupFilesByFolder(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetGroupFilesByFolderID(p.Get("group_id").Int(), p.Get("folder_id").Str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupFileURL(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetGroupFileURL(p.Get("group_id").Int(), p.Get("file_id").Str, int32(p.Get("busid").Int()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func uploadGroupFile(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQUploadGroupFile(p.Get("group_id").Int(), p.Get("file").Str, p.Get("name").Str, p.Get("folder").Str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupMsgHistory(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetGroupMessageHistory(p.Get("group_id").Int(), p.Get("message_seq").Int())
|
||||||
|
}
|
||||||
|
|
||||||
|
func getVipInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetVipInfo(p.Get("user_id").Int())
|
||||||
|
}
|
||||||
|
|
||||||
|
func reloadEventFilter(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
||||||
|
return bot.CQReloadEventFilter()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGroupAtAllRemain(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetAtAllRemain(p.Get("group_id").Int())
|
||||||
|
}
|
||||||
|
|
||||||
|
func ocrImage(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQOcrImage(p.Get("image").Str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getOnlineClients(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetOnlineClients(p.Get("no_cache").Bool())
|
||||||
|
}
|
||||||
|
|
||||||
|
func getWordSlices(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetWordSlices(p.Get("content").Str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setGroupPortrait(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func setEssenceMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQSetEssenceMessage(int32(p.Get("message_id").Int()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteEssenceMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQDeleteEssenceMessage(int32(p.Get("message_id").Int()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEssenceMsgList(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQGetEssenceMessageList(p.Get("group_id").Int())
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkUrlSafely(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQCheckURLSafely(p.Get("url").String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func setGroupAnonymousBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
obj := p.Get("anonymous")
|
||||||
|
flag := p.Get("anonymous_flag")
|
||||||
|
if !flag.Exists() {
|
||||||
|
flag = p.Get("flag")
|
||||||
|
}
|
||||||
|
if !flag.Exists() && !obj.Exists() {
|
||||||
|
return coolq.Failed(100, "FLAG_NOT_FOUND", "flag未找到")
|
||||||
|
}
|
||||||
|
if !flag.Exists() {
|
||||||
|
flag = obj.Get("flag")
|
||||||
|
}
|
||||||
|
return bot.CQSetGroupAnonymousBan(p.Get("group_id").Int(), flag.String(), int32(p.Get("duration").Int()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleQuickOperation(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
||||||
|
return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation"))
|
||||||
|
}
|
||||||
|
|
||||||
|
var API = map[string]func(*coolq.CQBot, resultGetter) coolq.MSG{
|
||||||
|
"get_login_info": getLoginInfo,
|
||||||
|
"get_friend_list": getFriendList,
|
||||||
|
"get_group_list": getGroupList,
|
||||||
|
"get_group_info": getGroupInfo,
|
||||||
|
"get_group_member_list": getGroupMemberList,
|
||||||
|
"get_group_member_info": getGroupMemberInfo,
|
||||||
|
"send_msg": sendMSG,
|
||||||
|
"send_group_msg": sendGroupMSG,
|
||||||
|
"send_group_forward_msg": sendGroupForwardMSG,
|
||||||
|
"send_private_msg": sendPrivateMSG,
|
||||||
|
"delete_msg": deleteMSG,
|
||||||
|
"set_friend_add_request": setFriendAddRequest,
|
||||||
|
"set_group_add_request": setGroupAddRequest,
|
||||||
|
"set_group_card": setGroupCard,
|
||||||
|
"set_group_special_title": setGroupSpecialTitle,
|
||||||
|
"set_group_kick": setGroupKick,
|
||||||
|
"set_group_ban": setGroupBan,
|
||||||
|
"set_group_whole_ban": setGroupWholeBan,
|
||||||
|
"set_group_name": setGroupName,
|
||||||
|
"set_group_admin": setGroupAdmin,
|
||||||
|
"_send_group_notice": sendGroupNotice,
|
||||||
|
"set_group_leave": setGroupLeave,
|
||||||
|
"get_image": getImage,
|
||||||
|
"get_forward_msg": getForwardMSG,
|
||||||
|
"get_msg": getMSG,
|
||||||
|
"download_file": downloadFile,
|
||||||
|
"get_group_honor_info": getGroupHonorInfo,
|
||||||
|
"set_restart": setRestart,
|
||||||
|
"can_send_image": canSendImage,
|
||||||
|
"can_send_record": canSendRecord,
|
||||||
|
"get_stranger_info": getStrangerInfo,
|
||||||
|
"get_status": getStatus,
|
||||||
|
"get_version_info": getVersionInfo,
|
||||||
|
"get_group_system_msg": getGroupSystemMSG,
|
||||||
|
"get_group_file_system_info": getGroupFileSystemInfo,
|
||||||
|
"get_group_root_files": getGroupRootFiles,
|
||||||
|
"get_group_files_by_folder": getGroupFilesByFolder,
|
||||||
|
"get_group_file_url": getGroupFileURL,
|
||||||
|
"upload_group_file": uploadGroupFile,
|
||||||
|
"get_group_msg_history": getGroupMsgHistory,
|
||||||
|
"_get_vip_info": getVipInfo,
|
||||||
|
"reload_event_filter": reloadEventFilter,
|
||||||
|
".ocr_image": ocrImage,
|
||||||
|
"ocr_image": ocrImage,
|
||||||
|
"get_group_at_all_remain": getGroupAtAllRemain,
|
||||||
|
"get_online_clients": getOnlineClients,
|
||||||
|
".get_word_slices": getWordSlices,
|
||||||
|
"set_group_portrait": setGroupPortrait,
|
||||||
|
"set_essence_msg": setEssenceMSG,
|
||||||
|
"delete_essence_msg": deleteEssenceMSG,
|
||||||
|
"get_essence_msg_list": getEssenceMsgList,
|
||||||
|
"check_url_safely": checkUrlSafely,
|
||||||
|
"set_group_anonymous_ban": setGroupAnonymousBan,
|
||||||
|
".handle_quick_operation": handleQuickOperation,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *apiCaller) callAPI(action string, p resultGetter) coolq.MSG {
|
||||||
|
if f, ok := API[action]; ok {
|
||||||
|
return f(api.bot, p)
|
||||||
|
} else {
|
||||||
|
return coolq.Failed(404, "API_NOT_FOUND", "API不存在")
|
||||||
|
}
|
||||||
|
}
|
517
server/http.go
517
server/http.go
@ -7,16 +7,14 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/guonaihong/gout/dataflow"
|
|
||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/guonaihong/gout"
|
"github.com/guonaihong/gout"
|
||||||
|
"github.com/guonaihong/gout/dataflow"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
@ -25,6 +23,7 @@ type httpServer struct {
|
|||||||
engine *gin.Engine
|
engine *gin.Engine
|
||||||
bot *coolq.CQBot
|
bot *coolq.CQBot
|
||||||
HTTP *http.Server
|
HTTP *http.Server
|
||||||
|
api apiCaller
|
||||||
}
|
}
|
||||||
|
|
||||||
type httpClient struct {
|
type httpClient struct {
|
||||||
@ -34,6 +33,10 @@ type httpClient struct {
|
|||||||
timeout int32
|
timeout int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type httpContext struct {
|
||||||
|
ctx *gin.Context
|
||||||
|
}
|
||||||
|
|
||||||
var cqHTTPServer = &httpServer{}
|
var cqHTTPServer = &httpServer{}
|
||||||
|
|
||||||
// Debug 是否启用Debug模式
|
// Debug 是否启用Debug模式
|
||||||
@ -43,6 +46,7 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
|||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
s.engine = gin.New()
|
s.engine = gin.New()
|
||||||
s.bot = bot
|
s.bot = bot
|
||||||
|
s.api = apiCaller{s.bot}
|
||||||
s.engine.Use(func(c *gin.Context) {
|
s.engine.Use(func(c *gin.Context) {
|
||||||
if c.Request.Method != "GET" && c.Request.Method != "POST" {
|
if c.Request.Method != "GET" && c.Request.Method != "POST" {
|
||||||
log.Warnf("已拒绝客户端 %v 的请求: 方法错误", c.Request.RemoteAddr)
|
log.Warnf("已拒绝客户端 %v 的请求: 方法错误", c.Request.RemoteAddr)
|
||||||
@ -156,522 +160,29 @@ func (s *httpServer) HandleActions(c *gin.Context) {
|
|||||||
global.RateLimit(context.Background())
|
global.RateLimit(context.Background())
|
||||||
action := strings.ReplaceAll(c.Param("action"), "_async", "")
|
action := strings.ReplaceAll(c.Param("action"), "_async", "")
|
||||||
log.Debugf("HTTPServer接收到API调用: %v", action)
|
log.Debugf("HTTPServer接收到API调用: %v", action)
|
||||||
if f, ok := httpAPI[action]; ok {
|
c.JSON(200, s.api.callAPI(action, httpContext{ctx: c}))
|
||||||
f(s, c)
|
|
||||||
} else {
|
|
||||||
c.JSON(200, coolq.Failed(404))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLoginInfo 获取登录号信息
|
func (h httpContext) Get(k string) gjson.Result {
|
||||||
func GetLoginInfo(s *httpServer, c *gin.Context) {
|
c := h.ctx
|
||||||
c.JSON(200, s.bot.CQGetLoginInfo())
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetFriendList 获取好友列表
|
|
||||||
func GetFriendList(s *httpServer, c *gin.Context) {
|
|
||||||
c.JSON(200, s.bot.CQGetFriendList())
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGroupList 获取群列表
|
|
||||||
func GetGroupList(s *httpServer, c *gin.Context) {
|
|
||||||
nc := getParamOrDefault(c, "no_cache", "false")
|
|
||||||
c.JSON(200, s.bot.CQGetGroupList(nc == "true"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGroupInfo 获取群信息
|
|
||||||
func GetGroupInfo(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
nc := getParamOrDefault(c, "no_cache", "false")
|
|
||||||
c.JSON(200, s.bot.CQGetGroupInfo(gid, nc == "true"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGroupMemberList 获取群成员列表
|
|
||||||
func GetGroupMemberList(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
nc := getParamOrDefault(c, "no_cache", "false")
|
|
||||||
c.JSON(200, s.bot.CQGetGroupMemberList(gid, nc == "true"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGroupMemberInfo 获取群成员信息
|
|
||||||
func GetGroupMemberInfo(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQGetGroupMemberInfo(gid, uid))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGroupFileSystemInfo 扩展API-获取群文件系统信息
|
|
||||||
func GetGroupFileSystemInfo(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQGetGroupFileSystemInfo(gid))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGroupRootFiles 扩展API-获取群根目录文件列表
|
|
||||||
func GetGroupRootFiles(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQGetGroupRootFiles(gid))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGroupFilesByFolderID 扩展API-获取群子目录文件列表
|
|
||||||
func GetGroupFilesByFolderID(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
folderID := getParam(c, "folder_id")
|
|
||||||
c.JSON(200, s.bot.CQGetGroupFilesByFolderID(gid, folderID))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGroupFileURL 扩展API-获取群文件资源链接
|
|
||||||
func GetGroupFileURL(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
fid := getParam(c, "file_id")
|
|
||||||
busid, _ := strconv.ParseInt(getParam(c, "busid"), 10, 32)
|
|
||||||
c.JSON(200, s.bot.CQGetGroupFileURL(gid, fid, int32(busid)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// UploadGroupFile 扩展API-上传群文件
|
|
||||||
func UploadGroupFile(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQUploadGroupFile(gid, getParam(c, "file"), getParam(c, "name"), getParam(c, "folder")))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendMessage 发送消息
|
|
||||||
//
|
|
||||||
// https://git.io/JtwTQ
|
|
||||||
func SendMessage(s *httpServer, c *gin.Context) {
|
|
||||||
if getParam(c, "message_type") == "private" {
|
|
||||||
SendPrivateMessage(s, c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if getParam(c, "message_type") == "group" {
|
|
||||||
SendGroupMessage(s, c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if getParam(c, "group_id") != "" {
|
|
||||||
SendGroupMessage(s, c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if getParam(c, "user_id") != "" {
|
|
||||||
SendPrivateMessage(s, c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendPrivateMessage 发送私聊消息
|
|
||||||
func SendPrivateMessage(s *httpServer, c *gin.Context) {
|
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
|
||||||
msg, t := getParamWithType(c, "message")
|
|
||||||
autoEscape := global.EnsureBool(getParam(c, "auto_escape"), false)
|
|
||||||
if t == gjson.JSON {
|
|
||||||
c.JSON(200, s.bot.CQSendPrivateMessage(uid, gjson.Parse(msg), autoEscape))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.JSON(200, s.bot.CQSendPrivateMessage(uid, msg, autoEscape))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendGroupMessage 发送群消息
|
|
||||||
func SendGroupMessage(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
msg, t := getParamWithType(c, "message")
|
|
||||||
autoEscape := global.EnsureBool(getParam(c, "auto_escape"), false)
|
|
||||||
if t == gjson.JSON {
|
|
||||||
c.JSON(200, s.bot.CQSendGroupMessage(gid, gjson.Parse(msg), autoEscape))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.JSON(200, s.bot.CQSendGroupMessage(gid, msg, autoEscape))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendGroupForwardMessage 扩展API-发送合并转发(群)
|
|
||||||
func SendGroupForwardMessage(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
msg := getParam(c, "messages")
|
|
||||||
c.JSON(200, s.bot.CQSendGroupForwardMessage(gid, gjson.Parse(msg)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetImage 获取图片(修改自OneBot)
|
|
||||||
func GetImage(s *httpServer, c *gin.Context) {
|
|
||||||
file := getParam(c, "file")
|
|
||||||
c.JSON(200, s.bot.CQGetImage(file))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMessage 获取消息
|
|
||||||
func GetMessage(s *httpServer, c *gin.Context) {
|
|
||||||
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 32)
|
|
||||||
c.JSON(200, s.bot.CQGetMessage(int32(mid)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGroupHonorInfo 获取群荣誉信息
|
|
||||||
func GetGroupHonorInfo(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQGetGroupHonorInfo(gid, getParam(c, "type")))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProcessFriendRequest 处理加好友请求
|
|
||||||
func ProcessFriendRequest(s *httpServer, c *gin.Context) {
|
|
||||||
flag := getParam(c, "flag")
|
|
||||||
approve := getParamOrDefault(c, "approve", "true")
|
|
||||||
c.JSON(200, s.bot.CQProcessFriendRequest(flag, approve == "true"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProcessGroupRequest 处理加群请求/邀请
|
|
||||||
func ProcessGroupRequest(s *httpServer, c *gin.Context) {
|
|
||||||
flag := getParam(c, "flag")
|
|
||||||
subType := getParam(c, "sub_type")
|
|
||||||
if subType == "" {
|
|
||||||
subType = getParam(c, "type")
|
|
||||||
}
|
|
||||||
approve := getParamOrDefault(c, "approve", "true")
|
|
||||||
c.JSON(200, s.bot.CQProcessGroupRequest(flag, subType, getParam(c, "reason"), approve == "true"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetGroupCard 设置群名片(群备注)
|
|
||||||
func SetGroupCard(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQSetGroupCard(gid, uid, getParam(c, "card")))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetSpecialTitle 设置群组专属头衔
|
|
||||||
func SetSpecialTitle(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQSetGroupSpecialTitle(gid, uid, getParam(c, "special_title")))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetGroupKick 群组踢人
|
|
||||||
func SetGroupKick(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
|
||||||
msg := getParam(c, "message")
|
|
||||||
block := getParamOrDefault(c, "reject_add_request", "false")
|
|
||||||
c.JSON(200, s.bot.CQSetGroupKick(gid, uid, msg, block == "true"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetGroupBan 群组单人禁言
|
|
||||||
func SetGroupBan(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
|
||||||
i, _ := strconv.ParseInt(getParamOrDefault(c, "duration", "1800"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQSetGroupBan(gid, uid, uint32(i)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetWholeBan 群组全员禁言
|
|
||||||
func SetWholeBan(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQSetGroupWholeBan(gid, getParamOrDefault(c, "enable", "true") == "true"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetGroupName 设置群名
|
|
||||||
func SetGroupName(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQSetGroupName(gid, getParam(c, "group_name")))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetGroupAdmin 群组设置管理员
|
|
||||||
func SetGroupAdmin(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQSetGroupAdmin(gid, uid, getParamOrDefault(c, "enable", "true") == "true"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendGroupNotice 扩展API-发送群公告
|
|
||||||
func SendGroupNotice(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQSetGroupMemo(gid, getParam(c, "content")))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetGroupLeave 退出群组
|
|
||||||
func SetGroupLeave(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQSetGroupLeave(gid))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetRestart 重启 OneBot 实现
|
|
||||||
//
|
|
||||||
// https://git.io/JtwkJ
|
|
||||||
func SetRestart(s *httpServer, c *gin.Context) {
|
|
||||||
delay, _ := strconv.ParseInt(getParam(c, "delay"), 10, 64)
|
|
||||||
c.JSON(200, coolq.MSG{"data": nil, "retcode": 0, "status": "async"})
|
|
||||||
go func(delay int64) {
|
|
||||||
time.Sleep(time.Duration(delay) * time.Millisecond)
|
|
||||||
Restart <- struct{}{}
|
|
||||||
}(delay)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetForwardMessage 获取合并转发消息
|
|
||||||
func GetForwardMessage(s *httpServer, c *gin.Context) {
|
|
||||||
resID := getParam(c, "message_id")
|
|
||||||
if resID == "" {
|
|
||||||
resID = getParam(c, "id")
|
|
||||||
}
|
|
||||||
c.JSON(200, s.bot.CQGetForwardMessage(resID))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGroupSystemMessage 扩展API-获取群文件系统消息
|
|
||||||
func GetGroupSystemMessage(s *httpServer, c *gin.Context) {
|
|
||||||
c.JSON(200, s.bot.CQGetGroupSystemMessages())
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteMessage 撤回消息
|
|
||||||
func DeleteMessage(s *httpServer, c *gin.Context) {
|
|
||||||
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 32)
|
|
||||||
c.JSON(200, s.bot.CQDeleteMessage(int32(mid)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// CanSendImage 检查是否可以发送图片(此处永远返回true)
|
|
||||||
func CanSendImage(s *httpServer, c *gin.Context) {
|
|
||||||
c.JSON(200, s.bot.CQCanSendImage())
|
|
||||||
}
|
|
||||||
|
|
||||||
// CanSendRecord 检查是否可以发送语音(此处永远返回true)
|
|
||||||
func CanSendRecord(s *httpServer, c *gin.Context) {
|
|
||||||
c.JSON(200, s.bot.CQCanSendRecord())
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetStatus 获取运行状态
|
|
||||||
func GetStatus(s *httpServer, c *gin.Context) {
|
|
||||||
c.JSON(200, s.bot.CQGetStatus())
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetVersionInfo 获取版本信息
|
|
||||||
func GetVersionInfo(s *httpServer, c *gin.Context) {
|
|
||||||
c.JSON(200, s.bot.CQGetVersionInfo())
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReloadEventFilter 扩展API-重载事件过滤器
|
|
||||||
func ReloadEventFilter(s *httpServer, c *gin.Context) {
|
|
||||||
c.JSON(200, s.bot.CQReloadEventFilter())
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetVipInfo 扩展API-获取VIP信息
|
|
||||||
func GetVipInfo(s *httpServer, c *gin.Context) {
|
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQGetVipInfo(uid))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetStrangerInfo 获取陌生人信息
|
|
||||||
func GetStrangerInfo(s *httpServer, c *gin.Context) {
|
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQGetStrangerInfo(uid))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGroupAtAllRemain 扩展API-获取群 @全体成员 剩余次数
|
|
||||||
func GetGroupAtAllRemain(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQGetAtAllRemain(gid))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetGroupAnonymousBan 群组匿名用户禁言
|
|
||||||
func SetGroupAnonymousBan(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
d, _ := strconv.ParseInt(getParam(c, "duration"), 10, 64)
|
|
||||||
flag := getParam(c, "flag")
|
|
||||||
if flag == "" {
|
|
||||||
flag = getParam(c, "anonymous_flag")
|
|
||||||
}
|
|
||||||
if flag == "" {
|
|
||||||
o := gjson.Parse(getParam(c, "anonymous"))
|
|
||||||
flag = o.Get("flag").String()
|
|
||||||
}
|
|
||||||
c.JSON(200, s.bot.CQSetGroupAnonymousBan(gid, flag, int32(d)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGroupMessageHistory 获取群消息历史记录
|
|
||||||
func GetGroupMessageHistory(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
seq, _ := strconv.ParseInt(getParam(c, "message_seq"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQGetGroupMessageHistory(gid, seq))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetOnlineClients 扩展API-获取当前账号在线客户端列表
|
|
||||||
func GetOnlineClients(s *httpServer, c *gin.Context) {
|
|
||||||
c.JSON(200, s.bot.CQGetOnlineClients(getParamOrDefault(c, "no_cache", "false") == "true"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// HandleQuickOperation 隐藏API-对事件执行快速操作
|
|
||||||
func HandleQuickOperation(s *httpServer, c *gin.Context) {
|
|
||||||
if c.Request.Method != "POST" {
|
|
||||||
c.AbortWithStatus(404)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if i, ok := c.Get("json_body"); ok {
|
|
||||||
body := i.(gjson.Result)
|
|
||||||
c.JSON(200, s.bot.CQHandleQuickOperation(body.Get("context"), body.Get("operation")))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DownloadFile 扩展API-下载文件到缓存目录
|
|
||||||
func DownloadFile(s *httpServer, c *gin.Context) {
|
|
||||||
url := getParam(c, "url")
|
|
||||||
tc, _ := strconv.Atoi(getParam(c, "thread_count"))
|
|
||||||
h, t := getParamWithType(c, "headers")
|
|
||||||
headers := map[string]string{}
|
|
||||||
if t == gjson.Null || t == gjson.String {
|
|
||||||
lines := strings.Split(h, "\r\n")
|
|
||||||
for _, sub := range lines {
|
|
||||||
str := strings.SplitN(sub, "=", 2)
|
|
||||||
if len(str) == 2 {
|
|
||||||
headers[str[0]] = str[1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if t == gjson.JSON {
|
|
||||||
arr := gjson.Parse(h)
|
|
||||||
for _, sub := range arr.Array() {
|
|
||||||
str := strings.SplitN(sub.String(), "=", 2)
|
|
||||||
if len(str) == 2 {
|
|
||||||
headers[str[0]] = str[1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
println(url, tc, h, t)
|
|
||||||
c.JSON(200, s.bot.CQDownloadFile(url, headers, tc))
|
|
||||||
}
|
|
||||||
|
|
||||||
// OcrImage 扩展API-图片OCR
|
|
||||||
func OcrImage(s *httpServer, c *gin.Context) {
|
|
||||||
img := getParam(c, "image")
|
|
||||||
c.JSON(200, s.bot.CQOcrImage(img))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetWordSlices 隐藏API-获取中文分词
|
|
||||||
func GetWordSlices(s *httpServer, c *gin.Context) {
|
|
||||||
content := getParam(c, "content")
|
|
||||||
c.JSON(200, s.bot.CQGetWordSlices(content))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetGroupPortrait 扩展API-设置群头像
|
|
||||||
func SetGroupPortrait(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
file := getParam(c, "file")
|
|
||||||
cache := getParam(c, "cache")
|
|
||||||
c.JSON(200, s.bot.CQSetGroupPortrait(gid, file, cache))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetEssenceMsg 扩展API-设置精华消息
|
|
||||||
func SetEssenceMsg(s *httpServer, c *gin.Context) {
|
|
||||||
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQSetEssenceMessage(int32(mid)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteEssenceMsg 扩展API-移出精华消息
|
|
||||||
func DeleteEssenceMsg(s *httpServer, c *gin.Context) {
|
|
||||||
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQDeleteEssenceMessage(int32(mid)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetEssenceMsgList 扩展API-获取精华消息列表
|
|
||||||
func GetEssenceMsgList(s *httpServer, c *gin.Context) {
|
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
|
||||||
c.JSON(200, s.bot.CQGetEssenceMessageList(gid))
|
|
||||||
}
|
|
||||||
|
|
||||||
// CheckURLSafely 扩展API-检查链接安全性
|
|
||||||
func CheckURLSafely(s *httpServer, c *gin.Context) {
|
|
||||||
c.JSON(200, s.bot.CQCheckURLSafely(getParam(c, "url")))
|
|
||||||
}
|
|
||||||
|
|
||||||
func getParamOrDefault(c *gin.Context, k, def string) string {
|
|
||||||
r := getParam(c, k)
|
|
||||||
if r != "" {
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
return def
|
|
||||||
}
|
|
||||||
|
|
||||||
func getParam(c *gin.Context, k string) string {
|
|
||||||
p, _ := getParamWithType(c, k)
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
func getParamWithType(c *gin.Context, k string) (string, gjson.Type) {
|
|
||||||
if q := c.Query(k); q != "" {
|
if q := c.Query(k); q != "" {
|
||||||
return q, gjson.Null
|
return gjson.Result{Type: gjson.String, Str: q}
|
||||||
}
|
}
|
||||||
if c.Request.Method == "POST" {
|
if c.Request.Method == "POST" {
|
||||||
if h := c.Request.Header.Get("Content-Type"); h != "" {
|
if h := c.Request.Header.Get("Content-Type"); h != "" {
|
||||||
if strings.Contains(h, "application/x-www-form-urlencoded") {
|
if strings.Contains(h, "application/x-www-form-urlencoded") {
|
||||||
if p, ok := c.GetPostForm(k); ok {
|
if p, ok := c.GetPostForm(k); ok {
|
||||||
return p, gjson.Null
|
return gjson.Result{Type: gjson.String, Str: p}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if strings.Contains(h, "application/json") {
|
if strings.Contains(h, "application/json") {
|
||||||
if obj, ok := c.Get("json_body"); ok {
|
if obj, ok := c.Get("json_body"); ok {
|
||||||
res := obj.(gjson.Result).Get(k)
|
return obj.(gjson.Result).Get(k)
|
||||||
if res.Exists() {
|
|
||||||
switch res.Type {
|
|
||||||
case gjson.JSON:
|
|
||||||
return res.Raw, gjson.JSON
|
|
||||||
case gjson.String:
|
|
||||||
return res.Str, gjson.String
|
|
||||||
case gjson.Number:
|
|
||||||
return strconv.FormatInt(res.Int(), 10), gjson.Number // 似乎没有需要接受 float 类型的api
|
|
||||||
case gjson.True:
|
|
||||||
return "true", gjson.True
|
|
||||||
case gjson.False:
|
|
||||||
return "false", gjson.False
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return gjson.Result{Type: gjson.Null, Str: ""}
|
||||||
}
|
|
||||||
return "", gjson.Null
|
|
||||||
}
|
|
||||||
|
|
||||||
var httpAPI = map[string]func(s *httpServer, c *gin.Context){
|
|
||||||
"get_login_info": GetLoginInfo,
|
|
||||||
"get_friend_list": GetFriendList,
|
|
||||||
"get_group_list": GetGroupList,
|
|
||||||
"get_group_info": GetGroupInfo,
|
|
||||||
"get_group_member_list": GetGroupMemberList,
|
|
||||||
"get_group_member_info": GetGroupMemberInfo,
|
|
||||||
"get_group_file_system_info": GetGroupFileSystemInfo,
|
|
||||||
"get_group_root_files": GetGroupRootFiles,
|
|
||||||
"get_group_files_by_folder": GetGroupFilesByFolderID,
|
|
||||||
"get_group_file_url": GetGroupFileURL,
|
|
||||||
"upload_group_file": UploadGroupFile,
|
|
||||||
"get_essence_msg_list": GetEssenceMsgList,
|
|
||||||
"send_msg": SendMessage,
|
|
||||||
"send_group_msg": SendGroupMessage,
|
|
||||||
"send_group_forward_msg": SendGroupForwardMessage,
|
|
||||||
"send_private_msg": SendPrivateMessage,
|
|
||||||
"delete_msg": DeleteMessage,
|
|
||||||
"delete_essence_msg": DeleteEssenceMsg,
|
|
||||||
"set_friend_add_request": ProcessFriendRequest,
|
|
||||||
"set_group_add_request": ProcessGroupRequest,
|
|
||||||
"set_group_card": SetGroupCard,
|
|
||||||
"set_group_special_title": SetSpecialTitle,
|
|
||||||
"set_group_kick": SetGroupKick,
|
|
||||||
"set_group_ban": SetGroupBan,
|
|
||||||
"set_group_whole_ban": SetWholeBan,
|
|
||||||
"set_group_name": SetGroupName,
|
|
||||||
"set_group_admin": SetGroupAdmin,
|
|
||||||
"set_essence_msg": SetEssenceMsg,
|
|
||||||
"set_restart": SetRestart,
|
|
||||||
"_send_group_notice": SendGroupNotice,
|
|
||||||
"set_group_leave": SetGroupLeave,
|
|
||||||
"get_image": GetImage,
|
|
||||||
"get_forward_msg": GetForwardMessage,
|
|
||||||
"get_msg": GetMessage,
|
|
||||||
"get_group_system_msg": GetGroupSystemMessage,
|
|
||||||
"get_group_honor_info": GetGroupHonorInfo,
|
|
||||||
"can_send_image": CanSendImage,
|
|
||||||
"can_send_record": CanSendRecord,
|
|
||||||
"get_status": GetStatus,
|
|
||||||
"get_version_info": GetVersionInfo,
|
|
||||||
"_get_vip_info": GetVipInfo,
|
|
||||||
"get_stranger_info": GetStrangerInfo,
|
|
||||||
"reload_event_filter": ReloadEventFilter,
|
|
||||||
"set_group_portrait": SetGroupPortrait,
|
|
||||||
"set_group_anonymous_ban": SetGroupAnonymousBan,
|
|
||||||
"get_group_msg_history": GetGroupMessageHistory,
|
|
||||||
"check_url_safely": CheckURLSafely,
|
|
||||||
"download_file": DownloadFile,
|
|
||||||
".handle_quick_operation": HandleQuickOperation,
|
|
||||||
".ocr_image": OcrImage,
|
|
||||||
"ocr_image": OcrImage,
|
|
||||||
"get_group_at_all_remain": GetGroupAtAllRemain,
|
|
||||||
"get_online_clients": GetOnlineClients,
|
|
||||||
".get_word_slices": GetWordSlices,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) ShutDown() {
|
func (s *httpServer) ShutDown() {
|
||||||
|
@ -38,6 +38,7 @@ type WebSocketClient struct {
|
|||||||
type webSocketConn struct {
|
type webSocketConn struct {
|
||||||
*websocket.Conn
|
*websocket.Conn
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
apiCaller apiCaller
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebSocketServer 初始化一个WebSocketServer实例
|
// WebSocketServer 初始化一个WebSocketServer实例
|
||||||
@ -106,7 +107,7 @@ func (c *WebSocketClient) connectAPI() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("已连接到反向WebSocket API服务器 %v", c.conf.ReverseAPIURL)
|
log.Infof("已连接到反向WebSocket API服务器 %v", c.conf.ReverseAPIURL)
|
||||||
wrappedConn := &webSocketConn{Conn: conn}
|
wrappedConn := &webSocketConn{Conn: conn, apiCaller: apiCaller{c.bot}}
|
||||||
go c.listenAPI(wrappedConn, false)
|
go c.listenAPI(wrappedConn, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +139,7 @@ func (c *WebSocketClient) connectEvent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("已连接到反向WebSocket Event服务器 %v", c.conf.ReverseEventURL)
|
log.Infof("已连接到反向WebSocket Event服务器 %v", c.conf.ReverseEventURL)
|
||||||
c.eventConn = &webSocketConn{Conn: conn}
|
c.eventConn = &webSocketConn{Conn: conn, apiCaller: apiCaller{c.bot}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WebSocketClient) connectUniversal() {
|
func (c *WebSocketClient) connectUniversal() {
|
||||||
@ -168,7 +169,7 @@ func (c *WebSocketClient) connectUniversal() {
|
|||||||
log.Warnf("反向WebSocket 握手时出现错误: %v", err)
|
log.Warnf("反向WebSocket 握手时出现错误: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wrappedConn := &webSocketConn{Conn: conn}
|
wrappedConn := &webSocketConn{Conn: conn, apiCaller: apiCaller{c.bot}}
|
||||||
go c.listenAPI(wrappedConn, true)
|
go c.listenAPI(wrappedConn, true)
|
||||||
c.universalConn = wrappedConn
|
c.universalConn = wrappedConn
|
||||||
}
|
}
|
||||||
@ -250,7 +251,7 @@ func (s *webSocketServer) event(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
log.Infof("接受 WebSocket 连接: %v (/event)", r.RemoteAddr)
|
log.Infof("接受 WebSocket 连接: %v (/event)", r.RemoteAddr)
|
||||||
|
|
||||||
conn := &webSocketConn{Conn: c}
|
conn := &webSocketConn{Conn: c, apiCaller: apiCaller{s.bot}}
|
||||||
|
|
||||||
s.eventConnMutex.Lock()
|
s.eventConnMutex.Lock()
|
||||||
s.eventConn = append(s.eventConn, conn)
|
s.eventConn = append(s.eventConn, conn)
|
||||||
@ -273,7 +274,7 @@ func (s *webSocketServer) api(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("接受 WebSocket 连接: %v (/api)", r.RemoteAddr)
|
log.Infof("接受 WebSocket 连接: %v (/api)", r.RemoteAddr)
|
||||||
conn := &webSocketConn{Conn: c}
|
conn := &webSocketConn{Conn: c, apiCaller: apiCaller{s.bot}}
|
||||||
go s.listenAPI(conn)
|
go s.listenAPI(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,8 +300,10 @@ func (s *webSocketServer) any(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("接受 WebSocket 连接: %v (/)", r.RemoteAddr)
|
log.Infof("接受 WebSocket 连接: %v (/)", r.RemoteAddr)
|
||||||
conn := &webSocketConn{Conn: c}
|
conn := &webSocketConn{Conn: c, apiCaller: apiCaller{s.bot}}
|
||||||
|
s.eventConnMutex.Lock()
|
||||||
s.eventConn = append(s.eventConn, conn)
|
s.eventConn = append(s.eventConn, conn)
|
||||||
|
s.eventConnMutex.Unlock()
|
||||||
s.listenAPI(conn)
|
s.listenAPI(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,7 +321,7 @@ func (s *webSocketServer) listenAPI(c *webSocketConn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *webSocketConn) handleRequest(bot *coolq.CQBot, payload []byte) {
|
func (c *webSocketConn) handleRequest(_ *coolq.CQBot, payload []byte) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
log.Printf("处置WS命令时发生无法恢复的异常:%v\n%s", err, debug.Stack())
|
log.Printf("处置WS命令时发生无法恢复的异常:%v\n%s", err, debug.Stack())
|
||||||
@ -329,23 +332,13 @@ func (c *webSocketConn) handleRequest(bot *coolq.CQBot, payload []byte) {
|
|||||||
j := gjson.ParseBytes(payload)
|
j := gjson.ParseBytes(payload)
|
||||||
t := strings.ReplaceAll(j.Get("action").Str, "_async", "")
|
t := strings.ReplaceAll(j.Get("action").Str, "_async", "")
|
||||||
log.Debugf("WS接收到API调用: %v 参数: %v", t, j.Get("params").Raw)
|
log.Debugf("WS接收到API调用: %v 参数: %v", t, j.Get("params").Raw)
|
||||||
if f, ok := wsAPI[t]; ok {
|
ret := c.apiCaller.callAPI(t, j.Get("params"))
|
||||||
ret := f(bot, j.Get("params"))
|
|
||||||
if j.Get("echo").Exists() {
|
if j.Get("echo").Exists() {
|
||||||
ret["echo"] = j.Get("echo").Value()
|
ret["echo"] = j.Get("echo").Value()
|
||||||
}
|
}
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
_ = c.WriteJSON(ret)
|
_ = c.WriteJSON(ret)
|
||||||
} else {
|
|
||||||
ret := coolq.Failed(1404, "API_NOT_FOUND", "API不存在")
|
|
||||||
if j.Get("echo").Exists() {
|
|
||||||
ret["echo"] = j.Get("echo").Value()
|
|
||||||
}
|
|
||||||
c.Lock()
|
|
||||||
defer c.Unlock()
|
|
||||||
_ = c.WriteJSON(ret)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *webSocketServer) onBotPushEvent(m coolq.MSG) {
|
func (s *webSocketServer) onBotPushEvent(m coolq.MSG) {
|
||||||
@ -371,254 +364,3 @@ func (s *webSocketServer) onBotPushEvent(m coolq.MSG) {
|
|||||||
conn.Unlock()
|
conn.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var wsAPI = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
|
||||||
"get_login_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetLoginInfo()
|
|
||||||
},
|
|
||||||
"get_friend_list": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetFriendList()
|
|
||||||
},
|
|
||||||
"get_group_list": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetGroupList(p.Get("no_cache").Bool())
|
|
||||||
},
|
|
||||||
"get_group_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetGroupInfo(p.Get("group_id").Int(), p.Get("no_cache").Bool())
|
|
||||||
},
|
|
||||||
"get_group_member_list": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetGroupMemberList(p.Get("group_id").Int(), p.Get("no_cache").Bool())
|
|
||||||
},
|
|
||||||
"get_group_member_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetGroupMemberInfo(
|
|
||||||
p.Get("group_id").Int(), p.Get("user_id").Int(),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
"send_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
autoEscape := global.EnsureBool(p.Get("auto_escape"), false)
|
|
||||||
if p.Get("message_type").Str == "private" {
|
|
||||||
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"), autoEscape)
|
|
||||||
}
|
|
||||||
if p.Get("message_type").Str == "group" {
|
|
||||||
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
|
||||||
}
|
|
||||||
if p.Get("group_id").Int() != 0 {
|
|
||||||
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
|
||||||
}
|
|
||||||
if p.Get("user_id").Int() != 0 {
|
|
||||||
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"), autoEscape)
|
|
||||||
}
|
|
||||||
return coolq.MSG{}
|
|
||||||
},
|
|
||||||
"send_group_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), global.EnsureBool(p.Get("auto_escape"), false))
|
|
||||||
},
|
|
||||||
"send_group_forward_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQSendGroupForwardMessage(p.Get("group_id").Int(), p.Get("messages"))
|
|
||||||
},
|
|
||||||
"send_private_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"), global.EnsureBool(p.Get("auto_escape"), false))
|
|
||||||
},
|
|
||||||
"delete_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQDeleteMessage(int32(p.Get("message_id").Int()))
|
|
||||||
},
|
|
||||||
"set_friend_add_request": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
apr := true
|
|
||||||
if p.Get("approve").Exists() {
|
|
||||||
apr = p.Get("approve").Bool()
|
|
||||||
}
|
|
||||||
return bot.CQProcessFriendRequest(p.Get("flag").Str, apr)
|
|
||||||
},
|
|
||||||
"set_group_add_request": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
subType := p.Get("sub_type").Str
|
|
||||||
apr := true
|
|
||||||
if subType == "" {
|
|
||||||
subType = p.Get("type").Str
|
|
||||||
}
|
|
||||||
if p.Get("approve").Exists() {
|
|
||||||
apr = p.Get("approve").Bool()
|
|
||||||
}
|
|
||||||
return bot.CQProcessGroupRequest(p.Get("flag").Str, subType, p.Get("reason").Str, apr)
|
|
||||||
},
|
|
||||||
"set_group_card": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQSetGroupCard(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("card").Str)
|
|
||||||
},
|
|
||||||
"set_group_special_title": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQSetGroupSpecialTitle(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("special_title").Str)
|
|
||||||
},
|
|
||||||
"set_group_kick": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQSetGroupKick(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("message").Str, p.Get("reject_add_request").Bool())
|
|
||||||
},
|
|
||||||
"set_group_ban": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQSetGroupBan(p.Get("group_id").Int(), p.Get("user_id").Int(), func() uint32 {
|
|
||||||
if p.Get("duration").Exists() {
|
|
||||||
return uint32(p.Get("duration").Int())
|
|
||||||
}
|
|
||||||
return 1800
|
|
||||||
}())
|
|
||||||
},
|
|
||||||
"set_group_whole_ban": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQSetGroupWholeBan(p.Get("group_id").Int(), func() bool {
|
|
||||||
if p.Get("enable").Exists() {
|
|
||||||
return p.Get("enable").Bool()
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}())
|
|
||||||
},
|
|
||||||
"set_group_name": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQSetGroupName(p.Get("group_id").Int(), p.Get("group_name").Str)
|
|
||||||
},
|
|
||||||
"set_group_admin": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQSetGroupAdmin(p.Get("group_id").Int(), p.Get("user_id").Int(), func() bool {
|
|
||||||
if p.Get("enable").Exists() {
|
|
||||||
return p.Get("enable").Bool()
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}())
|
|
||||||
},
|
|
||||||
"_send_group_notice": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQSetGroupMemo(p.Get("group_id").Int(), p.Get("content").Str)
|
|
||||||
},
|
|
||||||
"set_group_leave": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQSetGroupLeave(p.Get("group_id").Int())
|
|
||||||
},
|
|
||||||
"get_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetImage(p.Get("file").Str)
|
|
||||||
},
|
|
||||||
"get_forward_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
id := p.Get("message_id").Str
|
|
||||||
if id == "" {
|
|
||||||
id = p.Get("id").Str
|
|
||||||
}
|
|
||||||
return bot.CQGetForwardMessage(id)
|
|
||||||
},
|
|
||||||
"get_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetMessage(int32(p.Get("message_id").Int()))
|
|
||||||
},
|
|
||||||
"download_file": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
headers := map[string]string{}
|
|
||||||
headersToken := p.Get("headers")
|
|
||||||
if headersToken.IsArray() {
|
|
||||||
for _, sub := range headersToken.Array() {
|
|
||||||
str := strings.SplitN(sub.String(), "=", 2)
|
|
||||||
if len(str) == 2 {
|
|
||||||
headers[str[0]] = str[1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if headersToken.Type == gjson.String {
|
|
||||||
lines := strings.Split(headersToken.String(), "\r\n")
|
|
||||||
for _, sub := range lines {
|
|
||||||
str := strings.SplitN(sub, "=", 2)
|
|
||||||
if len(str) == 2 {
|
|
||||||
headers[str[0]] = str[1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bot.CQDownloadFile(p.Get("url").Str, headers, int(p.Get("thread_count").Int()))
|
|
||||||
},
|
|
||||||
"get_group_honor_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetGroupHonorInfo(p.Get("group_id").Int(), p.Get("type").Str)
|
|
||||||
},
|
|
||||||
"set_restart": func(c *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
var delay int64
|
|
||||||
delay = p.Get("delay").Int()
|
|
||||||
if delay < 0 {
|
|
||||||
delay = 0
|
|
||||||
}
|
|
||||||
defer func(delay int64) {
|
|
||||||
time.Sleep(time.Duration(delay) * time.Millisecond)
|
|
||||||
Restart <- struct{}{}
|
|
||||||
}(delay)
|
|
||||||
return coolq.MSG{"data": nil, "retcode": 0, "status": "async"}
|
|
||||||
|
|
||||||
},
|
|
||||||
"can_send_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQCanSendImage()
|
|
||||||
},
|
|
||||||
"can_send_record": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQCanSendRecord()
|
|
||||||
},
|
|
||||||
"get_stranger_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetStrangerInfo(p.Get("user_id").Int())
|
|
||||||
},
|
|
||||||
"get_status": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetStatus()
|
|
||||||
},
|
|
||||||
"get_version_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetVersionInfo()
|
|
||||||
},
|
|
||||||
"get_group_system_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetGroupSystemMessages()
|
|
||||||
},
|
|
||||||
"get_group_file_system_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetGroupFileSystemInfo(p.Get("group_id").Int())
|
|
||||||
},
|
|
||||||
"get_group_root_files": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetGroupRootFiles(p.Get("group_id").Int())
|
|
||||||
},
|
|
||||||
"get_group_files_by_folder": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetGroupFilesByFolderID(p.Get("group_id").Int(), p.Get("folder_id").Str)
|
|
||||||
},
|
|
||||||
"get_group_file_url": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetGroupFileURL(p.Get("group_id").Int(), p.Get("file_id").Str, int32(p.Get("busid").Int()))
|
|
||||||
},
|
|
||||||
"upload_group_file": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQUploadGroupFile(p.Get("group_id").Int(), p.Get("file").Str, p.Get("name").Str, p.Get("folder").Str)
|
|
||||||
},
|
|
||||||
"get_group_msg_history": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetGroupMessageHistory(p.Get("group_id").Int(), p.Get("message_seq").Int())
|
|
||||||
},
|
|
||||||
"_get_vip_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetVipInfo(p.Get("user_id").Int())
|
|
||||||
},
|
|
||||||
"reload_event_filter": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQReloadEventFilter()
|
|
||||||
},
|
|
||||||
".ocr_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQOcrImage(p.Get("image").Str)
|
|
||||||
},
|
|
||||||
"ocr_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQOcrImage(p.Get("image").Str)
|
|
||||||
},
|
|
||||||
"get_group_at_all_remain": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetAtAllRemain(p.Get("group_id").Int())
|
|
||||||
},
|
|
||||||
"get_online_clients": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetOnlineClients(p.Get("no_cache").Bool())
|
|
||||||
},
|
|
||||||
".get_word_slices": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetWordSlices(p.Get("content").Str)
|
|
||||||
},
|
|
||||||
"set_group_portrait": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
|
|
||||||
},
|
|
||||||
"set_essence_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQSetEssenceMessage(int32(p.Get("message_id").Int()))
|
|
||||||
},
|
|
||||||
"delete_essence_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQDeleteEssenceMessage(int32(p.Get("message_id").Int()))
|
|
||||||
},
|
|
||||||
"get_essence_msg_list": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQGetEssenceMessageList(p.Get("group_id").Int())
|
|
||||||
},
|
|
||||||
"check_url_safely": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQCheckURLSafely(p.Get("url").String())
|
|
||||||
},
|
|
||||||
"set_group_anonymous_ban": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
obj := p.Get("anonymous")
|
|
||||||
flag := p.Get("anonymous_flag")
|
|
||||||
if !flag.Exists() {
|
|
||||||
flag = p.Get("flag")
|
|
||||||
}
|
|
||||||
if !flag.Exists() && !obj.Exists() {
|
|
||||||
return coolq.Failed(100, "FLAG_NOT_FOUND", "flag未找到")
|
|
||||||
}
|
|
||||||
if !flag.Exists() {
|
|
||||||
flag = obj.Get("flag")
|
|
||||||
}
|
|
||||||
return bot.CQSetGroupAnonymousBan(p.Get("group_id").Int(), flag.String(), int32(p.Get("duration").Int()))
|
|
||||||
},
|
|
||||||
".handle_quick_operation": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
|
||||||
return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation"))
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user