Group Card

This commit is contained in:
jiahua.liu 2020-02-04 15:56:43 +08:00
parent a76606ae0a
commit 35742632b3
4 changed files with 25 additions and 14 deletions

View File

@ -61,6 +61,7 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin
internal class MemberImpl(
qq: QQImpl,
override var groupCard: String,
group: GroupImpl,
override val coroutineContext: CoroutineContext,
override val permission: MemberPermission

View File

@ -174,6 +174,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
group.owner =
MemberImpl(
qq = bot.QQ(it.dwGroupOwnerUin) as QQImpl,
groupCard = "",//unknown now
group = group,
coroutineContext = group.coroutineContext,
permission = MemberPermission.OWNER
@ -253,6 +254,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
list.delegate.addLast(
MemberImpl(
qq = bot.QQ(it.memberUin) as QQImpl,
groupCard = it.sShowName ?: it.sName ?: it.nick,
group = group,
coroutineContext = group.coroutineContext,
permission = when {
@ -262,8 +264,11 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
}
)
)
} else if (it.dwFlag == 1L) {
group.botPermission = MemberPermission.ADMINISTRATOR
} else {
group.owner.groupCard = it.sShowName ?: it.sName ?: it.nick
if (it.dwFlag == 1L) {
group.botPermission = MemberPermission.ADMINISTRATOR
}
}
}
size += data.members.size

View File

@ -21,6 +21,11 @@ interface Member : QQ, Contact {
*/
val permission: MemberPermission
/**
*
*/
var groupCard: String
/**
* 禁言
*
@ -37,6 +42,7 @@ interface Member : QQ, Contact {
* 解除禁言
*/
suspend fun unmute(): Boolean
}
@ExperimentalTime

View File

@ -2,7 +2,6 @@ package demo.gentleman
import com.alibaba.fastjson.JSON
import kotlinx.coroutines.*
import kotlinx.serialization.json.JsonObject
import net.mamoe.mirai.contact.Contact
import net.mamoe.mirai.message.data.Image
import net.mamoe.mirai.message.uploadAsImage
@ -18,21 +17,24 @@ class GentleImage {
val seImage: Deferred<Image> by lazy { getImage(1) }
fun getImage(r18: Int): Deferred<Image> {
GlobalScope.async {
return GlobalScope.async {
withTimeoutOrNull(5 * 1000) {
withContext(Dispatchers.IO) {
val result = JSON.parseObject(
Jsoup.connect("https://api.lolicon.app/setu/?r18=$r18").ignoreContentType(true).timeout(10_0000).get().body().text(),
val result =
JSON.parseObject(
Jsoup.connect("https://api.lolicon.app/setu/?r18=$r18").ignoreContentType(true).timeout(
10_0000
).get().body().text()
)
var url = "";
var pid = "";
val url: String
val pid: String
with(result.getJSONArray("data").getJSONObject(0)) {
url = this.getString("url")
pid = this.getString("pid")
}
val image = Jsoup
Jsoup
.connect(url)
.followRedirects(true)
.timeout(180_000)
@ -41,12 +43,9 @@ class GentleImage {
.referrer("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=$pid")
.ignoreHttpErrors(true)
.maxBodySize(10000000)
.execute()
if (image.statusCode() != 200) error("Failed to download image")
.execute().also { check(it.statusCode() == 200) { "Failed to download image" } }
}
image.bodyStream().uploadAsImage(contact) ?: error("Unable to upload image")
}
}?.bodyStream()?.uploadAsImage(contact) ?: error("Unable to download image")
}
}
}