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
ead17724
Commit
ead17724
authored
Oct 28, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update docs
parent
e7725bdc
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
199 deletions
+79
-199
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
...onMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
+67
-63
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
.../src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
+4
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/SendFriendMessagePacket.kt
...ork/protocol/tim/packet/action/SendFriendMessagePacket.kt
+0
-6
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/ServerLoginResponse.kt
.../network/protocol/tim/packet/login/ServerLoginResponse.kt
+4
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt
.../commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt
+1
-1
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Gentleman.kt
...emo-gentleman/src/main/kotlin/demo/gentleman/Gentleman.kt
+3
-124
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
View file @
ead17724
This diff is collapsed.
Click to expand it.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
View file @
ead17724
...
@@ -83,14 +83,14 @@ interface Message {
...
@@ -83,14 +83,14 @@ interface Message {
if
(
tail
is
MessageChain
)
tail
.
concat
(
this
)
/*MessageChainImpl(this).also { tail.forEach { child -> it.concat(child) } }*/
if
(
tail
is
MessageChain
)
tail
.
concat
(
this
)
/*MessageChainImpl(this).also { tail.forEach { child -> it.concat(child) } }*/
else
MessageChainImpl
(
this
,
tail
)
else
MessageChainImpl
(
this
,
tail
)
infix
operator
fun
plus
(
another
:
Message
):
MessageChain
=
this
.
concat
(
another
)
operator
fun
plus
(
another
:
Message
):
MessageChain
=
this
.
concat
(
another
)
infix
operator
fun
plus
(
another
:
String
):
MessageChain
=
this
.
concat
(
another
.
toMessage
())
operator
fun
plus
(
another
:
String
):
MessageChain
=
this
.
concat
(
another
.
toMessage
())
}
}
/**
/**
* 将 [this] 发送给指定联系人
* 将 [this] 发送给指定联系人
*/
*/
suspend
fun
Message
.
sendTo
(
contact
:
Contact
)
=
contact
.
sendMessage
(
this
)
suspend
inline
fun
Message
.
sendTo
(
contact
:
Contact
)
=
contact
.
sendMessage
(
this
)
// endregion
// endregion
// region PlainText
// region PlainText
...
@@ -172,7 +172,7 @@ inline class Face(val id: FaceID) : Message {
...
@@ -172,7 +172,7 @@ inline class Face(val id: FaceID) : Message {
// region MessageChain
// region MessageChain
// ==================================== MessageChain ====================================
// ==================================== MessageChain ====================================
// region constructors
// region constructor
function
s
/**
/**
* 构造无初始元素的可修改的 [MessageChain]. 初始大小将会被设定为 8
* 构造无初始元素的可修改的 [MessageChain]. 初始大小将会被设定为 8
*/
*/
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/SendFriendMessagePacket.kt
View file @
ead17724
...
@@ -5,8 +5,6 @@ package net.mamoe.mirai.network.protocol.tim.packet.action
...
@@ -5,8 +5,6 @@ package net.mamoe.mirai.network.protocol.tim.packet.action
import
kotlinx.io.core.*
import
kotlinx.io.core.*
import
net.mamoe.mirai.message.MessageChain
import
net.mamoe.mirai.message.MessageChain
import
net.mamoe.mirai.message.internal.toPacket
import
net.mamoe.mirai.message.internal.toPacket
import
net.mamoe.mirai.message.toChain
import
net.mamoe.mirai.message.toMessage
import
net.mamoe.mirai.network.protocol.tim.TIMProtocol
import
net.mamoe.mirai.network.protocol.tim.TIMProtocol
import
net.mamoe.mirai.network.protocol.tim.packet.OutgoingPacket
import
net.mamoe.mirai.network.protocol.tim.packet.OutgoingPacket
import
net.mamoe.mirai.network.protocol.tim.packet.PacketId
import
net.mamoe.mirai.network.protocol.tim.packet.PacketId
...
@@ -15,10 +13,6 @@ import net.mamoe.mirai.network.protocol.tim.packet.ResponsePacket
...
@@ -15,10 +13,6 @@ import net.mamoe.mirai.network.protocol.tim.packet.ResponsePacket
import
net.mamoe.mirai.utils.io.*
import
net.mamoe.mirai.utils.io.*
import
net.mamoe.mirai.utils.md5
import
net.mamoe.mirai.utils.md5
fun
main
()
{
println
(
"牛逼"
.
toMessage
().
toChain
().
toPacket
(
true
).
readBytes
().
toUHexString
())
}
@PacketId
(
0
x00_CDu
)
@PacketId
(
0
x00_CDu
)
@PacketVersion
(
date
=
"2019.10.19"
,
timVersion
=
"2.3.2.21173"
)
@PacketVersion
(
date
=
"2019.10.19"
,
timVersion
=
"2.3.2.21173"
)
class
SendFriendMessagePacket
(
class
SendFriendMessagePacket
(
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/ServerLoginResponse.kt
View file @
ead17724
...
@@ -83,7 +83,10 @@ class LoginResponseSuccessPacket(input: ByteReadPacket) : ServerLoginResponsePac
...
@@ -83,7 +83,10 @@ class LoginResponseSuccessPacket(input: ByteReadPacket) : ServerLoginResponsePac
discardExact
(
60
)
//00 20 01 60 C5 A1 39 7A 12 8E BC 34 C3 56 70 E3 1A ED 20 67 ED A9 DB 06 C1 70 81 3C 01 69 0D FF 63 DA 00 00 01 03 00 14 00 01 00 10 60 C9 5D A7 45 70 04 7F 21 7D 84 50 5C 66 A5 C6
discardExact
(
60
)
//00 20 01 60 C5 A1 39 7A 12 8E BC 34 C3 56 70 E3 1A ED 20 67 ED A9 DB 06 C1 70 81 3C 01 69 0D FF 63 DA 00 00 01 03 00 14 00 01 00 10 60 C9 5D A7 45 70 04 7F 21 7D 84 50 5C 66 A5 C6
discardExact
(
when
(
readUByte
().
toUInt
())
{
discardExact
(
when
(
readUByte
().
toUInt
())
{
0
x00u
->
if
(
readUByte
().
toUInt
()
==
0
x33u
)
28
else
null
0
x00u
->
when
(
readUByte
().
toUInt
())
{
0
x33u
->
28
else
->
null
}
0
x01u
->
when
(
readUByte
().
toUInt
())
{
0
x01u
->
when
(
readUByte
().
toUInt
())
{
0
x07u
->
0
0
x07u
->
0
0
x10u
->
64
0
x10u
->
64
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt
View file @
ead17724
...
@@ -75,7 +75,7 @@ suspend fun ExternalImage.upload(contact: Contact): Image = when (contact) {
...
@@ -75,7 +75,7 @@ suspend fun ExternalImage.upload(contact: Contact): Image = when (contact) {
/**
/**
* 将图片发送给 [this]
* 将图片发送给 [this]
*/
*/
suspend
fun
Contact
.
sendImage
(
image
:
ExternalImage
)
=
image
.
sendTo
(
this
)
suspend
inline
fun
Contact
.
sendImage
(
image
:
ExternalImage
)
=
image
.
sendTo
(
this
)
private
operator
fun
ByteArray
.
get
(
range
:
IntRange
):
String
=
buildString
{
private
operator
fun
ByteArray
.
get
(
range
:
IntRange
):
String
=
buildString
{
range
.
forEach
{
range
.
forEach
{
...
...
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Gentleman.kt
View file @
ead17724
package
demo.gentleman
package
demo.gentleman
import
kotlinx.coroutines.
*
import
kotlinx.coroutines.
ExperimentalCoroutinesApi
import
kotlinx.coroutines.
Dispatchers.IO
import
kotlinx.coroutines.
GlobalScope
import
kotlinx.coroutines.channels.Channel
import
kotlinx.coroutines.channels.Channel
import
net.mamoe.ex.content.RandomAccessHDImage
import
kotlinx.coroutines.launch
import
net.mamoe.ex.network.ExNetwork
import
net.mamoe.ex.network.connections.defaults.DownloadHDImageStreamSpider
import
net.mamoe.ex.network.connections.defaults.ExIPWhiteListSpider
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.contact.Group
import
net.mamoe.mirai.contact.QQ
import
net.mamoe.mirai.message.sendTo
import
net.mamoe.mirai.message.uploadImage
import
net.mamoe.robot.AsyncTaskPool
import
java.io.Closeable
import
java.io.InputStream
import
java.util.*
import
java.util.concurrent.ExecutionException
import
java.util.concurrent.Future
/**
/**
...
@@ -37,103 +24,6 @@ object Gentlemen : MutableMap<UInt, Gentleman> by mutableMapOf() {
...
@@ -37,103 +24,6 @@ object Gentlemen : MutableMap<UInt, Gentleman> by mutableMapOf() {
}
}
private
val
sessionMap
=
LinkedHashMap
<
Long
,
HPictureSession
>()
val
ERROR_LINK
=
"https://i.loli.net/2019/08/05/usINjXSiZxrQJkT.jpg"
val
TITLE_PICTURE_LINK
=
"https://i.loli.net/2019/08/04/B5ZMw1rdzVQI7Yv.jpg"
var
minstar
=
100
class
HPictureSession
constructor
(
private
val
group
:
Group
,
private
val
sender
:
QQ
,
val
keyword
:
String
)
:
Closeable
{
private
var
hdImage
:
RandomAccessHDImage
?
=
null
var
sentCount
:
Int
=
0
set
(
sentCount
)
{
field
=
this
.
sentCount
}
//已经发送了几个 ImageSet
private
var
fetchTask
:
Future
<
RandomAccessHDImage
>?
=
null
init
{
AsyncTaskPool
.
submit
{
try
{
Thread
.
sleep
((
1000
*
60
*
10
).
toLong
())
//10min
}
catch
(
ignored
:
InterruptedException
)
{
}
close
()
}
}
init
{
GlobalScope
.
launch
{
reloadImage
()
}
}
private
suspend
fun
reloadImage
()
{
if
(
keyword
.
isEmpty
())
{
group
.
sendMessage
(
"正在搜寻随机色图"
)
}
else
{
group
.
sendMessage
(
"正在搜寻有关 $keyword 的色图"
)
}
try
{
withContext
(
IO
)
{
if
(!
ExNetwork
.
doSpider
(
ExIPWhiteListSpider
()).
get
())
{
group
.
sendMessage
(
"无法连接EX"
)
close
()
return
@
withContext
}
}
}
catch
(
e
:
InterruptedException
)
{
e
.
printStackTrace
()
close
()
return
}
catch
(
e
:
ExecutionException
)
{
e
.
printStackTrace
()
close
()
return
}
this
.
fetchTask
=
ExNetwork
.
getRandomImage
(
keyword
,
minstar
)
{
value
->
this
.
hdImage
=
value
if
(
this
.
hdImage
==
null
)
{
runBlocking
{
group
.
sendMessage
(
"没找到"
)
}
close
()
}
else
{
with
(
this
.
hdImage
!!
)
{
if
(
this
.
picId
!=
null
)
{
runBlocking
{
group
.
sendMessage
(
picId
)
}
}
else
{
AsyncTaskPool
.
submit
{
try
{
runBlocking
{
group
.
uploadImage
(
ExNetwork
.
doSpider
(
DownloadHDImageStreamSpider
(
this
@
with
)).
get
()
as
InputStream
).
sendTo
(
group
)
}
}
catch
(
var7
:
Exception
)
{
var7
.
printStackTrace
()
}
}
}
}
}
}
}
override
fun
close
()
{
this
.
hdImage
=
null
if
(
this
.
fetchTask
!=
null
)
{
if
(!
this
.
fetchTask
!!
.
isCancelled
&&
!
this
.
fetchTask
!!
.
isDone
)
{
this
.
fetchTask
!!
.
cancel
(
true
)
}
}
this
.
fetchTask
=
null
sessionMap
.
entries
.
removeIf
{
longHPictureSessionEntry
->
longHPictureSessionEntry
.
value
===
this
}
}
}
@ExperimentalCoroutinesApi
@ExperimentalCoroutinesApi
class
Gentleman
(
private
val
contact
:
Contact
)
:
Channel
<
GentleImage
>
by
Channel
(
IMAGE_BUFFER_CAPACITY
)
{
class
Gentleman
(
private
val
contact
:
Contact
)
:
Channel
<
GentleImage
>
by
Channel
(
IMAGE_BUFFER_CAPACITY
)
{
init
{
init
{
...
@@ -179,15 +69,4 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel(
...
@@ -179,15 +69,4 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel(
}
}
}
}
}
}
}
object
ForbiddenKeyWords
:
List
<
String
>
by
listOf
(
"miku"
,
"vocaloid"
,
"kuriyama"
,
"mirai"
)
{
override
fun
contains
(
element
:
String
):
Boolean
{
return
this
.
stream
().
anyMatch
{
element
.
contains
(
it
,
ignoreCase
=
true
)
}
}
}
}
\ No newline at end of file
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