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
92a1b0d4
Commit
92a1b0d4
authored
Apr 24, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add imageId regex, fix #262
parent
d57ce6eb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
8 deletions
+46
-8
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt
...c/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt
+46
-8
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt
View file @
92a1b0d4
...
@@ -20,6 +20,7 @@ import net.mamoe.mirai.BotImpl
...
@@ -20,6 +20,7 @@ import net.mamoe.mirai.BotImpl
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.contact.Group
import
net.mamoe.mirai.contact.Group
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
net.mamoe.mirai.utils.PlannedRemoval
import
net.mamoe.mirai.utils.SinceMirai
import
net.mamoe.mirai.utils.SinceMirai
import
kotlin.js.JsName
import
kotlin.js.JsName
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmMultifileClass
...
@@ -52,6 +53,44 @@ expect interface Image : Message, MessageContent {
...
@@ -52,6 +53,44 @@ expect interface Image : Message, MessageContent {
val
imageId
:
String
val
imageId
:
String
}
}
/**
* 好友图片 ID 正则表达式
*
* `/f8f1ab55-bf8e-4236-b55e-955848d7069f`
*/
@SinceMirai
(
"0.39.2"
)
// Java: MessageUtils.FRIEND_IMAGE_ID_REGEX_1
val
FRIEND_IMAGE_ID_REGEX_1
=
Regex
(
"""/.{8}-(.{4}-){3}.{12}"""
)
/**
* 好友图片 ID 正则表达式 2
*
* `/000000000-3814297509-BFB7027B9354B8F899A062061D74E206`
* @see FRIEND_IMAGE_ID_REGEX_1
*/
@SinceMirai
(
"0.39.2"
)
// Java: MessageUtils.FRIEND_IMAGE_ID_REGEX_2
val
FRIEND_IMAGE_ID_REGEX_2
=
Regex
(
"""/[0-9]*-[0-9]*-[0-9a-zA-Z]{32}"""
)
/**
* 群图片 ID 正则表达式
*
* `{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.mirai`
*/
@SinceMirai
(
"0.39.2"
)
// Java: MessageUtils.GROUP_IMAGE_ID_REGEX
val
GROUP_IMAGE_ID_REGEX
=
Regex
(
"""\{.{8}-(.{4}-){3}.{12}}\.mirai"""
)
/**
* 在 `0.39.1` 前的图片的正则表示
*/
@Deprecated
(
"Only for temporal use"
,
replaceWith
=
ReplaceWith
(
"GROUP_IMAGE_ID_REGEX"
,
"net.mamoe.mirai.message.data.GROUP_IMAGE_ID_REGEX"
))
@SinceMirai
(
"0.39.2"
)
@PlannedRemoval
(
"1.0.0"
)
// Java: MessageUtils.GROUP_IMAGE_ID_REGEX_OLD
val
GROUP_IMAGE_ID_REGEX_OLD
=
Regex
(
"""\{.{8}-(.{4}-){3}.{12}}\..*"""
)
/**
/**
* 通过 [Image.imageId] 构造一个 [Image] 以便发送.
* 通过 [Image.imageId] 构造一个 [Image] 以便发送.
* 这个图片必须是服务器已经存在的图片.
* 这个图片必须是服务器已经存在的图片.
...
@@ -62,25 +101,24 @@ expect interface Image : Message, MessageContent {
...
@@ -62,25 +101,24 @@ expect interface Image : Message, MessageContent {
* @see Image 获取更多说明
* @see Image 获取更多说明
* @see Image.imageId 获取更多说明
* @see Image.imageId 获取更多说明
*/
*/
@Suppress
(
"FunctionName"
)
@Suppress
(
"FunctionName"
,
"DEPRECATION"
)
@JsName
(
"newImage"
)
@JsName
(
"newImage"
)
@JvmName
(
"newImage"
)
@JvmName
(
"newImage"
)
fun
Image
(
imageId
:
String
):
OfflineImage
=
when
{
fun
Image
(
imageId
:
String
):
OfflineImage
=
when
{
imageId
.
startsWith
(
'/'
)
->
OfflineFriendImage
(
imageId
)
// /f8f1ab55-bf8e-4236-b55e-955848d7069f
imageId
matches
FRIEND_IMAGE_ID_REGEX_1
->
OfflineFriendImage
(
imageId
)
imageId
.
length
==
42
||
imageId
.
startsWith
(
'{'
)
&&
imageId
.
endsWith
(
'}'
)
->
OfflineGroupImage
(
imageId
)
// {01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.png
imageId
matches
FRIEND_IMAGE_ID_REGEX_2
->
OfflineFriendImage
(
imageId
)
imageId
matches
GROUP_IMAGE_ID_REGEX
->
OfflineGroupImage
(
imageId
)
imageId
matches
GROUP_IMAGE_ID_REGEX_OLD
->
OfflineGroupImage
(
imageId
)
else
->
throw
IllegalArgumentException
(
"illegal imageId: $imageId. $ILLEGAL_IMAGE_ID_EXCEPTION_MESSAGE"
)
else
->
throw
IllegalArgumentException
(
"illegal imageId: $imageId. $ILLEGAL_IMAGE_ID_EXCEPTION_MESSAGE"
)
}
}
@PlannedRemoval
(
"1.0.0"
)
@JvmSynthetic
@JvmSynthetic
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"FunctionName"
)
@Suppress
(
"FunctionName"
)
@JsName
(
"newImage"
)
@JsName
(
"newImage"
)
@JvmName
(
"newImage"
)
@JvmName
(
"newImage"
)
fun
Image2
(
imageId
:
String
):
Image
=
when
{
fun
Image2
(
imageId
:
String
):
Image
=
Image
(
imageId
)
imageId
.
startsWith
(
'/'
)
->
OfflineFriendImage
(
imageId
)
// /f8f1ab55-bf8e-4236-b55e-955848d7069f
imageId
.
length
==
42
||
imageId
.
startsWith
(
'{'
)
&&
imageId
.
endsWith
(
'}'
)
->
OfflineGroupImage
(
imageId
)
// {01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.png
else
->
throw
IllegalArgumentException
(
"illegal imageId: $imageId. $ILLEGAL_IMAGE_ID_EXCEPTION_MESSAGE"
)
}
@MiraiInternalAPI
(
"使用 Image"
)
@MiraiInternalAPI
(
"使用 Image"
)
sealed
class
AbstractImage
:
Image
{
sealed
class
AbstractImage
:
Image
{
...
...
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