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
3f56faae
Commit
3f56faae
authored
Oct 27, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed image
parent
c973fbd0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
62 deletions
+38
-62
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
.../commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
+22
-19
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
+0
-33
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/GentleImage.kt
...o-gentleman/src/main/kotlin/demo/gentleman/GentleImage.kt
+2
-3
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Gentleman.kt
...emo-gentleman/src/main/kotlin/demo/gentleman/Gentleman.kt
+14
-7
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
View file @
3f56faae
...
@@ -66,7 +66,7 @@ suspend fun httpPostFriendImage(
...
@@ -66,7 +66,7 @@ suspend fun httpPostFriendImage(
imageInput
=
imageInput
,
imageInput
=
imageInput
,
inputSize
=
inputSize
,
inputSize
=
inputSize
,
uKeyHex
=
uKeyHex
uKeyHex
=
uKeyHex
)
as
HttpStatusCode
).
value
.
also
{
println
(
it
)
}
==
200
)
as
HttpStatusCode
).
value
==
200
/**
/**
* 上传群图片
* 上传群图片
...
@@ -85,7 +85,7 @@ suspend fun httpPostGroupImage(
...
@@ -85,7 +85,7 @@ suspend fun httpPostGroupImage(
imageInput
=
imageInput
,
imageInput
=
imageInput
,
inputSize
=
inputSize
,
inputSize
=
inputSize
,
uKeyHex
=
uKeyHex
uKeyHex
=
uKeyHex
)
as
HttpStatusCode
).
value
.
also
{
println
(
it
)
}
==
200
)
as
HttpStatusCode
).
value
==
200
@Suppress
(
"SpellCheckingInspection"
)
@Suppress
(
"SpellCheckingInspection"
)
private
suspend
inline
fun
<
reified
T
>
HttpClient
.
postImage
(
private
suspend
inline
fun
<
reified
T
>
HttpClient
.
postImage
(
...
@@ -95,28 +95,31 @@ private suspend inline fun <reified T> HttpClient.postImage(
...
@@ -95,28 +95,31 @@ private suspend inline fun <reified T> HttpClient.postImage(
imageInput
:
Input
,
imageInput
:
Input
,
inputSize
:
Long
,
inputSize
:
Long
,
uKeyHex
:
String
uKeyHex
:
String
):
T
=
post
{
):
T
=
try
{
url
{
post
{
protocol
=
URLProtocol
.
HTTP
url
{
host
=
"htdata2.qq.com"
protocol
=
URLProtocol
.
HTTP
path
(
"cgi-bin/httpconn"
)
host
=
"htdata2.qq.com"
path
(
"cgi-bin/httpconn"
)
parameters
[
"htcmd"
]
=
htcmd
parameters
[
"htcmd"
]
=
htcmd
parameters
[
"uin"
]
=
uin
.
toLong
().
toString
()
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
[
"term"
]
=
"pc"
parameters
[
"ver"
]
=
"5603"
parameters
[
"ver"
]
=
"5603"
parameters
[
"filesize"
]
=
inputSize
.
toString
()
parameters
[
"filesize"
]
=
inputSize
.
toString
()
parameters
[
"range"
]
=
0
.
toString
()
parameters
[
"range"
]
=
0
.
toString
()
parameters
[
"ukey"
]
=
uKeyHex
parameters
[
"ukey"
]
=
uKeyHex
userAgent
(
"QQClient"
)
userAgent
(
"QQClient"
)
}
}
println
(
url
.
buildString
())
configureBody
(
inputSize
,
imageInput
)
configureBody
(
inputSize
,
imageInput
)
}
}
finally
{
imageInput
.
close
()
}
}
internal
expect
fun
HttpRequestBuilder
.
configureBody
(
inputSize
:
Long
,
input
:
Input
)
internal
expect
fun
HttpRequestBuilder
.
configureBody
(
inputSize
:
Long
,
input
:
Input
)
\ No newline at end of file
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
View file @
3f56faae
...
@@ -59,39 +59,6 @@ actual fun solveIpAddress(hostname: String): String = InetAddress.getByName(host
...
@@ -59,39 +59,6 @@ actual fun solveIpAddress(hostname: String): String = InetAddress.getByName(host
actual
fun
localIpAddress
():
String
=
InetAddress
.
getLocalHost
().
hostAddress
actual
fun
localIpAddress
():
String
=
InetAddress
.
getLocalHost
().
hostAddress
/*
actual suspend fun httpPostFriendImageOld(
uKeyHex: String,
botNumber: UInt,
imageData: ByteReadPacket
): Boolean = Jsoup.connect(
"http://htdata2.qq.com/cgi-bin/httpconn" +
"?htcmd=0x6ff0070" +
"&ver=5603" +
"&ukey=$uKeyHex" +
"&filesize=${imageData.remaining}" +
"&range=0" +
"&uin=$botNumber"
)
.postImage(imageData)
private suspend fun Connection.postImage(image: ByteReadPacket): Boolean = this
.userAgent("QQClient")
.header("Content-Length", image.remaining.toString())
.requestBody(String(image.readBytes(), Charsets.ISO_8859_1))
.method(Connection.Method.POST)
.postDataCharset("ISO_8859_1")
.header("Content-type", "image/gif")
.ignoreContentType(true)
.suspendExecute()
.statusCode() == 200
private suspend fun Connection.suspendExecute(): Connection.Response = withContext(Dispatchers.IO) {
execute()
}
*/
internal
actual
val
httpClient
:
HttpClient
=
HttpClient
(
CIO
)
internal
actual
val
httpClient
:
HttpClient
=
HttpClient
(
CIO
)
internal
actual
fun
HttpRequestBuilder
.
configureBody
(
internal
actual
fun
HttpRequestBuilder
.
configureBody
(
...
...
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/GentleImage.kt
View file @
3f56faae
...
@@ -4,7 +4,6 @@ import kotlinx.coroutines.*
...
@@ -4,7 +4,6 @@ import kotlinx.coroutines.*
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.message.Image
import
net.mamoe.mirai.message.Image
import
net.mamoe.mirai.message.upload
import
net.mamoe.mirai.message.upload
import
net.mamoe.mirai.utils.MiraiLogger
import
org.jsoup.Jsoup
import
org.jsoup.Jsoup
class
GentleImage
{
class
GentleImage
{
...
@@ -42,7 +41,7 @@ class GentleImage {
...
@@ -42,7 +41,7 @@ class GentleImage {
// CompletableDeferred(suspend {
// CompletableDeferred(suspend {
delay
((
Math
.
random
()
*
5000L
).
toLong
())
delay
((
Math
.
random
()
*
5000L
).
toLong
())
MiraiLogger
.
logPurple
(
"Downloading image: $name"
)
//
MiraiLogger.logPurple("Downloading image: $name")
withContext
(
Dispatchers
.
IO
)
{
withContext
(
Dispatchers
.
IO
)
{
Jsoup
.
connect
(
sample_url
)
Jsoup
.
connect
(
sample_url
)
.
userAgent
(
UserAgent
.
randomUserAgent
)
.
userAgent
(
UserAgent
.
randomUserAgent
)
...
@@ -52,7 +51,7 @@ class GentleImage {
...
@@ -52,7 +51,7 @@ class GentleImage {
.
execute
()
.
execute
()
.
bodyStream
()
.
bodyStream
()
}.
upload
(
contact
).
also
{
}.
upload
(
contact
).
also
{
MiraiLogger
.
logPurple
(
"Downloaded image: $name"
)
//
MiraiLogger.logPurple("Downloaded image: $name")
}
}
// }())
// }())
// }
// }
...
...
mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Gentleman.kt
View file @
3f56faae
package
demo.gentleman
package
demo.gentleman
import
com.alibaba.fastjson.JSONArray
import
kotlinx.coroutines.ExperimentalCoroutinesApi
import
kotlinx.coroutines.
*
import
kotlinx.coroutines.
GlobalScope
import
kotlinx.coroutines.channels.Channel
import
kotlinx.coroutines.channels.Channel
import
kotlinx.coroutines.launch
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.contact.Contact
import
org.jsoup.Connection
import
org.jsoup.Jsoup
/**
/**
* 最少缓存的图片数量
* 最少缓存的图片数量
*/
*/
private
const
val
IMAGE_BUFFER_CAPACITY
:
Int
=
5
private
const
val
IMAGE_BUFFER_CAPACITY
:
Int
=
5
0
/**
/**
* 每次补充的数量
* 每次补充的数量
...
@@ -30,12 +29,20 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel(
...
@@ -30,12 +29,20 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel(
GlobalScope
.
launch
{
GlobalScope
.
launch
{
while
(!
isClosedForSend
)
{
while
(!
isClosedForSend
)
{
send
(
GentleImage
().
apply
{
sample_url
=
"http://dev.itxtech.org:10322/randomImg.uue?tdsourcetag=s_pctim_aiomsg"
contact
=
this
@Gentleman
.
contact
image
.
await
()
})
/*
val response = withContext(Dispatchers.IO) {
val response = withContext(Dispatchers.IO) {
tryNTimes(2) {
tryNTimes(2) {
Jsoup.connect("https://yande.re/post.json?")
Jsoup.connect("https://yande.re/post.json?")
.userAgent(UserAgent.randomUserAgent)
.userAgent(UserAgent.randomUserAgent)
.data("limit", "20")
.data("limit", "20")
.
data
(
"page"
,
(
Math
.
random
()
*
4000
).
toString
())
.data("page", (
Random.Default.nextInt(12000)
).toString())
.ignoreContentType(true)
.ignoreContentType(true)
.timeout(20_000)
.timeout(20_000)
.method(Connection.Method.GET)
.method(Connection.Method.GET)
...
@@ -57,7 +64,7 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel(
...
@@ -57,7 +64,7 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel(
it.image//start downloading
it.image//start downloading
send(it)
send(it)
}
}
*/
}
}
}
}
}
}
...
...
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