Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
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
MyCard
Mirai
Commits
df4cef62
Commit
df4cef62
authored
Apr 30, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve image regex
parent
244bbff8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt
...c/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt
+5
-5
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/impl.kt
...rc/commonMain/kotlin/net.mamoe.mirai/message/data/impl.kt
+3
-3
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt
View file @
df4cef62
...
@@ -94,7 +94,7 @@ expect interface Image : Message, MessageContent {
...
@@ -94,7 +94,7 @@ expect interface Image : Message, MessageContent {
*/
*/
@SinceMirai
(
"0.39.2"
)
@SinceMirai
(
"0.39.2"
)
// Java: MessageUtils.FRIEND_IMAGE_ID_REGEX_1
// Java: MessageUtils.FRIEND_IMAGE_ID_REGEX_1
val
FRIEND_IMAGE_ID_REGEX_1
=
Regex
(
"""/
.{8}-(.{4}-){3}.
{12}"""
)
val
FRIEND_IMAGE_ID_REGEX_1
=
Regex
(
"""/
[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]
{12}"""
)
/**
/**
* 好友图片 ID 正则表达式 2
* 好友图片 ID 正则表达式 2
...
@@ -104,7 +104,7 @@ val FRIEND_IMAGE_ID_REGEX_1 = Regex("""/.{8}-(.{4}-){3}.{12}""")
...
@@ -104,7 +104,7 @@ val FRIEND_IMAGE_ID_REGEX_1 = Regex("""/.{8}-(.{4}-){3}.{12}""")
*/
*/
@SinceMirai
(
"0.39.2"
)
@SinceMirai
(
"0.39.2"
)
// Java: MessageUtils.FRIEND_IMAGE_ID_REGEX_2
// Java: MessageUtils.FRIEND_IMAGE_ID_REGEX_2
val
FRIEND_IMAGE_ID_REGEX_2
=
Regex
(
"""/[0-9]*-[0-9]*-[0-9a-
zA-Z
]{32}"""
)
val
FRIEND_IMAGE_ID_REGEX_2
=
Regex
(
"""/[0-9]*-[0-9]*-[0-9a-
fA-F
]{32}"""
)
/**
/**
* 群图片 ID 正则表达式
* 群图片 ID 正则表达式
...
@@ -114,7 +114,7 @@ val FRIEND_IMAGE_ID_REGEX_2 = Regex("""/[0-9]*-[0-9]*-[0-9a-zA-Z]{32}""")
...
@@ -114,7 +114,7 @@ val FRIEND_IMAGE_ID_REGEX_2 = Regex("""/[0-9]*-[0-9]*-[0-9a-zA-Z]{32}""")
@Suppress
(
"RegExpRedundantEscape"
)
// This is required on Android
@Suppress
(
"RegExpRedundantEscape"
)
// This is required on Android
@SinceMirai
(
"0.39.2"
)
@SinceMirai
(
"0.39.2"
)
// Java: MessageUtils.GROUP_IMAGE_ID_REGEX
// Java: MessageUtils.GROUP_IMAGE_ID_REGEX
val
GROUP_IMAGE_ID_REGEX
=
Regex
(
"""\{
.{8}-(.{4}-){3}.
{12}\}\.mirai"""
)
val
GROUP_IMAGE_ID_REGEX
=
Regex
(
"""\{
[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]
{12}\}\.mirai"""
)
/**
/**
* 在 `0.39.0` 前的图片的正则表示
* 在 `0.39.0` 前的图片的正则表示
...
@@ -125,7 +125,7 @@ val GROUP_IMAGE_ID_REGEX = Regex("""\{.{8}-(.{4}-){3}.{12}\}\.mirai""")
...
@@ -125,7 +125,7 @@ val GROUP_IMAGE_ID_REGEX = Regex("""\{.{8}-(.{4}-){3}.{12}\}\.mirai""")
@SinceMirai
(
"0.39.2"
)
@SinceMirai
(
"0.39.2"
)
@PlannedRemoval
(
"1.0.0"
)
@PlannedRemoval
(
"1.0.0"
)
// Java: MessageUtils.GROUP_IMAGE_ID_REGEX_OLD
// Java: MessageUtils.GROUP_IMAGE_ID_REGEX_OLD
val
GROUP_IMAGE_ID_REGEX_OLD
=
Regex
(
"""\{
.{8}-(.{4}-){3}.
{12}\}\..*"""
)
val
GROUP_IMAGE_ID_REGEX_OLD
=
Regex
(
"""\{
[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]
{12}\}\..*"""
)
/**
/**
* 通过 [Image.imageId] 构造一个 [Image] 以便发送.
* 通过 [Image.imageId] 构造一个 [Image] 以便发送.
...
@@ -145,7 +145,7 @@ fun Image(imageId: String): OfflineImage = when {
...
@@ -145,7 +145,7 @@ fun Image(imageId: String): OfflineImage = when {
imageId
matches
FRIEND_IMAGE_ID_REGEX_2
->
OfflineFriendImage
(
imageId
)
imageId
matches
FRIEND_IMAGE_ID_REGEX_2
->
OfflineFriendImage
(
imageId
)
imageId
matches
GROUP_IMAGE_ID_REGEX
->
OfflineGroupImage
(
imageId
)
imageId
matches
GROUP_IMAGE_ID_REGEX
->
OfflineGroupImage
(
imageId
)
imageId
matches
GROUP_IMAGE_ID_REGEX_OLD
->
OfflineGroupImage
(
imageId
)
imageId
matches
GROUP_IMAGE_ID_REGEX_OLD
->
OfflineGroupImage
(
imageId
)
else
->
throw
IllegalArgumentException
(
"
i
llegal imageId: $imageId. $ILLEGAL_IMAGE_ID_EXCEPTION_MESSAGE"
)
else
->
throw
IllegalArgumentException
(
"
I
llegal imageId: $imageId. $ILLEGAL_IMAGE_ID_EXCEPTION_MESSAGE"
)
}
}
// region 在线图片
// region 在线图片
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/impl.kt
View file @
df4cef62
...
@@ -323,7 +323,7 @@ internal inline fun Char.hexDigitToByte(): Int {
...
@@ -323,7 +323,7 @@ internal inline fun Char.hexDigitToByte(): Int {
in
'0'
..
'9'
->
this
-
'0'
in
'0'
..
'9'
->
this
-
'0'
in
'A'
..
'F'
->
10
+
(
this
-
'A'
)
in
'A'
..
'F'
->
10
+
(
this
-
'A'
)
in
'a'
..
'f'
->
10
+
(
this
-
'a'
)
in
'a'
..
'f'
->
10
+
(
this
-
'a'
)
else
->
throw
IllegalArgumentException
(
"
i
llegal hex digit: $this"
)
else
->
throw
IllegalArgumentException
(
"
I
llegal hex digit: $this"
)
}
}
}
}
...
@@ -333,7 +333,7 @@ internal fun String.skipToSecondHyphen(): Int {
...
@@ -333,7 +333,7 @@ internal fun String.skipToSecondHyphen(): Int {
this
.
forEachIndexed
{
index
,
c
->
this
.
forEachIndexed
{
index
,
c
->
if
(
c
==
'-'
&&
++
count
==
2
)
return
index
if
(
c
==
'-'
&&
++
count
==
2
)
return
index
}
}
error
(
"
cannot find two hyphen
s"
)
error
(
"
Internal error: failed skipToSecondHyphen, cannot find two hyphens. Input=$thi
s"
)
}
}
@JvmSynthetic
@JvmSynthetic
...
@@ -354,7 +354,7 @@ internal fun String.imageIdToMd5(offset: Int): ByteArray {
...
@@ -354,7 +354,7 @@ internal fun String.imageIdToMd5(offset: Int): ByteArray {
hasCurrent
=
true
hasCurrent
=
true
}
}
}
}
error
(
"
No enough chars
"
)
error
(
"
Internal error: failed imageIdToMd5, no enough chars. Input=$this, offset=$offset
"
)
}
}
@OptIn
(
ExperimentalStdlibApi
::
class
)
@OptIn
(
ExperimentalStdlibApi
::
class
)
...
...
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