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
c973fbd0
Commit
c973fbd0
authored
Oct 27, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed image
parent
eb024494
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
87 additions
and
324 deletions
+87
-324
README.md
README.md
+42
-265
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
...onMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
+42
-12
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
.../commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
+1
-33
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt
+1
-2
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
+0
-1
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt
...rai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt
+1
-11
No files found.
README.md
View file @
c973fbd0
This diff is collapsed.
Click to expand it.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
View file @
c973fbd0
...
...
@@ -152,12 +152,16 @@ internal typealias MessageReplier<T> = @MessageListenerDsl suspend T.(String) ->
internal
typealias
StringReplier
<
T
>
=
@MessageListenerDsl
suspend
T
.(
String
)
->
String
internal
suspend
inline
operator
fun
<
T
:
SenderAndMessage
<
*
>>
MessageListener
<
T
>.
invoke
(
t
:
T
)
=
this
.
invoke
(
t
,
t
.
message
.
stringValue
)
internal
suspend
inline
operator
fun
<
T
:
SenderAndMessage
<
*
>>
MessageListener
<
T
>.
invoke
(
t
:
T
)
=
this
.
invoke
(
t
,
t
.
message
.
stringValue
)
@JvmName
(
"invoke1"
)
//Avoid Platform declaration clash
internal
suspend
inline
operator
fun
<
T
:
SenderAndMessage
<
*
>>
StringReplier
<
T
>.
invoke
(
t
:
T
):
String
=
this
.
invoke
(
t
,
t
.
message
.
stringValue
)
internal
suspend
inline
operator
fun
<
T
:
SenderAndMessage
<
*
>>
StringReplier
<
T
>.
invoke
(
t
:
T
):
String
=
this
.
invoke
(
t
,
t
.
message
.
stringValue
)
@JvmName
(
"invoke2"
)
//Avoid Platform declaration clash
internal
suspend
inline
operator
fun
<
T
:
SenderAndMessage
<
*
>>
MessageReplier
<
T
>.
invoke
(
t
:
T
):
Message
=
this
.
invoke
(
t
,
t
.
message
.
stringValue
)
internal
suspend
inline
operator
fun
<
T
:
SenderAndMessage
<
*
>>
MessageReplier
<
T
>.
invoke
(
t
:
T
):
Message
=
this
.
invoke
(
t
,
t
.
message
.
stringValue
)
/**
* 消息订阅构造器
...
...
@@ -171,22 +175,48 @@ internal suspend inline operator fun <T : SenderAndMessage<*>> MessageReplier<T>
class
MessageSubscribersBuilder
<
T
:
SenderAndMessage
<
*
>>(
val
handlerConsumer
:
suspend
(
MessageListener
<
T
>)
->
Unit
)
{
suspend
inline
fun
case
(
equals
:
String
,
trim
:
Boolean
=
true
,
noinline
listener
:
MessageListener
<
T
>)
=
content
({
equals
==
if
(
trim
)
it
.
trim
()
else
it
},
listener
)
suspend
inline
fun
contains
(
value
:
String
,
noinline
listener
:
MessageListener
<
T
>)
=
content
({
value
in
it
},
listener
)
suspend
inline
fun
startsWith
(
prefix
:
String
,
removePrefix
:
Boolean
=
false
,
noinline
listener
:
MessageListener
<
T
>)
=
content
({
it
.
startsWith
(
prefix
)
})
{
if
(
removePrefix
)
listener
.
invoke
(
this
,
this
.
message
.
stringValue
.
substringAfter
(
prefix
))
else
listener
(
this
)
}
suspend
inline
fun
case
(
equals
:
String
,
trim
:
Boolean
=
true
,
noinline
listener
:
MessageListener
<
T
>)
=
content
({
equals
==
if
(
trim
)
it
.
trim
()
else
it
},
listener
)
suspend
inline
fun
contains
(
value
:
String
,
noinline
listener
:
MessageListener
<
T
>)
=
content
({
value
in
it
},
listener
)
suspend
inline
fun
startsWith
(
prefix
:
String
,
removePrefix
:
Boolean
=
false
,
noinline
listener
:
MessageListener
<
T
>
)
=
content
({
it
.
startsWith
(
prefix
)
})
{
if
(
removePrefix
)
listener
.
invoke
(
this
,
this
.
message
.
stringValue
.
substringAfter
(
prefix
)
)
else
listener
(
this
)
}
suspend
inline
fun
endsWith
(
start
:
String
,
noinline
listener
:
MessageListener
<
T
>)
=
content
({
it
.
endsWith
(
start
)
},
listener
)
suspend
inline
fun
endsWith
(
start
:
String
,
noinline
listener
:
MessageListener
<
T
>)
=
content
({
it
.
endsWith
(
start
)
},
listener
)
suspend
inline
fun
sentBy
(
id
:
UInt
,
noinline
listener
:
MessageListener
<
T
>)
=
content
({
sender
.
id
==
id
},
listener
)
suspend
inline
fun
sentBy
(
id
:
Long
,
noinline
listener
:
MessageListener
<
T
>)
=
sentBy
(
id
.
toUInt
(),
listener
)
suspend
inline
fun
<
reified
M
:
Message
>
has
(
noinline
listener
:
MessageListener
<
T
>)
=
handlerConsumer
{
if
(
message
.
any
<
M
>())
listener
(
this
)
}
suspend
inline
fun
<
reified
M
:
Message
>
has
(
noinline
listener
:
MessageListener
<
T
>)
=
handlerConsumer
{
if
(
message
.
any
<
M
>())
listener
(
this
)
}
suspend
inline
fun
content
(
noinline
filter
:
T
.(
String
)
->
Boolean
,
noinline
listener
:
MessageListener
<
T
>)
=
handlerConsumer
{
if
(
this
.
filter
(
message
.
stringValue
))
listener
(
this
)
}
suspend
infix
fun
String
.
caseReply
(
replier
:
String
)
=
case
(
this
,
true
)
{
this
@
case
.
reply
(
replier
)
}
suspend
infix
fun
String
.
caseReply
(
replier
:
StringReplier
<
T
>)
=
case
(
this
,
true
)
{
this
@
case
.
reply
(
replier
(
this
))
}
suspend
infix
fun
String
.
containsReply
(
replier
:
StringReplier
<
T
>)
=
content
({
this
@
containsReply
in
it
})
{
replier
(
this
)
}
suspend
infix
fun
String
.
startsWithReply
(
replier
:
StringReplier
<
T
>)
=
content
({
it
.
startsWith
(
this
@
startsWithReply
)
})
{
replier
(
this
)
}
suspend
infix
fun
String
.
endswithReply
(
replier
:
StringReplier
<
T
>)
=
content
({
it
.
endsWith
(
this
@
endswithReply
)
})
{
replier
(
this
)
}
suspend
infix
fun
String
.
containsReply
(
replier
:
String
)
=
content
({
this
@
containsReply
in
it
})
{
this
@
content
.
reply
(
replier
)
}
suspend
infix
fun
String
.
containsReply
(
replier
:
StringReplier
<
T
>)
=
content
({
this
@
containsReply
in
it
})
{
replier
(
this
)
}
suspend
infix
fun
String
.
startsWithReply
(
replier
:
StringReplier
<
T
>)
=
content
({
it
.
startsWith
(
this
@
startsWithReply
)
})
{
replier
(
this
)
}
suspend
infix
fun
String
.
endswithReply
(
replier
:
StringReplier
<
T
>)
=
content
({
it
.
endsWith
(
this
@
endswithReply
)
})
{
replier
(
this
)
}
suspend
infix
fun
String
.
reply
(
reply
:
String
)
=
case
(
this
)
{
this
@
case
.
reply
(
reply
)
}
suspend
infix
fun
String
.
reply
(
reply
:
StringReplier
<
T
>)
=
case
(
this
)
{
this
@
case
.
reply
(
reply
(
this
))
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
View file @
c973fbd0
...
...
@@ -68,15 +68,6 @@ suspend fun httpPostFriendImage(
uKeyHex
=
uKeyHex
)
as
HttpStatusCode
).
value
.
also
{
println
(
it
)
}
==
200
/*
httpPostFriendImageOld(uKeyHex, botAccount, imageInput.readBytes().toReadPacket())
expect suspend fun httpPostFriendImageOld(
uKeyHex: String,
botNumber: UInt,
imageData: ByteReadPacket
): Boolean
*/
/**
* 上传群图片
*/
...
...
@@ -95,27 +86,6 @@ suspend fun httpPostGroupImage(
inputSize
=
inputSize
,
uKeyHex
=
uKeyHex
)
as
HttpStatusCode
).
value
.
also
{
println
(
it
)
}
==
200
/* = (httpClient.post {
url {
protocol = URLProtocol.HTTP
host = "htdata2.qq.com"
path("cgi-bin/httpconn")
parameters["htcmd"] = "0x6ff0071"
parameters["ver"] = "5603"
parameters["term"] = "pc"
parameters["ukey"] = uKeyHex
parameters["filesize"] = inputSize.toString()
parameters["range"] = 0.toString()
parameters["uin"] = botAccount.toLong().toString()
parameters["groupcode"] = groupId.value.toLong().toString()
// userAgent("QQClient")
}
println(url.buildString())
body = ByteArrayContent(imageInput.readBytes())
//configureBody(inputSize, imageInput)
} as HttpStatusCode).value.also { println(it) } == 200*/
@Suppress
(
"SpellCheckingInspection"
)
private
suspend
inline
fun
<
reified
T
>
HttpClient
.
postImage
(
...
...
@@ -134,9 +104,7 @@ private suspend inline fun <reified T> HttpClient.postImage(
parameters
[
"htcmd"
]
=
htcmd
parameters
[
"uin"
]
=
uin
.
toLong
().
toString
()
if
(
groupcode
!=
null
)
{
parameters
[
"groupcode"
]
=
groupcode
.
value
.
toLong
().
toString
()
}
if
(
groupcode
!=
null
)
parameters
[
"groupcode"
]
=
groupcode
.
value
.
toLong
().
toString
()
parameters
[
"term"
]
=
"pc"
parameters
[
"ver"
]
=
"5603"
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt
View file @
c973fbd0
...
...
@@ -49,7 +49,6 @@ fun BufferedImage.toExternalImage(formatName: String = "gif"): ExternalImage {
*/
@Throws
(
IOException
::
class
)
fun
File
.
toExternalImage
():
ExternalImage
{
println
(
this
.
path
)
val
input
=
ImageIO
.
createImageInputStream
(
this
)
checkNotNull
(
input
)
{
"Unable to read file(path=${this.path}), no ImageInputStream found"
}
val
image
=
ImageIO
.
getImageReaders
(
input
).
asSequence
().
firstOrNull
()
?:
error
(
"Unable to read file(path=${this.path}), no ImageReader found"
)
...
...
@@ -58,7 +57,7 @@ fun File.toExternalImage(): ExternalImage {
return
ExternalImage
(
width
=
image
.
getWidth
(
0
),
height
=
image
.
getHeight
(
0
),
md5
=
input
.
md5
(),
md5
=
this
.
inputStream
()
.
md5
(),
imageFormat
=
image
.
formatName
,
input
=
this
.
inputStream
().
asInput
(
IoBuffer
.
Pool
),
inputSize
=
this
.
length
()
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
View file @
c973fbd0
...
...
@@ -110,7 +110,6 @@ internal actual fun HttpRequestBuilder.configureBody(
input
.
readFully
(
buffer
,
0
,
1
)
channel
.
writeFully
(
buffer
,
0
,
1
)
}
println
(
"已经发送$contentLength"
)
}
}
}
\ No newline at end of file
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt
View file @
c973fbd0
...
...
@@ -8,7 +8,6 @@ import net.mamoe.mirai.event.subscribeMessages
import
net.mamoe.mirai.login
import
net.mamoe.mirai.message.Image
import
net.mamoe.mirai.message.ImageId
import
net.mamoe.mirai.message.sendAsImageTo
import
net.mamoe.mirai.network.protocol.tim.packet.login.requireSuccess
import
java.io.File
...
...
@@ -42,17 +41,8 @@ suspend fun main() {
reply
(
Image
(
ImageId
(
it
)))
}
startsWith
(
"上传图片"
,
removePrefix
=
true
)
{
File
(
"C:/Users/Him18/Desktop/$it"
).
sendAsImageTo
(
subject
)
}
case
(
"随机色图"
)
{
reply
(
"Downloading started"
)
val
received
=
Gentlemen
.
getOrPut
(
subject
).
receive
()
reply
(
"Received Image"
)
received
.
image
.
await
().
send
()
reply
(
"Thanks for using"
)
Gentlemen
.
getOrPut
(
subject
).
receive
().
image
.
await
().
send
()
}
"色图"
caseReply
{
...
...
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