mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-30 11:53:25 +00:00
Compare commits
59 Commits
Author | SHA1 | Date | |
---|---|---|---|
2ec7f83d38 | |||
06f4a10cf7 | |||
b229b9e543 | |||
6effdcc58c | |||
99767029be | |||
2dca0a3e9f | |||
053d62ff4a | |||
34d2d4fbe2 | |||
8094553bdb | |||
9b7ba6fda6 | |||
59cce1d568 | |||
7e4d55e440 | |||
f181726c2c | |||
e6ebb9cfb2 | |||
c20a8cd99c | |||
674c797076 | |||
94ebee6afe | |||
ff09c0da3e | |||
d3f91c1166 | |||
b93a3c14b5 | |||
fe8b0fabc4 | |||
f70398342e | |||
d5bff2ad8b | |||
e754bd36ed | |||
fb47a66931 | |||
4be73b2834 | |||
e2227d582a | |||
06fccbd9ef | |||
81d2ad3e79 | |||
977337914d | |||
6780615d45 | |||
2670c84c8e | |||
e2b6c3d607 | |||
58a3f81142 | |||
64cb539c0d | |||
3bb844d1d4 | |||
0fdb01e82c | |||
7cf199189a | |||
3aea70e92a | |||
d1505ec15d | |||
750a01acdd | |||
a12dcfa2d7 | |||
86422c5a00 | |||
f3b43bc64c | |||
57153d2d4a | |||
b73aeb6666 | |||
a215028ac0 | |||
d076f174bb | |||
5c8fa7f9a0 | |||
9c95a906b6 | |||
87beb55ca1 | |||
557400b343 | |||
0a6ddb0810 | |||
e6ffa9fbe5 | |||
56ca382a9b | |||
549525236d | |||
f19c76d4e1 | |||
700a056a17 | |||
2a6b9925f8 |
52
.github/workflows/ci.yml
vendored
Normal file
52
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
env:
|
||||||
|
BINARY_PREFIX: "go-cqhttp_"
|
||||||
|
BINARY_SUFFIX: ""
|
||||||
|
PR_PROMPT: "::warning:: Build artifact will not be uploaded due to the workflow is trigged by pull request."
|
||||||
|
LD_FLAGS: "-w -s"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build binary CI
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/386, darwin/amd64
|
||||||
|
goos: [linux, windows, darwin]
|
||||||
|
goarch: ["386", amd64, arm]
|
||||||
|
exclude:
|
||||||
|
- goos: darwin
|
||||||
|
goarch: arm
|
||||||
|
fail-fast: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Go environment
|
||||||
|
uses: actions/setup-go@v2.1.1
|
||||||
|
with:
|
||||||
|
go-version: 1.14
|
||||||
|
|
||||||
|
- name: Build binary file
|
||||||
|
env:
|
||||||
|
GOOS: ${{ matrix.goos }}
|
||||||
|
GOARCH: ${{ matrix.goarch }}
|
||||||
|
IS_PR: ${{ !!github.head_ref }}
|
||||||
|
run: |
|
||||||
|
if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi
|
||||||
|
if $IS_PR ; then echo $PR_PROMPT; fi
|
||||||
|
export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX"
|
||||||
|
export CGO_ENABLED=0
|
||||||
|
go build -o "output/$BINARY_NAME" -ldflags "$LD_FLAGS" .
|
||||||
|
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
if: ${{ !github.head_ref }}
|
||||||
|
with:
|
||||||
|
name: ${{ matrix.goos }}_${{ matrix.goarch }}
|
||||||
|
path: output/
|
||||||
|
|
||||||
|
|
6
.github/workflows/release.yml
vendored
6
.github/workflows/release.yml
vendored
@ -11,9 +11,15 @@ jobs:
|
|||||||
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/386, darwin/amd64
|
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/386, darwin/amd64
|
||||||
goos: [linux, windows, darwin]
|
goos: [linux, windows, darwin]
|
||||||
goarch: ["386", amd64, arm]
|
goarch: ["386", amd64, arm]
|
||||||
|
exclude:
|
||||||
|
- goos: darwin
|
||||||
|
goarch: arm
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: wangyoucao577/go-release-action@master
|
- uses: wangyoucao577/go-release-action@master
|
||||||
|
env:
|
||||||
|
CGO_ENABLED: 0
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
goos: ${{ matrix.goos }}
|
goos: ${{ matrix.goos }}
|
||||||
|
674
LICENSE
674
LICENSE
@ -1,21 +1,661 @@
|
|||||||
MIT License
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
Copyright (c) 2020 Mrs4s
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Preamble
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
copies or substantial portions of the Software.
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
The licenses for most software and other practical works are designed
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
to take away your freedom to share and change the works. By contrast,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
share and change all versions of a program--to make sure it remains free
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
software for all its users.
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
40
README.md
40
README.md
@ -2,17 +2,44 @@
|
|||||||
使用 [mirai](https://github.com/mamoe/mirai) 以及 [MiraiGo](https://github.com/Mrs4s/MiraiGo) 开发的cqhttp golang原生实现, 并在[cqhttp原版](https://github.com/richardchien/coolq-http-api)的基础上做了部分修改和拓展.
|
使用 [mirai](https://github.com/mamoe/mirai) 以及 [MiraiGo](https://github.com/Mrs4s/MiraiGo) 开发的cqhttp golang原生实现, 并在[cqhttp原版](https://github.com/richardchien/coolq-http-api)的基础上做了部分修改和拓展.
|
||||||
文档暂时可查看 `docs` 目录, 目前还在撰写中.
|
文档暂时可查看 `docs` 目录, 目前还在撰写中.
|
||||||
|
|
||||||
|
测试版可前往 Release 下载
|
||||||
|
|
||||||
# 兼容性
|
# 兼容性
|
||||||
|
|
||||||
#### 接口
|
#### 接口
|
||||||
- [x] HTTP API
|
- [x] HTTP API
|
||||||
- [x] 反向HTTP POST (暂不支持回复)
|
- [x] 反向HTTP POST
|
||||||
- [x] 正向Websocket
|
- [x] 正向Websocket
|
||||||
- [ ] 反向Websocket (开发中)
|
- [x] 反向Websocket
|
||||||
|
|
||||||
|
#### 拓展支持
|
||||||
|
> 拓展API可前往 [文档](docs/cqhttp.md) 查看
|
||||||
|
- [x] HTTP POST多点上报
|
||||||
|
- [x] 反向WS多点连接
|
||||||
|
- [x] 修改群名
|
||||||
|
- [x] 消息撤回事件
|
||||||
|
- [x] 解析/发送 回复消息
|
||||||
|
- [x] 解析/发送 合并转发
|
||||||
|
- [ ] 使用代理请求网络图片
|
||||||
|
|
||||||
#### 实现
|
#### 实现
|
||||||
|
<details>
|
||||||
|
<summary>已实现CQ码</summary>
|
||||||
|
|
||||||
|
- [CQ:image]
|
||||||
|
- [CQ:face]
|
||||||
|
- [CQ:at]
|
||||||
|
- [CQ:share]
|
||||||
|
- [CQ:reply]
|
||||||
|
- [CQ:forward]
|
||||||
|
- [CQ:node]
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>已实现API</summary>
|
<summary>已实现API</summary>
|
||||||
|
|
||||||
##### 注意: 部分API实现与CQHTTP原版略有差异,请参考WIKI
|
##### 注意: 部分API实现与CQHTTP原版略有差异,请参考文档
|
||||||
| API | 功能 |
|
| API | 功能 |
|
||||||
| ------------------------ | ------------------------------------------------------------ |
|
| ------------------------ | ------------------------------------------------------------ |
|
||||||
| /get_login_info | [获取登录号信息](https://cqhttp.cc/docs/4.15/#/API?id=get_login_info-获取登录号信息) |
|
| /get_login_info | [获取登录号信息](https://cqhttp.cc/docs/4.15/#/API?id=get_login_info-获取登录号信息) |
|
||||||
@ -32,6 +59,7 @@
|
|||||||
| /set_group_kick | [群组T人](https://cqhttp.cc/docs/4.15/#/API?id=set_group_kick-群组踢人) |
|
| /set_group_kick | [群组T人](https://cqhttp.cc/docs/4.15/#/API?id=set_group_kick-群组踢人) |
|
||||||
| /set_group_ban | [群组单人禁言](https://cqhttp.cc/docs/4.15/#/API?id=set_group_ban-群组单人禁言) |
|
| /set_group_ban | [群组单人禁言](https://cqhttp.cc/docs/4.15/#/API?id=set_group_ban-群组单人禁言) |
|
||||||
| /set_group_whole_ban | [群组全员禁言](https://cqhttp.cc/docs/4.15/#/API?id=set_group_whole_ban-群组全员禁言) |
|
| /set_group_whole_ban | [群组全员禁言](https://cqhttp.cc/docs/4.15/#/API?id=set_group_whole_ban-群组全员禁言) |
|
||||||
|
| /set_group_leave | [退出群组](https://cqhttp.cc/docs/4.15/#/API?id=set_group_leave-退出群组) |
|
||||||
| /set_group_name | 设置群组名(拓展API) |
|
| /set_group_name | 设置群组名(拓展API) |
|
||||||
| /get_image | 获取图片信息(拓展API) |
|
| /get_image | 获取图片信息(拓展API) |
|
||||||
| /get_group_msg | 获取群组消息(拓展API) |
|
| /get_group_msg | 获取群组消息(拓展API) |
|
||||||
@ -45,16 +73,18 @@
|
|||||||
<details>
|
<details>
|
||||||
<summary>已实现Event</summary>
|
<summary>已实现Event</summary>
|
||||||
|
|
||||||
##### 注意: 部分Event数据与CQHTTP原版略有差异,请参考WIKI
|
##### 注意: 部分Event数据与CQHTTP原版略有差异,请参考文档
|
||||||
| Event |
|
| Event |
|
||||||
| ------------------------------------------------------------ |
|
| ------------------------------------------------------------ |
|
||||||
| [私聊信息](https://cqhttp.cc/docs/4.15/#/Post?id=私聊消息) |
|
| [私聊信息](https://cqhttp.cc/docs/4.15/#/Post?id=私聊消息) |
|
||||||
| [群消息](https://cqhttp.cc/docs/4.15/#/Post?id=群消息) |
|
| [群消息](https://cqhttp.cc/docs/4.15/#/Post?id=群消息) |
|
||||||
| [群消息撤回(拓展Event)](docs/cqhttp.md#群消息撤回) |
|
| [群消息撤回(拓展Event)](docs/cqhttp.md#群消息撤回) |
|
||||||
|
| [好友消息撤回(拓展Event)](docs/cqhttp.md#好友消息撤回) |
|
||||||
| [群管理员变动](https://cqhttp.cc/docs/4.15/#/Post?id=群管理员变动) |
|
| [群管理员变动](https://cqhttp.cc/docs/4.15/#/Post?id=群管理员变动) |
|
||||||
| [群成员减少](https://cqhttp.cc/docs/4.15/#/Post?id=群成员减少) |
|
| [群成员减少](https://cqhttp.cc/docs/4.15/#/Post?id=群成员减少) |
|
||||||
| [群成员增加](https://cqhttp.cc/docs/4.15/#/Post?id=群成员增加) |
|
| [群成员增加](https://cqhttp.cc/docs/4.15/#/Post?id=群成员增加) |
|
||||||
| [群禁言](https://cqhttp.cc/docs/4.15/#/Post?id=群禁言) |
|
| [群禁言](https://cqhttp.cc/docs/4.15/#/Post?id=群禁言) |
|
||||||
|
| [群文件上传](https://cqhttp.cc/docs/4.15/#/Post?id=群文件上传)|
|
||||||
| [加好友请求](https://cqhttp.cc/docs/4.15/#/Post?id=加好友请求) |
|
| [加好友请求](https://cqhttp.cc/docs/4.15/#/Post?id=加好友请求) |
|
||||||
| [加群请求/邀请](https://cqhttp.cc/docs/4.15/#/Post?id=加群请求/邀请) |
|
| [加群请求/邀请](https://cqhttp.cc/docs/4.15/#/Post?id=加群请求/邀请) |
|
||||||
|
|
||||||
|
220
coolq/api.go
220
coolq/api.go
@ -6,11 +6,13 @@ import (
|
|||||||
"github.com/Mrs4s/MiraiGo/message"
|
"github.com/Mrs4s/MiraiGo/message"
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=get_login_info-%E8%8E%B7%E5%8F%96%E7%99%BB%E5%BD%95%E5%8F%B7%E4%BF%A1%E6%81%AF
|
// https://cqhttp.cc/docs/4.15/#/API?id=get_login_info-%E8%8E%B7%E5%8F%96%E7%99%BB%E5%BD%95%E5%8F%B7%E4%BF%A1%E6%81%AF
|
||||||
@ -94,11 +96,37 @@ func (bot *CQBot) CQGetGroupMemberInfo(groupId, userId int64, noCache bool) MSG
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF
|
// https://cqhttp.cc/docs/4.15/#/API?id=send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF
|
||||||
func (bot *CQBot) CQSendGroupMessage(groupId int64, msg string) MSG {
|
func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}) MSG {
|
||||||
if msg == "" {
|
var str string
|
||||||
|
if m, ok := i.(gjson.Result); ok {
|
||||||
|
if m.Type == gjson.JSON {
|
||||||
|
elem := bot.ConvertObjectMessage(m, true)
|
||||||
|
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
||||||
|
if mid == -1 {
|
||||||
|
return Failed(100)
|
||||||
|
}
|
||||||
|
return OK(MSG{"message_id": mid})
|
||||||
|
}
|
||||||
|
str = func() string {
|
||||||
|
if m.Str != "" {
|
||||||
|
return m.Str
|
||||||
|
}
|
||||||
|
return m.Raw
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
if s, ok := i.(string); ok {
|
||||||
|
str = s
|
||||||
|
}
|
||||||
|
if str == "" {
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
}
|
}
|
||||||
elem := bot.ConvertStringMessage(msg, true)
|
elem := bot.ConvertStringMessage(str, true)
|
||||||
|
// fix at display
|
||||||
|
for _, e := range elem {
|
||||||
|
if at, ok := e.(*message.AtElement); ok && at.Target != 0 {
|
||||||
|
at.Display = "@" + bot.Client.FindGroup(groupId).FindMember(at.Target).DisplayName()
|
||||||
|
}
|
||||||
|
}
|
||||||
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
@ -106,12 +134,102 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, msg string) MSG {
|
|||||||
return OK(MSG{"message_id": mid})
|
return OK(MSG{"message_id": mid})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF
|
func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
||||||
func (bot *CQBot) CQSendPrivateMessage(userId int64, msg string) MSG {
|
if m.Type != gjson.JSON {
|
||||||
if msg == "" {
|
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
}
|
}
|
||||||
elem := bot.ConvertStringMessage(msg, false)
|
var nodes []*message.ForwardNode
|
||||||
|
ts := time.Now().Add(-time.Minute * 5)
|
||||||
|
hasCustom := func() bool {
|
||||||
|
for _, item := range m.Array() {
|
||||||
|
if item.Get("data.uin").Exists() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}()
|
||||||
|
convert := func(e gjson.Result) {
|
||||||
|
if e.Get("type").Str != "node" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ts.Add(time.Second)
|
||||||
|
if e.Get("data.id").Exists() {
|
||||||
|
i, _ := strconv.Atoi(e.Get("data.id").Str)
|
||||||
|
m := bot.GetGroupMessage(int32(i))
|
||||||
|
if m != nil {
|
||||||
|
sender := m["sender"].(message.Sender)
|
||||||
|
nodes = append(nodes, &message.ForwardNode{
|
||||||
|
SenderId: sender.Uin,
|
||||||
|
SenderName: (&sender).DisplayName(),
|
||||||
|
Time: func() int32 {
|
||||||
|
if hasCustom {
|
||||||
|
return int32(ts.Unix())
|
||||||
|
}
|
||||||
|
return m["time"].(int32)
|
||||||
|
}(),
|
||||||
|
Message: bot.ConvertStringMessage(m["message"].(string), true),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Warnf("警告: 引用消息 %v 错误或数据库未开启.", e.Get("data.id").Str)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uin, _ := strconv.ParseInt(e.Get("data.uin").Str, 10, 64)
|
||||||
|
name := e.Get("data.name").Str
|
||||||
|
content := bot.ConvertObjectMessage(e.Get("data.content"), true)
|
||||||
|
if uin != 0 && name != "" && len(content) > 0 {
|
||||||
|
nodes = append(nodes, &message.ForwardNode{
|
||||||
|
SenderId: uin,
|
||||||
|
SenderName: name,
|
||||||
|
Time: int32(ts.Unix()),
|
||||||
|
Message: content,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Warnf("警告: 非法 Forward node 将跳过")
|
||||||
|
}
|
||||||
|
if m.IsArray() {
|
||||||
|
for _, item := range m.Array() {
|
||||||
|
convert(item)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
convert(m)
|
||||||
|
}
|
||||||
|
if len(nodes) > 0 {
|
||||||
|
gm := bot.Client.SendGroupForwardMessage(groupId, &message.ForwardMessage{Nodes: nodes})
|
||||||
|
return OK(MSG{
|
||||||
|
"message_id": ToGlobalId(groupId, gm.Id),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return Failed(100)
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://cqhttp.cc/docs/4.15/#/API?id=send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF
|
||||||
|
func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}) MSG {
|
||||||
|
var str string
|
||||||
|
if m, ok := i.(gjson.Result); ok {
|
||||||
|
if m.Type == gjson.JSON {
|
||||||
|
elem := bot.ConvertObjectMessage(m, true)
|
||||||
|
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
||||||
|
if mid == -1 {
|
||||||
|
return Failed(100)
|
||||||
|
}
|
||||||
|
return OK(MSG{"message_id": mid})
|
||||||
|
}
|
||||||
|
str = func() string {
|
||||||
|
if m.Str != "" {
|
||||||
|
return m.Str
|
||||||
|
}
|
||||||
|
return m.Raw
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
if s, ok := i.(string); ok {
|
||||||
|
str = s
|
||||||
|
}
|
||||||
|
if str == "" {
|
||||||
|
return Failed(100)
|
||||||
|
}
|
||||||
|
elem := bot.ConvertStringMessage(str, false)
|
||||||
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
@ -180,6 +298,15 @@ func (bot *CQBot) CQSetGroupWholeBan(groupId int64, enable bool) MSG {
|
|||||||
return Failed(100)
|
return Failed(100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_leave-%E9%80%80%E5%87%BA%E7%BE%A4%E7%BB%84
|
||||||
|
func (bot *CQBot) CQSetGroupLeave(groupId int64) MSG {
|
||||||
|
if g := bot.Client.FindGroup(groupId); g != nil {
|
||||||
|
g.Quit()
|
||||||
|
return OK(nil)
|
||||||
|
}
|
||||||
|
return Failed(100)
|
||||||
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_friend_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E5%A5%BD%E5%8F%8B%E8%AF%B7%E6%B1%82
|
// https://cqhttp.cc/docs/4.15/#/API?id=set_friend_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E5%A5%BD%E5%8F%8B%E8%AF%B7%E6%B1%82
|
||||||
func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) MSG {
|
func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) MSG {
|
||||||
req, ok := bot.friendReqCache.Load(flag)
|
req, ok := bot.friendReqCache.Load(flag)
|
||||||
@ -232,6 +359,63 @@ func (bot *CQBot) CQDeleteMessage(messageId int32) MSG {
|
|||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://cqhttp.cc/docs/4.15/#/API?id=-handle_quick_operation-%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%89%A7%E8%A1%8C%E5%BF%AB%E9%80%9F%E6%93%8D%E4%BD%9C
|
||||||
|
// https://github.com/richardchien/coolq-http-api/blob/master/src/cqhttp/plugins/web/http.cpp#L376
|
||||||
|
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
||||||
|
postType := context.Get("post_type").Str
|
||||||
|
switch postType {
|
||||||
|
case "message":
|
||||||
|
msgType := context.Get("message_type").Str
|
||||||
|
reply := operation.Get("reply")
|
||||||
|
if reply.Exists() {
|
||||||
|
/*
|
||||||
|
at := true
|
||||||
|
if operation.Get("at_sender").Exists() {
|
||||||
|
at = operation.Get("at_sender").Bool()
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
// TODO: 处理at字段
|
||||||
|
if msgType == "group" {
|
||||||
|
bot.CQSendGroupMessage(context.Get("group_id").Int(), reply)
|
||||||
|
}
|
||||||
|
if msgType == "private" {
|
||||||
|
bot.CQSendPrivateMessage(context.Get("user_id").Int(), reply)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if msgType == "group" {
|
||||||
|
anonymous := context.Get("anonymous")
|
||||||
|
isAnonymous := anonymous.Type == gjson.Null
|
||||||
|
if operation.Get("delete").Bool() {
|
||||||
|
bot.CQDeleteMessage(int32(context.Get("message_id").Int()))
|
||||||
|
}
|
||||||
|
if operation.Get("kick").Bool() && !isAnonymous {
|
||||||
|
bot.CQSetGroupKick(context.Get("group_id").Int(), context.Get("user_id").Int(), "")
|
||||||
|
}
|
||||||
|
if operation.Get("ban").Bool() {
|
||||||
|
var duration uint32 = 30 * 60
|
||||||
|
if operation.Get("ban_duration").Exists() {
|
||||||
|
duration = uint32(operation.Get("ban_duration").Uint())
|
||||||
|
}
|
||||||
|
// unsupported anonymous ban yet
|
||||||
|
if !isAnonymous {
|
||||||
|
bot.CQSetGroupBan(context.Get("group_id").Int(), context.Get("user_id").Int(), duration)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "request":
|
||||||
|
reqType := context.Get("request_type").Str
|
||||||
|
if context.Get("approve").Bool() {
|
||||||
|
if reqType == "friend" {
|
||||||
|
bot.CQProcessFriendRequest(context.Get("flag").Str, true)
|
||||||
|
}
|
||||||
|
if reqType == "group" {
|
||||||
|
bot.CQProcessGroupRequest(context.Get("flag").Str, context.Get("sub_type").Str, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return OK(nil)
|
||||||
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQGetImage(file string) MSG {
|
func (bot *CQBot) CQGetImage(file string) MSG {
|
||||||
if !global.PathExists(path.Join(global.IMAGE_PATH, file)) {
|
if !global.PathExists(path.Join(global.IMAGE_PATH, file)) {
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
@ -248,6 +432,28 @@ func (bot *CQBot) CQGetImage(file string) MSG {
|
|||||||
return Failed(100)
|
return Failed(100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bot *CQBot) CQGetForwardMessage(resId string) MSG {
|
||||||
|
m := bot.Client.GetForwardMessage(resId)
|
||||||
|
if m == nil {
|
||||||
|
return Failed(100)
|
||||||
|
}
|
||||||
|
var r []MSG
|
||||||
|
for _, n := range m.Nodes {
|
||||||
|
checkImage(n.Message)
|
||||||
|
r = append(r, MSG{
|
||||||
|
"sender": MSG{
|
||||||
|
"user_id": n.SenderId,
|
||||||
|
"nickname": n.SenderName,
|
||||||
|
},
|
||||||
|
"time": n.Time,
|
||||||
|
"content": ToStringMessage(n.Message, 0, false),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return OK(MSG{
|
||||||
|
"messages": r,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQGetGroupMessage(messageId int32) MSG {
|
func (bot *CQBot) CQGetGroupMessage(messageId int32) MSG {
|
||||||
msg := bot.GetGroupMessage(messageId)
|
msg := bot.GetGroupMessage(messageId)
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
|
31
coolq/bot.go
31
coolq/bot.go
@ -38,7 +38,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
|
|||||||
opt.EntryIdxMode = nutsdb.HintBPTSparseIdxMode
|
opt.EntryIdxMode = nutsdb.HintBPTSparseIdxMode
|
||||||
db, err := nutsdb.Open(opt)
|
db, err := nutsdb.Open(opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("打开数据库失败, 如果频繁遇到此问题请关闭数据库功能。")
|
log.Fatalf("打开数据库失败, 如果频繁遇到此问题请清理 data/db 文件夹或关闭数据库功能。")
|
||||||
}
|
}
|
||||||
bot.db = db
|
bot.db = db
|
||||||
gob.Register(message.Sender{})
|
gob.Register(message.Sender{})
|
||||||
@ -51,6 +51,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
|
|||||||
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)
|
||||||
|
bot.Client.OnFriendMessageRecalled(bot.friendRecallEvent)
|
||||||
bot.Client.OnJoinGroup(bot.joinGroupEvent)
|
bot.Client.OnJoinGroup(bot.joinGroupEvent)
|
||||||
bot.Client.OnLeaveGroup(bot.leaveGroupEvent)
|
bot.Client.OnLeaveGroup(bot.leaveGroupEvent)
|
||||||
bot.Client.OnGroupMemberJoined(bot.memberJoinEvent)
|
bot.Client.OnGroupMemberJoined(bot.memberJoinEvent)
|
||||||
@ -75,7 +76,7 @@ func (bot *CQBot) GetGroupMessage(mid int32) MSG {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
buff := new(bytes.Buffer)
|
buff := new(bytes.Buffer)
|
||||||
buff.Write(e.Value)
|
buff.Write(binary.GZipUncompress(e.Value))
|
||||||
return gob.NewDecoder(buff).Decode(&m)
|
return gob.NewDecoder(buff).Decode(&m)
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -92,7 +93,7 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
|
|||||||
if i, ok := elem.(*message.ImageElement); ok {
|
if i, ok := elem.(*message.ImageElement); ok {
|
||||||
gm, err := bot.Client.UploadGroupImage(groupId, i.Data)
|
gm, err := bot.Client.UploadGroupImage(groupId, i.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告: 群 %v 消息图片上传失败.", groupId)
|
log.Warnf("警告: 群 %v 消息图片上传失败: %v", groupId, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newElem = append(newElem, gm)
|
newElem = append(newElem, gm)
|
||||||
@ -135,16 +136,18 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
|
|||||||
"message": ToStringMessage(m.Elements, m.GroupCode, true),
|
"message": ToStringMessage(m.Elements, m.GroupCode, true),
|
||||||
}
|
}
|
||||||
id := ToGlobalId(m.GroupCode, m.Id)
|
id := ToGlobalId(m.GroupCode, m.Id)
|
||||||
err := bot.db.Update(func(tx *nutsdb.Tx) error {
|
if bot.db != nil {
|
||||||
buf := new(bytes.Buffer)
|
err := bot.db.Update(func(tx *nutsdb.Tx) error {
|
||||||
if err := gob.NewEncoder(buf).Encode(val); err != nil {
|
buf := new(bytes.Buffer)
|
||||||
return err
|
if err := gob.NewEncoder(buf).Encode(val); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return tx.Put("group-messages", binary.ToBytes(id), binary.GZipCompress(buf.Bytes()), 0)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("记录聊天数据时出现错误: %v", err)
|
||||||
|
return -1
|
||||||
}
|
}
|
||||||
return tx.Put("group-messages", binary.ToBytes(id), buf.Bytes(), 0)
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Warnf("记录聊天数据时出现错误: %v", err)
|
|
||||||
return -1
|
|
||||||
}
|
}
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
@ -154,7 +157,9 @@ func ToGlobalId(code int64, msgId int32) int32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) Release() {
|
func (bot *CQBot) Release() {
|
||||||
_ = bot.db.Close()
|
if bot.db != nil {
|
||||||
|
_ = bot.db.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) dispatchEventMessage(m MSG) {
|
func (bot *CQBot) dispatchEventMessage(m MSG) {
|
||||||
|
106
coolq/cqcode.go
106
coolq/cqcode.go
@ -2,15 +2,19 @@ package coolq
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Mrs4s/MiraiGo/binary"
|
"github.com/Mrs4s/MiraiGo/binary"
|
||||||
"github.com/Mrs4s/MiraiGo/message"
|
"github.com/Mrs4s/MiraiGo/message"
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -36,6 +40,8 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
|
|||||||
r += fmt.Sprintf("[CQ:at,qq=%d]", o.Target)
|
r += fmt.Sprintf("[CQ:at,qq=%d]", o.Target)
|
||||||
case *message.ReplyElement:
|
case *message.ReplyElement:
|
||||||
r += fmt.Sprintf("[CQ:reply,id=%d]", ToGlobalId(code, o.ReplySeq))
|
r += fmt.Sprintf("[CQ:reply,id=%d]", ToGlobalId(code, o.ReplySeq))
|
||||||
|
case *message.ForwardElement:
|
||||||
|
r += fmt.Sprintf("[CQ:forward,id=%s]", o.ResId)
|
||||||
case *message.FaceElement:
|
case *message.FaceElement:
|
||||||
r += fmt.Sprintf(`[CQ:face,id=%d]`, o.Index)
|
r += fmt.Sprintf(`[CQ:face,id=%d]`, o.Index)
|
||||||
case *message.ImageElement:
|
case *message.ImageElement:
|
||||||
@ -101,6 +107,58 @@ func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessa
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.IMessageElement) {
|
||||||
|
convertElem := func(e gjson.Result) {
|
||||||
|
t := e.Get("type").Str
|
||||||
|
if t == "reply" && group {
|
||||||
|
if len(r) > 0 {
|
||||||
|
if _, ok := r[0].(*message.ReplyElement); ok {
|
||||||
|
log.Warnf("警告: 一条信息只能包含一个 Reply 元素.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mid, err := strconv.Atoi(e.Get("data").Get("id").Str)
|
||||||
|
if err == nil {
|
||||||
|
org := bot.GetGroupMessage(int32(mid))
|
||||||
|
if org != nil {
|
||||||
|
r = append([]message.IMessageElement{
|
||||||
|
&message.ReplyElement{
|
||||||
|
ReplySeq: org["message-id"].(int32),
|
||||||
|
Sender: org["sender"].(message.Sender).Uin,
|
||||||
|
Time: org["time"].(int32),
|
||||||
|
Elements: bot.ConvertStringMessage(org["message"].(string), group),
|
||||||
|
},
|
||||||
|
}, r...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d := make(map[string]string)
|
||||||
|
e.Get("data").ForEach(func(key, value gjson.Result) bool {
|
||||||
|
d[key.Str] = value.Str
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
elem, err := bot.ToElement(t, d, group)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("转换CQ码到MiraiGo Element时出现错误: %v 将忽略本段CQ码.", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r = append(r, elem)
|
||||||
|
}
|
||||||
|
if m.Type == gjson.String {
|
||||||
|
return bot.ConvertStringMessage(m.Str, group)
|
||||||
|
}
|
||||||
|
if m.IsArray() {
|
||||||
|
for _, e := range m.Array() {
|
||||||
|
convertElem(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if m.IsObject() {
|
||||||
|
convertElem(m)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.IMessageElement, error) {
|
func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.IMessageElement, error) {
|
||||||
switch t {
|
switch t {
|
||||||
case "text":
|
case "text":
|
||||||
@ -121,24 +179,58 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
|
|||||||
}
|
}
|
||||||
return message.NewImage(b), nil
|
return message.NewImage(b), nil
|
||||||
}
|
}
|
||||||
if global.PathExists(path.Join(global.IMAGE_PATH, f)) {
|
if strings.HasPrefix(f, "file") {
|
||||||
b, err := ioutil.ReadFile(path.Join(global.IMAGE_PATH, f))
|
fu, err := url.Parse(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(fu.Path, "/") && runtime.GOOS == `windows` {
|
||||||
|
fu.Path = fu.Path[1:]
|
||||||
|
}
|
||||||
|
b, err := ioutil.ReadFile(fu.Path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return message.NewImage(b), nil
|
||||||
|
}
|
||||||
|
rawPath := path.Join(global.IMAGE_PATH, f)
|
||||||
|
if global.PathExists(rawPath) {
|
||||||
|
b, err := ioutil.ReadFile(rawPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if path.Ext(rawPath) != ".image" {
|
||||||
|
return message.NewImage(b), nil
|
||||||
|
}
|
||||||
if len(b) < 20 {
|
if len(b) < 20 {
|
||||||
return nil, errors.New("invalid local file")
|
return nil, errors.New("invalid local file")
|
||||||
}
|
}
|
||||||
r := binary.NewReader(b)
|
var size int32
|
||||||
hash := r.ReadBytes(16)
|
var hash []byte
|
||||||
|
if path.Ext(rawPath) == ".cqimg" {
|
||||||
|
for _, line := range strings.Split(global.ReadAllText(rawPath), "\n") {
|
||||||
|
kv := strings.SplitN(line, "=", 2)
|
||||||
|
switch kv[0] {
|
||||||
|
case "md5":
|
||||||
|
hash, _ = hex.DecodeString(kv[1])
|
||||||
|
case "size":
|
||||||
|
t, _ := strconv.Atoi(kv[1])
|
||||||
|
size = int32(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
r := binary.NewReader(b)
|
||||||
|
hash = r.ReadBytes(16)
|
||||||
|
size = r.ReadInt32()
|
||||||
|
}
|
||||||
if group {
|
if group {
|
||||||
rsp, err := bot.Client.QueryGroupImage(1, hash, r.ReadInt32())
|
rsp, err := bot.Client.QueryGroupImage(1, hash, size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return rsp, nil
|
return rsp, nil
|
||||||
}
|
}
|
||||||
rsp, err := bot.Client.QueryFriendImage(1, hash, r.ReadInt32())
|
rsp, err := bot.Client.QueryFriendImage(1, hash, size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -158,6 +250,8 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
|
|||||||
}
|
}
|
||||||
t, _ := strconv.ParseInt(qq, 10, 64)
|
t, _ := strconv.ParseInt(qq, 10, 64)
|
||||||
return message.NewAt(t), nil
|
return message.NewAt(t), nil
|
||||||
|
case "share":
|
||||||
|
return message.NewUrlShare(d["url"], d["title"], d["content"], d["image"]), nil
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("unsupported cq code: " + t)
|
return nil, errors.New("unsupported cq code: " + t)
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ func (bot *CQBot) privateMessageEvent(c *client.QQClient, m *message.PrivateMess
|
|||||||
"post_type": "message",
|
"post_type": "message",
|
||||||
"message_type": "private",
|
"message_type": "private",
|
||||||
"sub_type": "friend",
|
"sub_type": "friend",
|
||||||
"message_id": m.Id,
|
"message_id": ToGlobalId(m.Sender.Uin, m.Id),
|
||||||
"user_id": m.Sender.Uin,
|
"user_id": m.Sender.Uin,
|
||||||
"message": ToStringMessage(m.Elements, 0, false),
|
"message": ToStringMessage(m.Elements, 0, false),
|
||||||
"raw_message": cqm,
|
"raw_message": cqm,
|
||||||
@ -40,6 +40,27 @@ func (bot *CQBot) privateMessageEvent(c *client.QQClient, m *message.PrivateMess
|
|||||||
|
|
||||||
func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage) {
|
func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage) {
|
||||||
checkImage(m.Elements)
|
checkImage(m.Elements)
|
||||||
|
for _, elem := range m.Elements {
|
||||||
|
if file, ok := elem.(*message.GroupFileElement); ok {
|
||||||
|
log.Infof("群 %v(%v) 内 %v(%v) 上传了文件: %v", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, file.Name)
|
||||||
|
bot.dispatchEventMessage(MSG{
|
||||||
|
"post_type": "notice",
|
||||||
|
"notice_type": "group_upload",
|
||||||
|
"group_id": m.GroupCode,
|
||||||
|
"user_id": m.Sender.Uin,
|
||||||
|
"file": MSG{
|
||||||
|
"id": file.Path,
|
||||||
|
"name": file.Name,
|
||||||
|
"size": file.Size,
|
||||||
|
"busid": file.Busid,
|
||||||
|
"url": c.GetGroupFileUrl(m.GroupCode, file.Path, file.Busid),
|
||||||
|
},
|
||||||
|
"self_id": c.Uin,
|
||||||
|
"time": time.Now().Unix(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
cqm := ToStringMessage(m.Elements, m.GroupCode, true)
|
cqm := ToStringMessage(m.Elements, m.GroupCode, true)
|
||||||
id := m.Id
|
id := m.Id
|
||||||
if bot.db != nil {
|
if bot.db != nil {
|
||||||
@ -164,6 +185,20 @@ func (bot *CQBot) groupRecallEvent(c *client.QQClient, e *client.GroupMessageRec
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *client.FriendMessageRecalledEvent) {
|
||||||
|
f := c.FindFriend(e.FriendUin)
|
||||||
|
gid := ToGlobalId(e.FriendUin, e.MessageId)
|
||||||
|
log.Infof("好友 %v(%v) 撤回了消息: %v", f.Nickname, f.Uin, gid)
|
||||||
|
bot.dispatchEventMessage(MSG{
|
||||||
|
"post_type": "notice",
|
||||||
|
"notice_type": "friend_recall",
|
||||||
|
"self_id": c.Uin,
|
||||||
|
"user_id": f.Uin,
|
||||||
|
"time": e.Time,
|
||||||
|
"message_id": gid,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (bot *CQBot) joinGroupEvent(c *client.QQClient, group *client.GroupInfo) {
|
func (bot *CQBot) joinGroupEvent(c *client.QQClient, group *client.GroupInfo) {
|
||||||
log.Infof("Bot进入了群 %v.", formatGroupName(group))
|
log.Infof("Bot进入了群 %v.", formatGroupName(group))
|
||||||
bot.dispatchEventMessage(bot.groupIncrease(group.Code, 0, c.Uin))
|
bot.dispatchEventMessage(bot.groupIncrease(group.Code, 0, c.Uin))
|
||||||
|
@ -20,25 +20,41 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
|
|||||||
"password": "",
|
"password": "",
|
||||||
"enable_db": true,
|
"enable_db": true,
|
||||||
"access_token": "",
|
"access_token": "",
|
||||||
|
"relogin": false,
|
||||||
|
"relogin_delay": 0,
|
||||||
"http_config": {
|
"http_config": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"host": "0.0.0.0",
|
"host": "0.0.0.0",
|
||||||
"port": 5700
|
"port": 5700,
|
||||||
|
"post_urls": []
|
||||||
},
|
},
|
||||||
"ws_config": {
|
"ws_config": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"host": "0.0.0.0",
|
"host": "0.0.0.0",
|
||||||
"port": 6700
|
"port": 6700
|
||||||
}
|
},
|
||||||
|
"ws_reverse_servers": [
|
||||||
|
{
|
||||||
|
"enabled": false,
|
||||||
|
"reverse_url": "ws://you_websocket_universal.server",
|
||||||
|
"reverse_api_url": "ws://you_websocket_api.server",
|
||||||
|
"reverse_event_url": "ws://you_websocket_event.server",
|
||||||
|
"reverse_reconnect_interval": 3000
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
````
|
````
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ------------ | ------ | ------------------------------------------------------------ |
|
| ------------------ | -------- | ------------------------------------------------------------------- |
|
||||||
| uin | int64 | 登录用QQ号 |
|
| uin | int64 | 登录用QQ号 |
|
||||||
| password | string | 登录用密码 |
|
| password | string | 登录用密码 |
|
||||||
| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用 **回复/撤回** 等上下文相关接口 |
|
| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用 **回复/撤回** 等上下文相关接口 |
|
||||||
| access_token | string | 同CQHTTP的 `access_token` 用于身份验证 |
|
| access_token | string | 同CQHTTP的 `access_token` 用于身份验证 |
|
||||||
| http_config | object | HTTP API配置 |
|
| relogin | bool | 是否自动重新登录 |
|
||||||
| ws_config | object | Websocket API 配置 |
|
| relogin_delay | int | 重登录延时(秒) |
|
||||||
|
| http_config | object | HTTP API配置 |
|
||||||
|
| ws_config | object | Websocket API 配置 |
|
||||||
|
| ws_reverse_servers | object[] | 反向 Websocket API 配置 |
|
||||||
|
|
||||||
|
|
||||||
|
200
docs/cqhttp.md
200
docs/cqhttp.md
@ -4,13 +4,128 @@
|
|||||||
|
|
||||||
## CQCode
|
## CQCode
|
||||||
|
|
||||||
| Code | 示例 | 说明 |
|
### 回复
|
||||||
| ----- | -------------------- | ---------------------------------------------------------- |
|
|
||||||
| reply | [CQ:reply,id=123456] | 回复ID为 `123456`的信息. 发送时一条 `message` 仅能使用一次 |
|
Type : `reply`
|
||||||
|
|
||||||
|
范围: **发送/接收**
|
||||||
|
|
||||||
|
参数:
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 说明 |
|
||||||
|
| ------ | ---- | ------------------------------------- |
|
||||||
|
| id | int | 回复时所引用的消息id, 必须为本群消息. |
|
||||||
|
|
||||||
|
示例: `[CQ:reply,id=123456]`
|
||||||
|
|
||||||
|
### 合并转发
|
||||||
|
|
||||||
|
Type: `forward`
|
||||||
|
|
||||||
|
范围: **接收**
|
||||||
|
|
||||||
|
参数:
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 说明 |
|
||||||
|
| ------ | ------ | ------------------------------------------------------------ |
|
||||||
|
| id | string | 合并转发ID, 需要通过 `/get_forward_msg` API获取转发的具体内容 |
|
||||||
|
|
||||||
|
示例: `[CQ:forward,id=xxxx]`
|
||||||
|
|
||||||
|
### 合并转发消息节点
|
||||||
|
|
||||||
|
Type: `node`
|
||||||
|
|
||||||
|
范围: **发送**
|
||||||
|
|
||||||
|
参数:
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 说明 | 特殊说明 |
|
||||||
|
| ------- | ------- | -------------- | ------------------------------------------------------------ |
|
||||||
|
| id | int32 | 转发消息id | 直接引用他人的消息合并转发, 实际查看顺序为原消息发送顺序 **与下面的自定义消息二选一** |
|
||||||
|
| name | string | 发送者显示名字 | 用于自定义消息 (自定义消息并合并转发,实际查看顺序为自定义消息段顺序) |
|
||||||
|
| uin | int64 | 发送者QQ号 | 用于自定义消息 |
|
||||||
|
| content | message | 具体消息 | 用于自定义消息 **不支持转发套娃,不支持引用回复** |
|
||||||
|
|
||||||
|
特殊说明: **需要使用单独的API `/send_group_forward_msg` 发送,并且由于消息段较为复杂,仅支持Array形式入参。 如果引用消息和自定义消息同时出现,实际查看顺序将取消息段顺序. 另外按 [CQHTTP](https://cqhttp.cc/docs/4.15/#/Message?id=格式) 文档说明, `data` 应全为字符串, 但由于需要接收`message` 类型的消息, 所以 *仅限此Type的content字段* 支持Array套娃**
|
||||||
|
|
||||||
|
示例:
|
||||||
|
|
||||||
|
直接引用消息合并转发:
|
||||||
|
|
||||||
|
````json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"data": {
|
||||||
|
"id": "123"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"data": {
|
||||||
|
"id": "456"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
````
|
||||||
|
|
||||||
|
自定义消息合并转发:
|
||||||
|
|
||||||
|
````json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"data": {
|
||||||
|
"name": "消息发送者A",
|
||||||
|
"uin": "10086",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"data": {"text": "测试消息1"}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"data": {
|
||||||
|
"name": "消息发送者B",
|
||||||
|
"uin": "10087",
|
||||||
|
"content": "[CQ:image,file=xxxxx]测试消息2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
````
|
||||||
|
|
||||||
|
引用自定义混合合并转发:
|
||||||
|
|
||||||
|
````json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"data": {
|
||||||
|
"name": "自定义发送者",
|
||||||
|
"uin": "10086",
|
||||||
|
"content": "我是自定义消息"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"data": {
|
||||||
|
"id": "123"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
````
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
`/set_group_name` **设置群名**
|
### 设置群名
|
||||||
|
|
||||||
|
终结点: `/set_group_name`
|
||||||
|
|
||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
@ -19,7 +134,9 @@
|
|||||||
| group_id | int64 | 群号 |
|
| group_id | int64 | 群号 |
|
||||||
| name | string | 新名 |
|
| name | string | 新名 |
|
||||||
|
|
||||||
`/get_image` **获取图片信息**
|
### 获取图片信息
|
||||||
|
|
||||||
|
终结点: `/get_image`
|
||||||
|
|
||||||
> 该接口为 CQHTTP 接口修改
|
> 该接口为 CQHTTP 接口修改
|
||||||
|
|
||||||
@ -37,7 +154,9 @@
|
|||||||
| `filename` | string | 图片文件原名 |
|
| `filename` | string | 图片文件原名 |
|
||||||
| `url` | string | 图片下载地址 |
|
| `url` | string | 图片下载地址 |
|
||||||
|
|
||||||
`/get_group_msg` **获取群消息**
|
### 获取群消息
|
||||||
|
|
||||||
|
终结点: `/get_group_msg`
|
||||||
|
|
||||||
参数
|
参数
|
||||||
|
|
||||||
@ -55,6 +174,64 @@
|
|||||||
| `time` | int32 | 发送时间 |
|
| `time` | int32 | 发送时间 |
|
||||||
| `content` | message | 消息内容 |
|
| `content` | message | 消息内容 |
|
||||||
|
|
||||||
|
### 获取合并转发内容
|
||||||
|
|
||||||
|
终结点: `/get_forward_msg`
|
||||||
|
|
||||||
|
参数
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
| ------------ | ------ | ------ |
|
||||||
|
| `message_id` | string | 消息id |
|
||||||
|
|
||||||
|
响应数据
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
| ---------- | ----------------- | -------- |
|
||||||
|
| `messages` | forward message[] | 消息列表 |
|
||||||
|
|
||||||
|
响应示例
|
||||||
|
|
||||||
|
````json
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"messages": [
|
||||||
|
{
|
||||||
|
"content": "合并转发1",
|
||||||
|
"sender": {
|
||||||
|
"nickname": "发送者A",
|
||||||
|
"user_id": 10086
|
||||||
|
},
|
||||||
|
"time": 1595694374
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": "合并转发2[CQ:image,file=xxxx,url=xxxx]",
|
||||||
|
"sender": {
|
||||||
|
"nickname": "发送者B",
|
||||||
|
"user_id": 10087
|
||||||
|
},
|
||||||
|
"time": 1595694393
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"retcode": 0,
|
||||||
|
"status": "ok"
|
||||||
|
}
|
||||||
|
````
|
||||||
|
|
||||||
|
### 发送合并转发(群)
|
||||||
|
|
||||||
|
终结点: `/send_group_forward_msg`
|
||||||
|
|
||||||
|
**参数**
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
| ---------- | -------------- | ---------------------------- |
|
||||||
|
| `group_id` | int64 | 群号 |
|
||||||
|
| `messages` | forward node[] | 自定义转发消息, 具体看CQCode |
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
## 事件
|
## 事件
|
||||||
|
|
||||||
#### 群消息撤回
|
#### 群消息撤回
|
||||||
@ -70,3 +247,14 @@
|
|||||||
| `operator_id` | int64 | | 操作者id |
|
| `operator_id` | int64 | | 操作者id |
|
||||||
| `message_id` | int64 | | 被撤回的消息id |
|
| `message_id` | int64 | | 被撤回的消息id |
|
||||||
|
|
||||||
|
#### 好友消息撤回
|
||||||
|
|
||||||
|
**上报数据**
|
||||||
|
|
||||||
|
| 字段 | 类型 | 可能的值 | 说明 |
|
||||||
|
| ------------- | ------ | -------------- | -------------- |
|
||||||
|
| `post_type` | string | `notice` | 上报类型 |
|
||||||
|
| `notice_type` | string | `friend_recall`| 消息类型 |
|
||||||
|
| `user_id` | int64 | | 好友id |
|
||||||
|
| `message_id` | int64 | | 被撤回的消息id |
|
||||||
|
|
||||||
|
101
global/art.go
101
global/art.go
@ -1,101 +0,0 @@
|
|||||||
package global
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"golang.org/x/image/font"
|
|
||||||
"golang.org/x/image/font/basicfont"
|
|
||||||
"golang.org/x/image/math/fixed"
|
|
||||||
"image"
|
|
||||||
"image/color"
|
|
||||||
_ "image/jpeg"
|
|
||||||
_ "image/png"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
// https://github.com/xrlin/AsciiArt
|
|
||||||
|
|
||||||
func Convert(f io.Reader, chars []string, subWidth, subHeight int, imageSwitch bool, bgColor, penColor color.RGBA) (string, *image.NRGBA, error) {
|
|
||||||
var charsLength = len(chars)
|
|
||||||
if charsLength == 0 {
|
|
||||||
return "", nil, fmt.Errorf("no chars provided")
|
|
||||||
}
|
|
||||||
if subWidth == 0 || subHeight == 0 {
|
|
||||||
return "", nil, fmt.Errorf("subWidth and subHeight params is required")
|
|
||||||
}
|
|
||||||
m, _, err := image.Decode(f)
|
|
||||||
if err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
imageWidth, imageHeight := m.Bounds().Max.X, m.Bounds().Max.Y
|
|
||||||
var img *image.NRGBA
|
|
||||||
if imageSwitch {
|
|
||||||
img = initImage(imageWidth, imageHeight, bgColor)
|
|
||||||
}
|
|
||||||
piecesX, piecesY := imageWidth/subWidth, imageHeight/subHeight
|
|
||||||
var buff bytes.Buffer
|
|
||||||
for y := 0; y < piecesY; y++ {
|
|
||||||
offsetY := y * subHeight
|
|
||||||
for x := 0; x < piecesX; x++ {
|
|
||||||
offsetX := x * subWidth
|
|
||||||
averageBrightness := calculateAverageBrightness(m, image.Rect(offsetX, offsetY, offsetX+subWidth, offsetY+subHeight))
|
|
||||||
char := getCharByBrightness(chars, averageBrightness)
|
|
||||||
buff.WriteString(char)
|
|
||||||
if img != nil {
|
|
||||||
addCharToImage(img, char, x*subWidth, y*subHeight, penColor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buff.WriteString("\n")
|
|
||||||
}
|
|
||||||
return buff.String(), img, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func initImage(width, height int, bgColor color.RGBA) *image.NRGBA {
|
|
||||||
img := image.NewNRGBA(image.Rect(0, 0, width, height))
|
|
||||||
for x := 0; x < width; x++ {
|
|
||||||
for y := 0; y < height; y++ {
|
|
||||||
img.Set(x, y, bgColor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return img
|
|
||||||
}
|
|
||||||
func calculateAverageBrightness(img image.Image, rect image.Rectangle) float64 {
|
|
||||||
var averageBrightness float64
|
|
||||||
width, height := rect.Max.X-rect.Min.X, rect.Max.Y-rect.Min.Y
|
|
||||||
var brightness float64
|
|
||||||
for x := rect.Min.X; x < rect.Max.X; x++ {
|
|
||||||
for y := rect.Min.Y; y < rect.Max.Y; y++ {
|
|
||||||
r, g, b, _ := img.At(x, y).RGBA()
|
|
||||||
brightness = float64(r>>8+g>>8+b>>8) / 3
|
|
||||||
averageBrightness += brightness
|
|
||||||
}
|
|
||||||
}
|
|
||||||
averageBrightness /= float64(width * height)
|
|
||||||
return averageBrightness
|
|
||||||
}
|
|
||||||
|
|
||||||
func getCharByBrightness(chars []string, brightness float64) string {
|
|
||||||
index := int(brightness*float64(len(chars))) >> 8
|
|
||||||
if index == len(chars) {
|
|
||||||
index--
|
|
||||||
}
|
|
||||||
return chars[len(chars)-index-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
func addCharToImage(img *image.NRGBA, char string, x, y int, penColor color.RGBA) {
|
|
||||||
face := basicfont.Face7x13
|
|
||||||
point := fixed.Point26_6{X: fixed.Int26_6(x * 64), Y: fixed.Int26_6(y * 64)}
|
|
||||||
d := &font.Drawer{
|
|
||||||
Dst: img,
|
|
||||||
Src: image.NewUniform(penColor),
|
|
||||||
Face: face,
|
|
||||||
Dot: point,
|
|
||||||
}
|
|
||||||
d.DrawString(char)
|
|
||||||
}
|
|
||||||
|
|
||||||
var Colors = map[string]color.RGBA{"black": {0, 0, 0, 255},
|
|
||||||
"gray": {140, 140, 140, 255},
|
|
||||||
"red": {255, 0, 0, 255},
|
|
||||||
"green": {0, 128, 0, 255},
|
|
||||||
"blue": {0, 0, 255, 255}}
|
|
@ -6,14 +6,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type JsonConfig struct {
|
type JsonConfig struct {
|
||||||
Uin int64 `json:"uin"`
|
Uin int64 `json:"uin"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
EnableDB bool `json:"enable_db"`
|
EnableDB bool `json:"enable_db"`
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
Reconnect bool `json:"reconnect"`
|
ReLogin bool `json:"relogin"`
|
||||||
ReconnectDelay int `json:"reconnect_delay"`
|
ReLoginDelay int `json:"relogin_delay"`
|
||||||
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
||||||
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
||||||
|
ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"`
|
||||||
|
Debug bool `json:"debug"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CQHttpApiConfig struct {
|
type CQHttpApiConfig struct {
|
||||||
@ -48,6 +50,14 @@ type GoCQWebsocketConfig struct {
|
|||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GoCQReverseWebsocketConfig struct {
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
|
ReverseUrl string `json:"reverse_url"`
|
||||||
|
ReverseApiUrl string `json:"reverse_api_url"`
|
||||||
|
ReverseEventUrl string `json:"reverse_event_url"`
|
||||||
|
ReverseReconnectInterval uint16 `json:"reverse_reconnect_interval"`
|
||||||
|
}
|
||||||
|
|
||||||
func DefaultConfig() *JsonConfig {
|
func DefaultConfig() *JsonConfig {
|
||||||
return &JsonConfig{
|
return &JsonConfig{
|
||||||
EnableDB: true,
|
EnableDB: true,
|
||||||
@ -62,6 +72,15 @@ func DefaultConfig() *JsonConfig {
|
|||||||
Host: "0.0.0.0",
|
Host: "0.0.0.0",
|
||||||
Port: 6700,
|
Port: 6700,
|
||||||
},
|
},
|
||||||
|
ReverseServers: []*GoCQReverseWebsocketConfig{
|
||||||
|
{
|
||||||
|
Enabled: false,
|
||||||
|
ReverseUrl: "ws://you_websocket_universal.server",
|
||||||
|
ReverseApiUrl: "ws://you_websocket_api.server",
|
||||||
|
ReverseEventUrl: "ws://you_websocket_event.server",
|
||||||
|
ReverseReconnectInterval: 3000,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +99,7 @@ func Load(p string) *JsonConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *JsonConfig) Save(p string) error {
|
func (c *JsonConfig) Save(p string) error {
|
||||||
data, err := json.Marshal(c)
|
data, err := json.MarshalIndent(c, "", "\t")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
5
go.mod
5
go.mod
@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
|
|||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200721195252-2accd73f8b8e
|
github.com/Mrs4s/MiraiGo v0.0.0-20200807030850-ed30f7ad5934
|
||||||
github.com/gin-gonic/gin v1.6.3
|
github.com/gin-gonic/gin v1.6.3
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
github.com/guonaihong/gout v0.1.1
|
github.com/guonaihong/gout v0.1.1
|
||||||
@ -14,6 +14,7 @@ require (
|
|||||||
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.0
|
github.com/tidwall/gjson v1.6.0
|
||||||
github.com/xujiajun/nutsdb v0.5.0
|
github.com/xujiajun/nutsdb v0.5.0
|
||||||
golang.org/x/image v0.0.0-20200618115811-c13761719519
|
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
|
||||||
|
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa
|
||||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
|
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
|
||||||
)
|
)
|
||||||
|
29
go.sum
29
go.sum
@ -1,19 +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-20200717203209-5ead51215a01 h1:kG9Oj5/jI8PurVDu3M5DjytBgLaPpDcScIY4oo9YjYE=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200807030850-ed30f7ad5934 h1:LoNjIsnyEQFGP9IchIQ65yHRCfNKSru3BAOguRepkCM=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200717203209-5ead51215a01/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200807030850-ed30f7ad5934/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200718181224-a45ad2e14770 h1:sbEcdUqvUFQ5dGaXzJVlwc+Q5tsMORSDGs6vwEmHYDg=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200718181224-a45ad2e14770/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200719130800-9d81397b5d91 h1:0es7eD8Mn2CzPX7c4Ig67zt8Izz/eNyZu2wa4p0aRfY=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200719130800-9d81397b5d91/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200720175644-0a8fa220ea50 h1:phnnq/0GZXsLeoviernp6qD57M2XxBzAuWpHG8B9ESI=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200720175644-0a8fa220ea50/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200720230213-9a7a28f9dcc7 h1:nzGG3nm4gJA7wyvvyxMEvmY7RAJA7HtMTPcCUbrh/v0=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200720230213-9a7a28f9dcc7/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200720231612-a7e460246fbc h1:elEjdwOy2u+Gfz+1UvoverA/x3RKTenbbAuBMwizTGk=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200720231612-a7e460246fbc/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200721195252-2accd73f8b8e h1:68ol9TpLBwbFQU+S6VQ0CY6nQqN2xIPxHWD/rvBZxVI=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200721195252-2accd73f8b8e/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
|
|
||||||
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
|
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
|
||||||
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
|
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
|
||||||
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=
|
||||||
@ -46,7 +34,6 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x
|
|||||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||||
github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0=
|
|
||||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||||
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
|
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
|
||||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
@ -63,7 +50,6 @@ github.com/guonaihong/gout v0.1.1 h1:2i3eqQ1KUhTlj7AFeIHqVUFku5QwUhwE2wNgYTVpbxQ
|
|||||||
github.com/guonaihong/gout v0.1.1/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GByll2f/EA=
|
github.com/guonaihong/gout v0.1.1/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GByll2f/EA=
|
||||||
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
@ -79,9 +65,9 @@ github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2y
|
|||||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||||
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/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
|
||||||
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/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/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
@ -114,10 +100,10 @@ github.com/xujiajun/nutsdb v0.5.0 h1:j/jM3Zw7Chg8WK7bAcKR0Xr7Mal47U1oJAMgySfDn9E
|
|||||||
github.com/xujiajun/nutsdb v0.5.0/go.mod h1:owdwN0tW084RxEodABLbO7h4Z2s9WiAjZGZFhRh0/1Q=
|
github.com/xujiajun/nutsdb v0.5.0/go.mod h1:owdwN0tW084RxEodABLbO7h4Z2s9WiAjZGZFhRh0/1Q=
|
||||||
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b h1:jKG9OiL4T4xQN3IUrhUpc1tG+HfDXppkgVcrAiiaI/0=
|
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b h1:jKG9OiL4T4xQN3IUrhUpc1tG+HfDXppkgVcrAiiaI/0=
|
||||||
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b/go.mod h1:AZd87GYJlUzl82Yab2kTjx1EyXSQCAfZDhpTo1SQC4k=
|
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b/go.mod h1:AZd87GYJlUzl82Yab2kTjx1EyXSQCAfZDhpTo1SQC4k=
|
||||||
|
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=
|
||||||
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=
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/image v0.0.0-20200618115811-c13761719519 h1:1e2ufUJNM3lCHEY5jIgac/7UTjd6cgJNdatjPdFWf34=
|
|
||||||
golang.org/x/image v0.0.0-20200618115811-c13761719519/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
|
||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
@ -136,7 +122,6 @@ golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6/go.mod h1:STP8DvDyc/dI5b8T5h
|
|||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
|
|
||||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
|
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
|
||||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@ -172,7 +157,5 @@ gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWd
|
|||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
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=
|
||||||
|
77
main.go
77
main.go
@ -12,12 +12,14 @@ import (
|
|||||||
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"
|
||||||
"image/color"
|
asciiart "github.com/yinghau76/go-ascii-art"
|
||||||
|
"image"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -56,6 +58,13 @@ func init() {
|
|||||||
if conf.PostUrl != "" {
|
if conf.PostUrl != "" {
|
||||||
goConf.HttpConfig.PostUrls[conf.PostUrl] = conf.Secret
|
goConf.HttpConfig.PostUrls[conf.PostUrl] = conf.Secret
|
||||||
}
|
}
|
||||||
|
if conf.UseWsReverse {
|
||||||
|
goConf.ReverseServers[0].Enabled = true
|
||||||
|
goConf.ReverseServers[0].ReverseUrl = conf.WSReverseUrl
|
||||||
|
goConf.ReverseServers[0].ReverseApiUrl = conf.WSReverseApiUrl
|
||||||
|
goConf.ReverseServers[0].ReverseEventUrl = conf.WSReverseEventUrl
|
||||||
|
goConf.ReverseServers[0].ReverseReconnectInterval = conf.WSReverseReconnectInterval
|
||||||
|
}
|
||||||
if err := goConf.Save("config.json"); err != nil {
|
if err := goConf.Save("config.json"); err != nil {
|
||||||
log.Fatalf("保存 config.json 时出现错误: %v", err)
|
log.Fatalf("保存 config.json 时出现错误: %v", err)
|
||||||
}
|
}
|
||||||
@ -65,7 +74,34 @@ func init() {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
console := bufio.NewReader(os.Stdin)
|
console := bufio.NewReader(os.Stdin)
|
||||||
conf := global.Load("config.json")
|
var conf *global.JsonConfig
|
||||||
|
if global.PathExists("config.json") || os.Getenv("UIN") == "" {
|
||||||
|
conf = global.Load("config.json")
|
||||||
|
} else if os.Getenv("UIN") != "" {
|
||||||
|
log.Infof("将从环境变量加载配置.")
|
||||||
|
uin, _ := strconv.ParseInt(os.Getenv("UIN"), 10, 64)
|
||||||
|
pwd := os.Getenv("PASS")
|
||||||
|
post := os.Getenv("HTTP_POST")
|
||||||
|
conf = &global.JsonConfig{
|
||||||
|
Uin: uin,
|
||||||
|
Password: pwd,
|
||||||
|
HttpConfig: &global.GoCQHttpConfig{
|
||||||
|
Enabled: true,
|
||||||
|
Host: "0.0.0.0",
|
||||||
|
Port: 5700,
|
||||||
|
PostUrls: map[string]string{},
|
||||||
|
},
|
||||||
|
WSConfig: &global.GoCQWebsocketConfig{
|
||||||
|
Enabled: true,
|
||||||
|
Host: "0.0.0.0",
|
||||||
|
Port: 6700,
|
||||||
|
},
|
||||||
|
Debug: os.Getenv("DEBUG") == "true",
|
||||||
|
}
|
||||||
|
if post != "" {
|
||||||
|
conf.HttpConfig.PostUrls[post] = os.Getenv("HTTP_SECRET")
|
||||||
|
}
|
||||||
|
}
|
||||||
if conf == nil {
|
if conf == nil {
|
||||||
err := global.DefaultConfig().Save("config.json")
|
err := global.DefaultConfig().Save("config.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -73,14 +109,20 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("默认配置文件已生成, 请编辑 config.json 后重启程序.")
|
log.Infof("默认配置文件已生成, 请编辑 config.json 后重启程序.")
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if conf.Uin == 0 || conf.Password == "" {
|
if conf.Uin == 0 || conf.Password == "" {
|
||||||
log.Fatal("请修改 config.json 以添加账号密码.")
|
log.Warnf("请修改 config.json 以添加账号密码.")
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if conf.Debug {
|
||||||
|
log.SetLevel(log.DebugLevel)
|
||||||
|
log.Warnf("已开启Debug模式.")
|
||||||
}
|
}
|
||||||
if !global.PathExists("device.json") {
|
if !global.PathExists("device.json") {
|
||||||
log.Warn("虚拟设备信息不存在, 将自动生成随机设备,按 Enter 继续.")
|
log.Warn("虚拟设备信息不存在, 将自动生成随机设备.")
|
||||||
_, _ = console.ReadString('\n')
|
|
||||||
client.GenRandomDevice()
|
client.GenRandomDevice()
|
||||||
_ = ioutil.WriteFile("device.json", client.SystemDeviceInfo.ToJson(), 0777)
|
_ = ioutil.WriteFile("device.json", client.SystemDeviceInfo.ToJson(), 0777)
|
||||||
log.Info("已生成设备信息并保存到 device.json 文件.")
|
log.Info("已生成设备信息并保存到 device.json 文件.")
|
||||||
@ -100,19 +142,17 @@ func main() {
|
|||||||
if !rsp.Success {
|
if !rsp.Success {
|
||||||
switch rsp.Error {
|
switch rsp.Error {
|
||||||
case client.NeedCaptcha:
|
case client.NeedCaptcha:
|
||||||
art, _, err := global.Convert(bytes.NewReader(rsp.CaptchaImage), []string{" ", "1", "i", ":", "*", "|", "."}, 1, 1, false, global.Colors["gray"], color.RGBA{})
|
img, _, _ := image.Decode(bytes.NewReader(rsp.CaptchaImage))
|
||||||
global.Check(err)
|
fmt.Println(asciiart.New("image", img).Art)
|
||||||
fmt.Println(art)
|
log.Warn("请输入验证码: (Enter 提交)")
|
||||||
log.Warn("请输入验证码.")
|
|
||||||
text, _ := console.ReadString('\n')
|
text, _ := console.ReadString('\n')
|
||||||
rsp, err = cli.SubmitCaptcha(strings.ReplaceAll(text, "\n", ""), rsp.CaptchaSign)
|
rsp, err = cli.SubmitCaptcha(strings.ReplaceAll(text, "\n", ""), rsp.CaptchaSign)
|
||||||
continue
|
continue
|
||||||
case client.UnsafeDeviceError:
|
case client.UnsafeDeviceError:
|
||||||
log.Warnf("账号已开启设备锁,请前往 -> %v <- 验证.", rsp.VerifyUrl)
|
log.Warnf("账号已开启设备锁,请前往 -> %v <- 验证并重启Bot.", rsp.VerifyUrl)
|
||||||
log.Info("按 Enter 继续")
|
log.Infof(" 按 Enter 继续....")
|
||||||
_, _ = console.ReadString('\n')
|
_, _ = console.ReadString('\n')
|
||||||
rsp, err = cli.Login()
|
return
|
||||||
continue
|
|
||||||
case client.OtherLoginError, client.UnknownLoginError:
|
case client.OtherLoginError, client.UnknownLoginError:
|
||||||
log.Fatalf("登录失败: %v", rsp.ErrorMessage)
|
log.Fatalf("登录失败: %v", rsp.ErrorMessage)
|
||||||
}
|
}
|
||||||
@ -131,18 +171,21 @@ func main() {
|
|||||||
if conf.HttpConfig != nil && conf.HttpConfig.Enabled {
|
if conf.HttpConfig != nil && conf.HttpConfig.Enabled {
|
||||||
server.HttpServer.Run(fmt.Sprintf("%s:%d", conf.HttpConfig.Host, conf.HttpConfig.Port), conf.AccessToken, b)
|
server.HttpServer.Run(fmt.Sprintf("%s:%d", conf.HttpConfig.Host, conf.HttpConfig.Port), conf.AccessToken, b)
|
||||||
for k, v := range conf.HttpConfig.PostUrls {
|
for k, v := range conf.HttpConfig.PostUrls {
|
||||||
server.NewClient().Run(k, v, b)
|
server.NewHttpClient().Run(k, v, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if conf.WSConfig != nil && conf.WSConfig.Enabled {
|
if conf.WSConfig != nil && conf.WSConfig.Enabled {
|
||||||
server.WebsocketServer.Run(fmt.Sprintf("%s:%d", conf.WSConfig.Host, conf.WSConfig.Port), conf.AccessToken, b)
|
server.WebsocketServer.Run(fmt.Sprintf("%s:%d", conf.WSConfig.Host, conf.WSConfig.Port), conf.AccessToken, b)
|
||||||
}
|
}
|
||||||
|
for _, rc := range conf.ReverseServers {
|
||||||
|
server.NewWebsocketClient(rc, conf.AccessToken, b).Run()
|
||||||
|
}
|
||||||
log.Info("资源初始化完成, 开始处理信息.")
|
log.Info("资源初始化完成, 开始处理信息.")
|
||||||
log.Info("アトリは、高性能ですから!")
|
log.Info("アトリは、高性能ですから!")
|
||||||
cli.OnDisconnected(func(bot *client.QQClient, e *client.ClientDisconnectedEvent) {
|
cli.OnDisconnected(func(bot *client.QQClient, e *client.ClientDisconnectedEvent) {
|
||||||
if conf.Reconnect {
|
if conf.ReLogin {
|
||||||
log.Warnf("Bot已离线,将在 %v 秒后尝试重连.", conf.ReconnectDelay)
|
log.Warnf("Bot已离线 (%v),将在 %v 秒后尝试重连.", e.Message, conf.ReLoginDelay)
|
||||||
time.Sleep(time.Second * time.Duration(conf.ReconnectDelay))
|
time.Sleep(time.Second * time.Duration(conf.ReLoginDelay))
|
||||||
rsp, err := cli.Login()
|
rsp, err := cli.Login()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("重连失败: %v", err)
|
log.Fatalf("重连失败: %v", err)
|
||||||
|
@ -4,14 +4,15 @@ import (
|
|||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/guonaihong/gout"
|
"github.com/guonaihong/gout"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type httpServer struct {
|
type httpServer struct {
|
||||||
@ -61,12 +62,12 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
|||||||
c.AbortWithStatus(401)
|
c.AbortWithStatus(401)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
} else if c.Query("access_token") != authToken {
|
||||||
if c.Query("access_token") != authToken {
|
|
||||||
c.AbortWithStatus(401)
|
c.AbortWithStatus(401)
|
||||||
return
|
return
|
||||||
|
} else {
|
||||||
|
c.Next()
|
||||||
}
|
}
|
||||||
c.Next()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +98,9 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
|||||||
s.engine.Any("/send_group_msg", s.SendGroupMessage)
|
s.engine.Any("/send_group_msg", s.SendGroupMessage)
|
||||||
s.engine.Any("/send_group_msg_async", s.SendGroupMessage)
|
s.engine.Any("/send_group_msg_async", s.SendGroupMessage)
|
||||||
|
|
||||||
|
s.engine.Any("/send_group_forward_msg", s.SendGroupForwardMessage)
|
||||||
|
s.engine.Any("/send_group_forward_msg_async", s.SendGroupForwardMessage)
|
||||||
|
|
||||||
s.engine.Any("/delete_msg", s.DeleteMessage)
|
s.engine.Any("/delete_msg", s.DeleteMessage)
|
||||||
s.engine.Any("/delete_msg_async", s.DeleteMessage)
|
s.engine.Any("/delete_msg_async", s.DeleteMessage)
|
||||||
|
|
||||||
@ -124,9 +128,14 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
|||||||
s.engine.Any("/set_group_name", s.SetGroupName)
|
s.engine.Any("/set_group_name", s.SetGroupName)
|
||||||
s.engine.Any("/set_group_name_async", s.SetGroupName)
|
s.engine.Any("/set_group_name_async", s.SetGroupName)
|
||||||
|
|
||||||
|
s.engine.Any("/set_group_leave", s.SetGroupLeave)
|
||||||
|
s.engine.Any("/set_group_leave_async", s.SetGroupLeave)
|
||||||
|
|
||||||
s.engine.Any("/get_image", s.GetImage)
|
s.engine.Any("/get_image", s.GetImage)
|
||||||
s.engine.Any("/get_image_async", s.GetImage)
|
s.engine.Any("/get_image_async", s.GetImage)
|
||||||
|
|
||||||
|
s.engine.Any("/get_forward_msg", s.GetForwardMessage)
|
||||||
|
|
||||||
s.engine.Any("/get_group_msg", s.GetGroupMessage)
|
s.engine.Any("/get_group_msg", s.GetGroupMessage)
|
||||||
s.engine.Any("/get_group_msg_async", s.GetGroupMessage)
|
s.engine.Any("/get_group_msg_async", s.GetGroupMessage)
|
||||||
|
|
||||||
@ -142,13 +151,15 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
|||||||
s.engine.Any("/get_version_info", s.GetVersionInfo)
|
s.engine.Any("/get_version_info", s.GetVersionInfo)
|
||||||
s.engine.Any("/get_version_info_async", s.GetVersionInfo)
|
s.engine.Any("/get_version_info_async", s.GetVersionInfo)
|
||||||
|
|
||||||
|
s.engine.Any("/.handle_quick_operation", s.HandleQuickOperation)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
log.Infof("CQ HTTP 服务器已启动: %v", addr)
|
log.Infof("CQ HTTP 服务器已启动: %v", addr)
|
||||||
log.Fatal(s.engine.Run(addr))
|
log.Fatal(s.engine.Run(addr))
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient() *httpClient {
|
func NewHttpClient() *httpClient {
|
||||||
return &httpClient{}
|
return &httpClient{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,11 +172,11 @@ func (c *httpClient) Run(addr, secret string, bot *coolq.CQBot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *httpClient) onBotPushEvent(m coolq.MSG) {
|
func (c *httpClient) onBotPushEvent(m coolq.MSG) {
|
||||||
err := gout.POST(c.addr).SetJSON(m).SetHeader(func() gout.H {
|
var res string
|
||||||
|
err := gout.POST(c.addr).SetJSON(m).BindBody(&res).SetHeader(func() gout.H {
|
||||||
h := gout.H{
|
h := gout.H{
|
||||||
"X-Self_ID": c.bot.Client.Uin,
|
"X-Self-ID": c.bot.Client.Uin,
|
||||||
"X-Client-Role": "Universal",
|
"User-Agent": "CQHttp/4.15.0",
|
||||||
"User-Agent": "CQHttp/4.15.0",
|
|
||||||
}
|
}
|
||||||
if c.secret != "" {
|
if c.secret != "" {
|
||||||
mac := hmac.New(sha1.New, []byte(c.secret))
|
mac := hmac.New(sha1.New, []byte(c.secret))
|
||||||
@ -176,6 +187,10 @@ func (c *httpClient) onBotPushEvent(m coolq.MSG) {
|
|||||||
}()).SetTimeout(time.Second * 5).Do()
|
}()).SetTimeout(time.Second * 5).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("上报Event数据到 %v 失败: %v", c.addr, err)
|
log.Warnf("上报Event数据到 %v 失败: %v", c.addr, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if gjson.Valid(res) {
|
||||||
|
c.bot.CQHandleQuickOperation(gjson.Parse(m.ToJson()), gjson.Parse(res))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,15 +236,29 @@ func (s *httpServer) SendMessage(c *gin.Context) {
|
|||||||
func (s *httpServer) SendPrivateMessage(c *gin.Context) {
|
func (s *httpServer) SendPrivateMessage(c *gin.Context) {
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
||||||
msg := getParam(c, "message")
|
msg := getParam(c, "message")
|
||||||
|
if gjson.Valid(msg) {
|
||||||
|
c.JSON(200, s.bot.CQSendPrivateMessage(uid, gjson.Parse(msg)))
|
||||||
|
return
|
||||||
|
}
|
||||||
c.JSON(200, s.bot.CQSendPrivateMessage(uid, msg))
|
c.JSON(200, s.bot.CQSendPrivateMessage(uid, msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SendGroupMessage(c *gin.Context) {
|
func (s *httpServer) SendGroupMessage(c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
msg := getParam(c, "message")
|
msg := getParam(c, "message")
|
||||||
|
if gjson.Valid(msg) {
|
||||||
|
c.JSON(200, s.bot.CQSendGroupMessage(gid, gjson.Parse(msg)))
|
||||||
|
return
|
||||||
|
}
|
||||||
c.JSON(200, s.bot.CQSendGroupMessage(gid, msg))
|
c.JSON(200, s.bot.CQSendGroupMessage(gid, msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *httpServer) SendGroupForwardMessage(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)))
|
||||||
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetImage(c *gin.Context) {
|
func (s *httpServer) GetImage(c *gin.Context) {
|
||||||
file := getParam(c, "file")
|
file := getParam(c, "file")
|
||||||
c.JSON(200, s.bot.CQGetImage(file))
|
c.JSON(200, s.bot.CQGetImage(file))
|
||||||
@ -278,8 +307,8 @@ func (s *httpServer) SetGroupKick(c *gin.Context) {
|
|||||||
func (s *httpServer) SetGroupBan(c *gin.Context) {
|
func (s *httpServer) SetGroupBan(c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
||||||
time, _ := strconv.ParseInt(getParam(c, "duration"), 10, 64)
|
i, _ := strconv.ParseInt(getParamOrDefault(c, "duration", "1800"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQSetGroupBan(gid, uid, uint32(time)))
|
c.JSON(200, s.bot.CQSetGroupBan(gid, uid, uint32(i)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SetWholeBan(c *gin.Context) {
|
func (s *httpServer) SetWholeBan(c *gin.Context) {
|
||||||
@ -292,6 +321,16 @@ func (s *httpServer) SetGroupName(c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQSetGroupName(gid, getParam(c, "name")))
|
c.JSON(200, s.bot.CQSetGroupName(gid, getParam(c, "name")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *httpServer) SetGroupLeave(c *gin.Context) {
|
||||||
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
|
c.JSON(200, s.bot.CQSetGroupLeave(gid))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *httpServer) GetForwardMessage(c *gin.Context) {
|
||||||
|
resId := getParam(c, "message_id")
|
||||||
|
c.JSON(200, s.bot.CQGetForwardMessage(resId))
|
||||||
|
}
|
||||||
|
|
||||||
func (s *httpServer) DeleteMessage(c *gin.Context) {
|
func (s *httpServer) DeleteMessage(c *gin.Context) {
|
||||||
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 32)
|
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 32)
|
||||||
c.JSON(200, s.bot.CQDeleteMessage(int32(mid)))
|
c.JSON(200, s.bot.CQDeleteMessage(int32(mid)))
|
||||||
@ -313,6 +352,17 @@ func (s *httpServer) GetVersionInfo(c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQGetVersionInfo())
|
c.JSON(200, s.bot.CQGetVersionInfo())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *httpServer) HandleQuickOperation(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")))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getParamOrDefault(c *gin.Context, k, def string) string {
|
func getParamOrDefault(c *gin.Context, k, def string) string {
|
||||||
r := getParam(c, k)
|
r := getParam(c, k)
|
||||||
if r != "" {
|
if r != "" {
|
||||||
@ -337,6 +387,8 @@ func getParam(c *gin.Context, k string) string {
|
|||||||
res := obj.(gjson.Result).Get(k)
|
res := obj.(gjson.Result).Get(k)
|
||||||
if res.Exists() {
|
if res.Exists() {
|
||||||
switch res.Type {
|
switch res.Type {
|
||||||
|
case gjson.JSON:
|
||||||
|
return res.Raw
|
||||||
case gjson.String:
|
case gjson.String:
|
||||||
return res.Str
|
return res.Str
|
||||||
case gjson.Number:
|
case gjson.Number:
|
||||||
|
@ -3,10 +3,13 @@ package server
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||||
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
wsc "golang.org/x/net/websocket"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -21,6 +24,13 @@ type websocketServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type websocketClient struct {
|
type websocketClient struct {
|
||||||
|
conf *global.GoCQReverseWebsocketConfig
|
||||||
|
token string
|
||||||
|
bot *coolq.CQBot
|
||||||
|
|
||||||
|
pushLock *sync.Mutex
|
||||||
|
universalConn *wsc.Conn
|
||||||
|
eventConn *wsc.Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
var WebsocketServer = &websocketServer{}
|
var WebsocketServer = &websocketServer{}
|
||||||
@ -46,6 +56,154 @@ func (s *websocketServer) Run(addr, authToken string, b *coolq.CQBot) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewWebsocketClient(conf *global.GoCQReverseWebsocketConfig, authToken string, b *coolq.CQBot) *websocketClient {
|
||||||
|
return &websocketClient{conf: conf, token: authToken, bot: b, pushLock: new(sync.Mutex)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *websocketClient) Run() {
|
||||||
|
if !c.conf.Enabled {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if c.conf.ReverseApiUrl != "" {
|
||||||
|
c.connectApi()
|
||||||
|
}
|
||||||
|
if c.conf.ReverseEventUrl != "" {
|
||||||
|
c.connectEvent()
|
||||||
|
}
|
||||||
|
if c.conf.ReverseUrl != "" {
|
||||||
|
c.connectUniversal()
|
||||||
|
}
|
||||||
|
c.bot.OnEventPush(c.onBotPushEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *websocketClient) connectApi() {
|
||||||
|
log.Infof("开始尝试连接到反向Websocket API服务器: %v", c.conf.ReverseApiUrl)
|
||||||
|
wsConf, err := wsc.NewConfig(c.conf.ReverseApiUrl, c.conf.ReverseApiUrl)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("连接到反向Websocket API服务器 %v 时出现致命错误: %v", c.conf.ReverseApiUrl, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
wsConf.Header["X-Client-Role"] = []string{"API"}
|
||||||
|
wsConf.Header["X-Self-ID"] = []string{strconv.FormatInt(c.bot.Client.Uin, 10)}
|
||||||
|
wsConf.Header["User-Agent"] = []string{"CQHttp/4.15.0"}
|
||||||
|
if c.token != "" {
|
||||||
|
wsConf.Header["Authorization"] = []string{"Token " + c.token}
|
||||||
|
}
|
||||||
|
conn, err := wsc.DialConfig(wsConf)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("连接到反向Websocket API服务器 %v 时出现错误: %v", c.conf.ReverseApiUrl, err)
|
||||||
|
if c.conf.ReverseReconnectInterval != 0 {
|
||||||
|
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
|
||||||
|
c.connectApi()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Infof("已连接到反向Websocket API服务器 %v", c.conf.ReverseApiUrl)
|
||||||
|
go c.listenApi(conn, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *websocketClient) connectEvent() {
|
||||||
|
log.Infof("开始尝试连接到反向Websocket Event服务器: %v", c.conf.ReverseEventUrl)
|
||||||
|
wsConf, err := wsc.NewConfig(c.conf.ReverseEventUrl, c.conf.ReverseEventUrl)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("连接到反向Websocket Event服务器 %v 时出现致命错误: %v", c.conf.ReverseApiUrl, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
wsConf.Header["X-Client-Role"] = []string{"Event"}
|
||||||
|
wsConf.Header["X-Self-ID"] = []string{strconv.FormatInt(c.bot.Client.Uin, 10)}
|
||||||
|
wsConf.Header["User-Agent"] = []string{"CQHttp/4.15.0"}
|
||||||
|
if c.token != "" {
|
||||||
|
wsConf.Header["Authorization"] = []string{"Token " + c.token}
|
||||||
|
}
|
||||||
|
conn, err := wsc.DialConfig(wsConf)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("连接到反向Websocket API服务器 %v 时出现错误: %v", c.conf.ReverseApiUrl, err)
|
||||||
|
if c.conf.ReverseReconnectInterval != 0 {
|
||||||
|
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
|
||||||
|
c.connectApi()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Infof("已连接到反向Websocket Event服务器 %v", c.conf.ReverseEventUrl)
|
||||||
|
c.eventConn = conn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *websocketClient) connectUniversal() {
|
||||||
|
log.Infof("开始尝试连接到反向Websocket Universal服务器: %v", c.conf.ReverseUrl)
|
||||||
|
wsConf, err := wsc.NewConfig(c.conf.ReverseUrl, c.conf.ReverseUrl)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("连接到反向Websocket Universal服务器 %v 时出现致命错误: %v", c.conf.ReverseUrl, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
wsConf.Header["X-Client-Role"] = []string{"Universal"}
|
||||||
|
wsConf.Header["X-Self-ID"] = []string{strconv.FormatInt(c.bot.Client.Uin, 10)}
|
||||||
|
wsConf.Header["User-Agent"] = []string{"CQHttp/4.15.0"}
|
||||||
|
if c.token != "" {
|
||||||
|
wsConf.Header["Authorization"] = []string{"Token " + c.token}
|
||||||
|
}
|
||||||
|
conn, err := wsc.DialConfig(wsConf)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("连接到反向Websocket Universal服务器 %v 时出现错误: %v", c.conf.ReverseUrl, err)
|
||||||
|
if c.conf.ReverseReconnectInterval != 0 {
|
||||||
|
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
|
||||||
|
c.connectUniversal()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
go c.listenApi(conn, true)
|
||||||
|
c.universalConn = conn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *websocketClient) listenApi(conn *wsc.Conn, u bool) {
|
||||||
|
defer conn.Close()
|
||||||
|
for {
|
||||||
|
var buf []byte
|
||||||
|
err := wsc.Message.Receive(conn, &buf)
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
j := gjson.ParseBytes(buf)
|
||||||
|
t := strings.ReplaceAll(j.Get("action").Str, "_async", "")
|
||||||
|
log.Debugf("反向WS接收到API调用: %v 参数: %v", t, j.Get("params").Raw)
|
||||||
|
if f, ok := wsApi[t]; ok {
|
||||||
|
ret := f(c.bot, j.Get("params"))
|
||||||
|
if j.Get("echo").Exists() {
|
||||||
|
ret["echo"] = j.Get("echo").Value()
|
||||||
|
}
|
||||||
|
c.pushLock.Lock()
|
||||||
|
_, _ = conn.Write([]byte(ret.ToJson()))
|
||||||
|
c.pushLock.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if c.conf.ReverseReconnectInterval != 0 {
|
||||||
|
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
|
||||||
|
if u {
|
||||||
|
c.connectUniversal()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.connectApi()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *websocketClient) onBotPushEvent(m coolq.MSG) {
|
||||||
|
c.pushLock.Lock()
|
||||||
|
defer c.pushLock.Unlock()
|
||||||
|
if c.eventConn != nil {
|
||||||
|
log.Debugf("向WS服务器 %v 推送Event: %v", c.eventConn.RemoteAddr().String(), m.ToJson())
|
||||||
|
if _, err := c.eventConn.Write([]byte(m.ToJson())); err != nil {
|
||||||
|
_ = c.eventConn.Close()
|
||||||
|
if c.conf.ReverseReconnectInterval != 0 {
|
||||||
|
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
|
||||||
|
c.connectEvent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if c.universalConn != nil {
|
||||||
|
log.Debugf("向WS服务器 %v 推送Event: %v", c.universalConn.RemoteAddr().String(), m.ToJson())
|
||||||
|
_, _ = c.universalConn.Write([]byte(m.ToJson()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) {
|
func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) {
|
||||||
if s.token != "" {
|
if s.token != "" {
|
||||||
if r.URL.Query().Get("access_token") != s.token && strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token {
|
if r.URL.Query().Get("access_token") != s.token && strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token {
|
||||||
@ -114,9 +272,15 @@ func (s *websocketServer) listenApi(c *websocket.Conn) {
|
|||||||
if t == websocket.TextMessage {
|
if t == websocket.TextMessage {
|
||||||
j := gjson.ParseBytes(payload)
|
j := gjson.ParseBytes(payload)
|
||||||
t := strings.ReplaceAll(j.Get("action").Str, "_async", "") //TODO: async support
|
t := strings.ReplaceAll(j.Get("action").Str, "_async", "") //TODO: async support
|
||||||
log.Infof("API调用: %v", j.Get("action").Str)
|
log.Debugf("WS接收到API调用: %v 参数: %v", t, j.Get("params").Raw)
|
||||||
if f, ok := wsApi[t]; ok {
|
if f, ok := wsApi[t]; ok {
|
||||||
_ = c.WriteMessage(websocket.TextMessage, []byte(f(s.bot, j.Get("params"))))
|
ret := f(s.bot, j.Get("params"))
|
||||||
|
if j.Get("echo").Exists() {
|
||||||
|
ret["echo"] = j.Get("echo").Value()
|
||||||
|
}
|
||||||
|
s.pushLock.Lock()
|
||||||
|
_ = c.WriteJSON(ret)
|
||||||
|
s.pushLock.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,6 +291,7 @@ func (s *websocketServer) onBotPushEvent(m coolq.MSG) {
|
|||||||
defer s.pushLock.Unlock()
|
defer s.pushLock.Unlock()
|
||||||
pos := 0
|
pos := 0
|
||||||
for _, conn := range s.eventConn {
|
for _, conn := range s.eventConn {
|
||||||
|
log.Debugf("向WS客户端 %v 推送Event: %v", conn.RemoteAddr().String(), m.ToJson())
|
||||||
err := conn.WriteMessage(websocket.TextMessage, []byte(m.ToJson()))
|
err := conn.WriteMessage(websocket.TextMessage, []byte(m.ToJson()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = conn.Close()
|
_ = conn.Close()
|
||||||
@ -139,54 +304,57 @@ func (s *websocketServer) onBotPushEvent(m coolq.MSG) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var wsApi = map[string]func(*coolq.CQBot, gjson.Result) string{
|
var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
||||||
"get_login_info": func(bot *coolq.CQBot, p gjson.Result) string {
|
"get_login_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetLoginInfo().ToJson()
|
return bot.CQGetLoginInfo()
|
||||||
},
|
},
|
||||||
"get_friend_list": func(bot *coolq.CQBot, p gjson.Result) string {
|
"get_friend_list": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetFriendList().ToJson()
|
return bot.CQGetFriendList()
|
||||||
},
|
},
|
||||||
"get_group_list": func(bot *coolq.CQBot, p gjson.Result) string {
|
"get_group_list": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupList().ToJson()
|
return bot.CQGetGroupList()
|
||||||
},
|
},
|
||||||
"get_group_info": func(bot *coolq.CQBot, p gjson.Result) string {
|
"get_group_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupInfo(p.Get("group_id").Int()).ToJson()
|
return bot.CQGetGroupInfo(p.Get("group_id").Int())
|
||||||
},
|
},
|
||||||
"get_group_member_list": func(bot *coolq.CQBot, p gjson.Result) string {
|
"get_group_member_list": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupMemberList(p.Get("group_id").Int()).ToJson()
|
return bot.CQGetGroupMemberList(p.Get("group_id").Int())
|
||||||
},
|
},
|
||||||
"get_group_member_info": func(bot *coolq.CQBot, p gjson.Result) string {
|
"get_group_member_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupMemberInfo(
|
return bot.CQGetGroupMemberInfo(
|
||||||
p.Get("group_id").Int(), p.Get("user_id").Int(),
|
p.Get("group_id").Int(), p.Get("user_id").Int(),
|
||||||
p.Get("no_cache").Bool(),
|
p.Get("no_cache").Bool(),
|
||||||
).ToJson()
|
)
|
||||||
},
|
},
|
||||||
"send_msg": func(bot *coolq.CQBot, p gjson.Result) string {
|
"send_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
if p.Get("group_id").Int() != 0 {
|
if p.Get("group_id").Int() != 0 {
|
||||||
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message").Str).ToJson()
|
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"))
|
||||||
}
|
}
|
||||||
if p.Get("user_id").Int() != 0 {
|
if p.Get("user_id").Int() != 0 {
|
||||||
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message").Str).ToJson()
|
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"))
|
||||||
}
|
}
|
||||||
return ""
|
return coolq.MSG{}
|
||||||
},
|
},
|
||||||
"send_group_msg": func(bot *coolq.CQBot, p gjson.Result) string {
|
"send_group_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message").Str).ToJson()
|
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"))
|
||||||
},
|
},
|
||||||
"send_private_msg": func(bot *coolq.CQBot, p gjson.Result) string {
|
"send_group_forward_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message").Str).ToJson()
|
return bot.CQSendGroupForwardMessage(p.Get("group_id").Int(), p.Get("messages"))
|
||||||
},
|
},
|
||||||
"delete_msg": func(bot *coolq.CQBot, p gjson.Result) string {
|
"send_private_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQDeleteMessage(int32(p.Get("message_id").Int())).ToJson()
|
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("message"))
|
||||||
},
|
},
|
||||||
"set_friend_add_request": func(bot *coolq.CQBot, p gjson.Result) string {
|
"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
|
apr := true
|
||||||
if p.Get("approve").Exists() {
|
if p.Get("approve").Exists() {
|
||||||
apr = p.Get("approve").Bool()
|
apr = p.Get("approve").Bool()
|
||||||
}
|
}
|
||||||
return bot.CQProcessFriendRequest(p.Get("flag").Str, apr).ToJson()
|
return bot.CQProcessFriendRequest(p.Get("flag").Str, apr)
|
||||||
},
|
},
|
||||||
"set_group_add_request": func(bot *coolq.CQBot, p gjson.Result) string {
|
"set_group_add_request": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
subType := p.Get("sub_type").Str
|
subType := p.Get("sub_type").Str
|
||||||
apr := true
|
apr := true
|
||||||
if subType == "" {
|
if subType == "" {
|
||||||
@ -195,47 +363,61 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) string{
|
|||||||
if p.Get("approve").Exists() {
|
if p.Get("approve").Exists() {
|
||||||
apr = p.Get("approve").Bool()
|
apr = p.Get("approve").Bool()
|
||||||
}
|
}
|
||||||
return bot.CQProcessGroupRequest(p.Get("flag").Str, subType, apr).ToJson()
|
return bot.CQProcessGroupRequest(p.Get("flag").Str, subType, apr)
|
||||||
},
|
},
|
||||||
"set_group_card": func(bot *coolq.CQBot, p gjson.Result) string {
|
"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).ToJson()
|
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) string {
|
"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).ToJson()
|
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) string {
|
"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).ToJson()
|
return bot.CQSetGroupKick(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("message").Str)
|
||||||
},
|
},
|
||||||
"set_group_ban": func(bot *coolq.CQBot, p gjson.Result) string {
|
"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(), uint32(p.Get("duration").Int())).ToJson()
|
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) string {
|
"set_group_whole_ban": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQSetGroupWholeBan(p.Get("group_id").Int(), func() bool {
|
return bot.CQSetGroupWholeBan(p.Get("group_id").Int(), func() bool {
|
||||||
if p.Get("enable").Exists() {
|
if p.Get("enable").Exists() {
|
||||||
return p.Get("enable").Bool()
|
return p.Get("enable").Bool()
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}()).ToJson()
|
}())
|
||||||
},
|
},
|
||||||
"set_group_name": func(bot *coolq.CQBot, p gjson.Result) string {
|
"set_group_name": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQSetGroupName(p.Get("group_id").Int(), p.Get("name").Str).ToJson()
|
return bot.CQSetGroupName(p.Get("group_id").Int(), p.Get("name").Str)
|
||||||
},
|
},
|
||||||
"get_image": func(bot *coolq.CQBot, p gjson.Result) string {
|
"set_group_leave": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetImage(p.Get("file").Str).ToJson()
|
return bot.CQSetGroupLeave(p.Get("group_id").Int())
|
||||||
},
|
},
|
||||||
"get_group_msg": func(bot *coolq.CQBot, p gjson.Result) string {
|
"get_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupMessage(int32(p.Get("message_id").Int())).ToJson()
|
return bot.CQGetImage(p.Get("file").Str)
|
||||||
},
|
},
|
||||||
"can_send_image": func(bot *coolq.CQBot, p gjson.Result) string {
|
"get_forward_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQCanSendImage().ToJson()
|
return bot.CQGetForwardMessage(p.Get("message_id").Str)
|
||||||
},
|
},
|
||||||
"can_send_record": func(bot *coolq.CQBot, p gjson.Result) string {
|
"get_group_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQCanSendRecord().ToJson()
|
return bot.CQGetGroupMessage(int32(p.Get("message_id").Int()))
|
||||||
},
|
},
|
||||||
"get_status": func(bot *coolq.CQBot, p gjson.Result) string {
|
"can_send_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetStatus().ToJson()
|
return bot.CQCanSendImage()
|
||||||
},
|
},
|
||||||
"get_version_info": func(bot *coolq.CQBot, p gjson.Result) string {
|
"can_send_record": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetVersionInfo().ToJson()
|
return bot.CQCanSendRecord()
|
||||||
|
},
|
||||||
|
"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()
|
||||||
|
},
|
||||||
|
".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