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
4941f0c3
Commit
4941f0c3
authored
Aug 10, 2020
by
Mrs4s
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
try to support escape. #9
parent
bc47267c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
3 deletions
+19
-3
coolq/cqcode.go
coolq/cqcode.go
+19
-3
No files found.
coolq/cqcode.go
View file @
4941f0c3
...
@@ -31,7 +31,7 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
...
@@ -31,7 +31,7 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
for
_
,
elem
:=
range
e
{
for
_
,
elem
:=
range
e
{
switch
o
:=
elem
.
(
type
)
{
switch
o
:=
elem
.
(
type
)
{
case
*
message
.
TextElement
:
case
*
message
.
TextElement
:
r
+=
o
.
Content
r
+=
CQCodeEscapeText
(
o
.
Content
)
case
*
message
.
AtElement
:
case
*
message
.
AtElement
:
if
o
.
Target
==
0
{
if
o
.
Target
==
0
{
r
+=
"[CQ:at,qq=all]"
r
+=
"[CQ:at,qq=all]"
...
@@ -63,7 +63,7 @@ func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessa
...
@@ -63,7 +63,7 @@ func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessa
for
_
,
idx
:=
range
i
{
for
_
,
idx
:=
range
i
{
if
idx
[
0
]
>
si
{
if
idx
[
0
]
>
si
{
text
:=
m
[
si
:
idx
[
0
]]
text
:=
m
[
si
:
idx
[
0
]]
r
=
append
(
r
,
message
.
NewText
(
text
))
r
=
append
(
r
,
message
.
NewText
(
CQCodeUnescapeText
(
text
)
))
}
}
code
:=
m
[
idx
[
0
]
:
idx
[
1
]]
code
:=
m
[
idx
[
0
]
:
idx
[
1
]]
si
=
idx
[
1
]
si
=
idx
[
1
]
...
@@ -105,7 +105,7 @@ func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessa
...
@@ -105,7 +105,7 @@ func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessa
r
=
append
(
r
,
elem
)
r
=
append
(
r
,
elem
)
}
}
if
si
!=
len
(
m
)
{
if
si
!=
len
(
m
)
{
r
=
append
(
r
,
message
.
NewText
(
m
[
si
:
]
))
r
=
append
(
r
,
message
.
NewText
(
CQCodeUnescapeText
(
m
[
si
:
])
))
}
}
return
return
}
}
...
@@ -309,3 +309,19 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
...
@@ -309,3 +309,19 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
return
nil
,
errors
.
New
(
"unsupported cq code: "
+
t
)
return
nil
,
errors
.
New
(
"unsupported cq code: "
+
t
)
}
}
}
}
func
CQCodeEscapeText
(
raw
string
)
string
{
ret
:=
raw
ret
=
strings
.
ReplaceAll
(
ret
,
"["
,
"["
)
ret
=
strings
.
ReplaceAll
(
ret
,
"]"
,
"]"
)
ret
=
strings
.
ReplaceAll
(
ret
,
"&"
,
"&"
)
return
ret
}
func
CQCodeUnescapeText
(
content
string
)
string
{
ret
:=
content
ret
=
strings
.
ReplaceAll
(
ret
,
"["
,
"["
)
ret
=
strings
.
ReplaceAll
(
ret
,
"]"
,
"]"
)
ret
=
strings
.
ReplaceAll
(
ret
,
"&"
,
"&"
)
return
ret
}
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