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
d4dd720e
Commit
d4dd720e
authored
Oct 28, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update demo
parent
d3270bb3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
58 deletions
+7
-58
mirai-core/build.gradle
mirai-core/build.gradle
+0
-1
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/GentleImage.kt
...o-gentleman/src/main/kotlin/demo/gentleman/GentleImage.kt
+1
-9
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Gentleman.kt
...emo-gentleman/src/main/kotlin/demo/gentleman/Gentleman.kt
+6
-36
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt
...rai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt
+0
-12
No files found.
mirai-core/build.gradle
View file @
d4dd720e
...
...
@@ -94,7 +94,6 @@ kotlin {
}
compileKotlinJvm
{
}
compileTestJava
{
...
...
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/GentleImage.kt
View file @
d4dd720e
...
...
@@ -37,11 +37,7 @@ class GentleImage {
lateinit
var
contact
:
Contact
val
image
:
Deferred
<
Image
>
by
lazy
{
GlobalScope
.
async
{
// runBlocking {
// CompletableDeferred(suspend {
delay
((
Math
.
random
()
*
5000L
).
toLong
())
// MiraiLogger.logPurple("Downloading image: $name")
withContext
(
Dispatchers
.
IO
)
{
Jsoup
.
connect
(
sample_url
)
.
userAgent
(
UserAgent
.
randomUserAgent
)
...
...
@@ -50,11 +46,7 @@ class GentleImage {
.
maxBodySize
(
Int
.
MAX_VALUE
)
.
execute
()
.
bodyStream
()
}.
upload
(
contact
).
also
{
//MiraiLogger.logPurple("Downloaded image: $name")
}
// }())
// }
}.
upload
(
contact
)
}
}
}
...
...
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Gentleman.kt
View file @
d4dd720e
...
...
@@ -10,20 +10,20 @@ import net.mamoe.mirai.contact.Contact
/**
* 最少缓存的图片数量
*/
private
const
val
IMAGE_BUFFER_CAPACITY
:
Int
=
5
0
private
const
val
IMAGE_BUFFER_CAPACITY
:
Int
=
5
/**
*
每次补充的数量
*
为不同的联系人提供图片
*/
private
const
val
FILL_COUNT
:
Int
=
IMAGE_BUFFER_CAPACITY
@ExperimentalUnsignedTypes
@ExperimentalCoroutinesApi
object
Gentlemen
:
MutableMap
<
UInt
,
Gentleman
>
by
mutableMapOf
()
{
fun
getOrPut
(
key
:
Contact
):
Gentleman
=
this
.
getOrPut
(
key
.
id
)
{
Gentleman
(
key
)
}
}
/**
* 工作是缓存图片
*/
@ExperimentalCoroutinesApi
class
Gentleman
(
private
val
contact
:
Contact
)
:
Channel
<
GentleImage
>
by
Channel
(
IMAGE_BUFFER_CAPACITY
)
{
init
{
...
...
@@ -34,38 +34,8 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel(
sample_url
=
"http://dev.itxtech.org:10322/randomImg.uue?tdsourcetag=s_pctim_aiomsg&size=large"
contact
=
this
@Gentleman
.
contact
image
.
await
()
image
// start downloading
})
/*
val response = withContext(Dispatchers.IO) {
tryNTimes(2) {
Jsoup.connect("https://yande.re/post.json?")
.userAgent(UserAgent.randomUserAgent)
.data("limit", "20")
.data("page", (Random.Default.nextInt(12000)).toString())
.ignoreContentType(true)
.timeout(20_000)
.method(Connection.Method.GET)
.execute()
}
}
check(response.statusCode() == 200) { "failed to get resources" }
JSONArray.parseArray(response.body(), GentleImage::class.java)
.filterNot { it.tags in ForbiddenKeyWords }
.sortedBy { it.score }
.let {
if (it.size <= FILL_COUNT) {
it
} else it.slice(0..FILL_COUNT)
}
.forEach {
it.contact = contact
it.image//start downloading
send(it)
}*/
}
}
}
...
...
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt
View file @
d4dd720e
...
...
@@ -7,7 +7,6 @@ import kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.BotAccount
import
net.mamoe.mirai.event.subscribeGroupMessages
import
net.mamoe.mirai.event.subscribeMessages
import
net.mamoe.mirai.login
import
net.mamoe.mirai.network.protocol.tim.packet.login.requireSuccess
...
...
@@ -55,16 +54,5 @@ suspend fun main() {
}
bot
.
subscribeGroupMessages
{
startsWith
(
"图片"
,
removePrefix
=
true
)
{
HPictureSession
(
group
,
sender
,
it
)
}
startsWith
(
"minstar="
,
removePrefix
=
true
)
{
minstar
=
it
.
toInt
()
reply
(
"minStar set to $minstar"
)
}
}
bot
.
network
.
awaitDisconnection
()
//等到直到断开连接
}
\ 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