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( internal class MemberImpl(
qq: QQImpl, qq: QQImpl,
override var groupCard: String,
group: GroupImpl, group: GroupImpl,
override val coroutineContext: CoroutineContext, override val coroutineContext: CoroutineContext,
override val permission: MemberPermission override val permission: MemberPermission

View File

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

View File

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

View File

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