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
eb02c28e
Commit
eb02c28e
authored
Mar 17, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify with `fold`
parent
ee45ad63
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
17 deletions
+13
-17
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
...mmonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
+13
-17
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
View file @
eb02c28e
...
...
@@ -20,6 +20,8 @@ import io.ktor.client.statement.HttpResponse
import
kotlinx.coroutines.CoroutineName
import
kotlinx.coroutines.async
import
kotlinx.coroutines.io.ByteReadChannel
import
kotlinx.coroutines.withContext
import
kotlinx.serialization.UnstableDefault
import
kotlinx.serialization.json.Json
import
kotlinx.serialization.json.JsonConfiguration
import
kotlinx.serialization.json.int
...
...
@@ -68,6 +70,7 @@ internal abstract class QQAndroidBotBase constructor(
override
val
uin
:
Long
get
()
=
client
.
uin
companion
object
{
@OptIn
(
UnstableDefault
::
class
)
val
json
=
Json
(
JsonConfiguration
(
ignoreUnknownKeys
=
true
,
encodeDefaults
=
true
))
}
...
...
@@ -226,7 +229,7 @@ internal abstract class QQAndroidBotBase constructor(
@MiraiExperimentalAPI
override
suspend
fun
_lowLevelGetAnnouncements
(
groupId
:
Long
,
page
:
Int
,
amount
:
Int
):
GroupAnnouncementList
{
val
data
=
network
.
async
{
HttpClient
()
.
post
<
String
>
{
MiraiPlatformUtils
.
Http
.
post
<
String
>
{
url
(
"https://web.qun.qq.com/cgi-bin/announce/list_announce"
)
body
=
MultiPartFormDataContent
(
formData
{
append
(
"qid"
,
groupId
)
...
...
@@ -254,8 +257,8 @@ internal abstract class QQAndroidBotBase constructor(
@LowLevelAPI
@MiraiExperimentalAPI
override
suspend
fun
_lowLevelSendAnnouncement
(
groupId
:
Long
,
announcement
:
GroupAnnouncement
):
String
{
val
rep
=
network
.
async
{
HttpClient
()
.
post
<
String
>
{
val
rep
=
withContext
(
network
.
coroutineContext
)
{
MiraiPlatformUtils
.
Http
.
post
<
String
>
{
url
(
"https://web.qun.qq.com/cgi-bin/announce/add_qun_notice"
)
body
=
MultiPartFormDataContent
(
formData
{
append
(
"qid"
,
groupId
)
...
...
@@ -282,7 +285,7 @@ internal abstract class QQAndroidBotBase constructor(
}
}
}
val
jsonObj
=
json
.
parseJson
(
rep
.
await
()
)
val
jsonObj
=
json
.
parseJson
(
rep
)
return
jsonObj
.
jsonObject
[
"new_fid"
]
?.
primitive
?.
content
?:
throw
throw
IllegalStateException
(
"Send Announcement fail group:$groupId msg:${jsonObj.jsonObject["
em
"]} content:${announcement.msg.text}"
)
}
...
...
@@ -290,8 +293,8 @@ internal abstract class QQAndroidBotBase constructor(
@LowLevelAPI
@MiraiExperimentalAPI
override
suspend
fun
_lowLevelDeleteAnnouncement
(
groupId
:
Long
,
fid
:
String
)
{
val
rep
=
network
.
async
{
HttpClient
()
.
post
<
String
>
{
val
data
=
withContext
(
network
.
coroutineContext
)
{
MiraiPlatformUtils
.
Http
.
post
<
String
>
{
url
(
"https://web.qun.qq.com/cgi-bin/announce/del_feed"
)
body
=
MultiPartFormDataContent
(
formData
{
append
(
"qid"
,
groupId
)
...
...
@@ -310,7 +313,6 @@ internal abstract class QQAndroidBotBase constructor(
}
}
}
val
data
=
rep
.
await
()
val
jsonObj
=
json
.
parseJson
(
data
)
if
(
jsonObj
.
jsonObject
[
"ec"
]
?.
int
?:
1
!=
0
)
{
throw
throw
IllegalStateException
(
"delete Announcement fail group:$groupId msg:${jsonObj.jsonObject["
em
"]} fid:$fid"
)
...
...
@@ -361,17 +363,11 @@ internal abstract class QQAndroidBotBase constructor(
}
/**
* 获取 获取群公告 所需的
bkn
参数
* 获取 获取群公告 所需的
bkn
参数
* */
val
bkn
:
Int
get
()
{
val
str
=
client
.
wLoginSigInfo
.
sKey
.
data
.
encodeToString
()
var
magic
=
5381
for
(
i
in
str
)
{
magic
+=
magic
.
shl
(
5
)
+
i
.
toInt
()
}
return
Int
.
MAX_VALUE
.
and
(
magic
)
}
private
val
bkn
:
Int
get
()
=
client
.
wLoginSigInfo
.
sKey
.
data
.
fold
(
5381
)
{
acc
:
Int
,
b
:
Byte
->
acc
+
acc
.
shl
(
5
)
+
b
.
toInt
()
}
}
@Suppress
(
"DEPRECATION"
)
...
...
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