Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
go-cqhttp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
go-cqhttp
Commits
2e59cb8a
Commit
2e59cb8a
authored
Sep 28, 2020
by
wdvxdr1123
Committed by
GitHub
Sep 28, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge
sync
parents
cd09a68e
b7316223
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
23 additions
and
52 deletions
+23
-52
coolq/api.go
coolq/api.go
+14
-0
coolq/cqcode.go
coolq/cqcode.go
+2
-2
docs/file.md
docs/file.md
+0
-2
docs/quick_start.md
docs/quick_start.md
+1
-1
go.mod
go.mod
+1
-1
go.sum
go.sum
+4
-5
main.go
main.go
+1
-41
No files found.
coolq/api.go
View file @
2e59cb8a
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"path"
"path"
"runtime"
"runtime"
"strconv"
"strconv"
"strings"
"time"
"time"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/binary"
...
@@ -125,6 +126,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
...
@@ -125,6 +126,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
if
mid
==
-
1
{
if
mid
==
-
1
{
return
Failed
(
100
)
return
Failed
(
100
)
}
}
log
.
Infof
(
"发送群 %v(%v) 的消息: %v (%v)"
,
groupId
,
groupId
,
limitedString
(
m
.
String
()),
mid
)
return
OK
(
MSG
{
"message_id"
:
mid
})
return
OK
(
MSG
{
"message_id"
:
mid
})
}
}
str
=
func
()
string
{
str
=
func
()
string
{
...
@@ -151,6 +153,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
...
@@ -151,6 +153,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
if
mid
==
-
1
{
if
mid
==
-
1
{
return
Failed
(
100
)
return
Failed
(
100
)
}
}
log
.
Infof
(
"发送群 %v(%v) 的消息: %v (%v)"
,
groupId
,
groupId
,
limitedString
(
str
),
mid
)
return
OK
(
MSG
{
"message_id"
:
mid
})
return
OK
(
MSG
{
"message_id"
:
mid
})
}
}
...
@@ -247,6 +250,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
...
@@ -247,6 +250,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
if
mid
==
-
1
{
if
mid
==
-
1
{
return
Failed
(
100
)
return
Failed
(
100
)
}
}
log
.
Infof
(
"发送好友 %v(%v) 的消息: %v (%v)"
,
userId
,
userId
,
limitedString
(
m
.
String
()),
mid
)
return
OK
(
MSG
{
"message_id"
:
mid
})
return
OK
(
MSG
{
"message_id"
:
mid
})
}
}
str
=
func
()
string
{
str
=
func
()
string
{
...
@@ -271,6 +275,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
...
@@ -271,6 +275,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
if
mid
==
-
1
{
if
mid
==
-
1
{
return
Failed
(
100
)
return
Failed
(
100
)
}
}
log
.
Infof
(
"发送好友 %v(%v) 的消息: %v (%v)"
,
userId
,
userId
,
limitedString
(
str
),
mid
)
return
OK
(
MSG
{
"message_id"
:
mid
})
return
OK
(
MSG
{
"message_id"
:
mid
})
}
}
...
@@ -754,3 +759,12 @@ func convertGroupMemberInfo(groupId int64, m *client.GroupMemberInfo) MSG {
...
@@ -754,3 +759,12 @@ func convertGroupMemberInfo(groupId int64, m *client.GroupMemberInfo) MSG {
"card_changeable"
:
false
,
"card_changeable"
:
false
,
}
}
}
}
func
limitedString
(
str
string
)
string
{
if
strings
.
Count
(
str
,
""
)
<=
10
{
return
str
}
limited
:=
[]
rune
(
str
)
limited
=
limited
[
:
10
]
return
string
(
limited
)
+
" ..."
}
coolq/cqcode.go
View file @
2e59cb8a
...
@@ -58,8 +58,6 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
...
@@ -58,8 +58,6 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
"type"
:
"text"
,
"type"
:
"text"
,
"data"
:
map
[
string
]
string
{
"text"
:
o
.
Content
},
"data"
:
map
[
string
]
string
{
"text"
:
o
.
Content
},
}
}
case
*
message
.
ReplyElement
:
continue
case
*
message
.
LightAppElement
:
case
*
message
.
LightAppElement
:
//m = MSG{
//m = MSG{
// "type": "text",
// "type": "text",
...
@@ -144,6 +142,8 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
...
@@ -144,6 +142,8 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
"data"
:
map
[
string
]
string
{
"data"
:
o
.
Content
,
"resid"
:
fmt
.
Sprintf
(
"%d"
,
o
.
Id
)},
"data"
:
map
[
string
]
string
{
"data"
:
o
.
Content
,
"resid"
:
fmt
.
Sprintf
(
"%d"
,
o
.
Id
)},
}
}
}
}
default
:
continue
}
}
r
=
append
(
r
,
m
)
r
=
append
(
r
,
m
)
}
}
...
...
docs/file.md
View file @
2e59cb8a
...
@@ -7,7 +7,6 @@ go-cqhttp 默认生成的文件树如下所示:
...
@@ -7,7 +7,6 @@ go-cqhttp 默认生成的文件树如下所示:
├── go-cqhttp
├── go-cqhttp
├── config.json
├── config.json
├── device.json
├── device.json
├── servers.bin
├── logs
├── logs
│ └── xx-xx-xx.log
│ └── xx-xx-xx.log
└── data
└── data
...
@@ -21,7 +20,6 @@ go-cqhttp 默认生成的文件树如下所示:
...
@@ -21,7 +20,6 @@ go-cqhttp 默认生成的文件树如下所示:
| go-cqhttp | go-cqhttp可执行文件 |
| go-cqhttp | go-cqhttp可执行文件 |
| config.json | 运行配置文件 |
| config.json | 运行配置文件 |
| device.json | 虚拟设备配置文件 |
| device.json | 虚拟设备配置文件 |
| servers.bin | 储存QQ服务器地址 |
| logs | 日志存放目录 |
| logs | 日志存放目录 |
| data | 数据目录 |
| data | 数据目录 |
| data/images | 图片缓存目录 |
| data/images | 图片缓存目录 |
...
...
docs/quick_start.md
View file @
2e59cb8a
# 开始
# 开始
欢迎来到 go-cqhttp 文档
欢迎来到 go-cqhttp 文档 目前还在咕
\ No newline at end of file
\ No newline at end of file
go.mod
View file @
2e59cb8a
...
@@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
...
@@ -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-2020092
1142226-9a449519db5
c
github.com/Mrs4s/MiraiGo v0.0.0-2020092
8082341-65c1709f5ee
c
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/gin-gonic/gin v1.6.3
github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.3.0 // indirect
github.com/go-playground/validator/v10 v10.3.0 // indirect
...
...
go.sum
View file @
2e59cb8a
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-2020092
1142226-9a449519db5c h1:TpGiSjI8Pe0YLEQPAVkOV37OFLeJnQ6jxvcDSb/LESY
=
github.com/Mrs4s/MiraiGo v0.0.0-2020092
8082341-65c1709f5eec h1:lzFAr6b1yO6JIzfse0VIsPq71E0KfdsoS3VnyOLurS4
=
github.com/Mrs4s/MiraiGo v0.0.0-2020092
1142226-9a449519db5
c/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-2020092
8082341-65c1709f5ee
c/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
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=
...
@@ -56,7 +56,6 @@ github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
...
@@ -56,7 +56,6 @@ github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
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/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/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=
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
...
@@ -138,8 +137,8 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
...
@@ -138,8 +137,8 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
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/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-202009
09081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM
=
golang.org/x/sys v0.0.0-202009
16084744-dbad9cb7cb7a h1:chkwkn8HYWVtTE5DCQNKYlkyptadXYY0+PuyaVdyMo4
=
golang.org/x/sys v0.0.0-202009
09081042-eff7692f9009
/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-202009
16084744-dbad9cb7cb7a
/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s=
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s=
...
...
main.go
View file @
2e59cb8a
...
@@ -10,7 +10,6 @@ import (
...
@@ -10,7 +10,6 @@ import (
"image"
"image"
"io"
"io"
"io/ioutil"
"io/ioutil"
"net"
"os"
"os"
"os/signal"
"os/signal"
"path"
"path"
...
@@ -237,47 +236,8 @@ func main() {
...
@@ -237,47 +236,8 @@ func main() {
}
}
})
})
cli
.
OnServerUpdated
(
func
(
bot
*
client
.
QQClient
,
e
*
client
.
ServerUpdatedEvent
)
{
cli
.
OnServerUpdated
(
func
(
bot
*
client
.
QQClient
,
e
*
client
.
ServerUpdatedEvent
)
{
log
.
Infof
(
"收到服务器地址更新通知, 将在下一次重连时应用. 地址信息已储存到 servers.bin 文件"
)
log
.
Infof
(
"收到服务器地址更新通知, 将在下一次重连时应用. "
)
_
=
ioutil
.
WriteFile
(
"servers.bin"
,
binary
.
NewWriterF
(
func
(
w
*
binary
.
Writer
)
{
w
.
WriteUInt16
(
func
()
(
c
uint16
)
{
for
_
,
s
:=
range
e
.
Servers
{
if
!
strings
.
Contains
(
s
.
Server
,
"com"
)
{
c
++
}
}
return
}())
for
_
,
s
:=
range
e
.
Servers
{
if
!
strings
.
Contains
(
s
.
Server
,
"com"
)
{
w
.
WriteString
(
s
.
Server
)
w
.
WriteUInt16
(
uint16
(
s
.
Port
))
}
}
}),
0644
)
})
if
global
.
PathExists
(
"servers.bin"
)
{
if
data
,
err
:=
ioutil
.
ReadFile
(
"servers.bin"
);
err
==
nil
{
func
()
{
defer
func
()
{
if
pan
:=
recover
();
pan
!=
nil
{
log
.
Error
(
"读取服务器地址时出现错误: "
,
pan
)
}
}()
r
:=
binary
.
NewReader
(
data
)
var
addr
[]
*
net
.
TCPAddr
l
:=
r
.
ReadUInt16
()
for
i
:=
0
;
i
<
int
(
l
);
i
++
{
addr
=
append
(
addr
,
&
net
.
TCPAddr
{
IP
:
net
.
ParseIP
(
r
.
ReadString
()),
Port
:
int
(
r
.
ReadUInt16
()),
})
})
}
if
len
(
addr
)
>
0
{
cli
.
SetCustomServer
(
addr
)
}
}()
}
}
rsp
,
err
:=
cli
.
Login
()
rsp
,
err
:=
cli
.
Login
()
for
{
for
{
global
.
Check
(
err
)
global
.
Check
(
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment