-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from simple-robot/dev/update-simbot
更新simbot到4.3.0; 为 `QGAttachmentMessage` 实现 `BinaryDataAwareMessage`
- Loading branch information
Showing
8 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...re/src/jsMain/kotlin/love/forte/simbot/component/qguild/message/QGAttachmentMessage.js.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2024. ForteScarlet. | ||
* | ||
* This file is part of simbot-component-qq-guild. | ||
* | ||
* simbot-component-qq-guild is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Lesser General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* simbot-component-qq-guild is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License along with simbot-component-qq-guild. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package love.forte.simbot.component.qguild.message | ||
|
||
import io.ktor.client.request.* | ||
import io.ktor.client.statement.* | ||
import love.forte.simbot.component.qguild.bot.QGBot | ||
|
||
internal actual suspend fun readBinaryData( | ||
bot: QGBot?, | ||
url: String | ||
): ByteArray { | ||
val client = bot?.source?.apiClient ?: error("api Http client from bot is missing") | ||
return client.get(url).readBytes() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../src/jvmMain/kotlin/love/forte/simbot/component/qguild/message/QGAttachmentMessage.jvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2024. ForteScarlet. | ||
* | ||
* This file is part of simbot-component-qq-guild. | ||
* | ||
* simbot-component-qq-guild is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Lesser General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* simbot-component-qq-guild is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License along with simbot-component-qq-guild. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package love.forte.simbot.component.qguild.message | ||
|
||
import io.ktor.client.request.* | ||
import io.ktor.client.statement.* | ||
import io.ktor.util.cio.* | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import love.forte.simbot.component.qguild.bot.QGBot | ||
import java.io.IOException | ||
import java.net.URI | ||
|
||
internal actual suspend fun readBinaryData( | ||
bot: QGBot?, | ||
url: String | ||
): ByteArray { | ||
val client = bot?.source?.apiClient | ||
if (client != null) { | ||
return client.get(url).readBytes() | ||
} | ||
|
||
try { | ||
val jUrl = URI.create(url).toURL() | ||
return withContext(Dispatchers.IO) { | ||
jUrl.openStream() | ||
.toByteReadChannel(context = Dispatchers.IO) | ||
.toByteArray() | ||
} | ||
} catch (io: IOException) { | ||
throw IllegalStateException(io.localizedMessage, io) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ativeMain/kotlin/love/forte/simbot/component/qguild/message/QGAttachmentMessage.native.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2024. ForteScarlet. | ||
* | ||
* This file is part of simbot-component-qq-guild. | ||
* | ||
* simbot-component-qq-guild is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Lesser General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* simbot-component-qq-guild is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License along with simbot-component-qq-guild. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package love.forte.simbot.component.qguild.message | ||
|
||
import io.ktor.client.request.* | ||
import io.ktor.client.statement.* | ||
import love.forte.simbot.component.qguild.bot.QGBot | ||
|
||
internal actual suspend fun readBinaryData( | ||
bot: QGBot?, | ||
url: String | ||
): ByteArray { | ||
val client = bot?.source?.apiClient ?: error("api Http client from bot is missing") | ||
return client.get(url).readBytes() | ||
} | ||
|