Merge remote-tracking branch 'origin/master'

This commit is contained in:
Him188 2020-02-04 15:57:44 +08:00
commit 1922fdc5ba
6 changed files with 94 additions and 39 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,12 +174,13 @@ 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
)
if (it.dwGroupOwnerUin == bot.uin) {
group.botPermission == MemberPermission.OWNER
group.botPermission = MemberPermission.OWNER
}
toGet[group] = contactList
bot.groups.delegate.addLast(group)
@ -189,9 +190,9 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
launch {
try {
getTroopMemberList(it.key, it.value, it.key.owner.id)
groupInfo[it.key.uin] = it.value.size
groupInfo[it.key.id] = it.value.size
} catch (e: Exception) {
groupInfo[it.key.uin] = -1
groupInfo[it.key.id] = -1
bot.logger.info("${it.key.uin}的列表拉取失败, 将采用动态加入")
}
}
@ -206,25 +207,30 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
}
//===log===//
fun fillUntil9(long: Number): String {
fun fillUntil(long: Number, size: Int): String {
val x = long.toString()
return " ".repeat(
if (9 - x.length > 0) {
9 - x.length
return x + " ".repeat(
if (size - x.length > 0) {
size - x.length
} else {
0
}
) + x
)
}
bot.logger.info("====================Mirai Bot List初始化完毕====================")
bot.logger.info("好友数量: ${fillUntil9(bot.qqs.size)}\t\t\t 加载时间: ${friendLoadFinish - startTime}ms")
bot.logger.info("加入群组: ${fillUntil9(bot.groups.size)}\t\t\t 加载时间: ${currentTimeMillis - friendLoadFinish}ms")
bot.logger.info("好友数量: ${fillUntil(bot.qqs.size, 9)}\t\t\t 加载时间: ${friendLoadFinish - startTime}ms")
bot.logger.info("加入群组: ${fillUntil(bot.groups.size, 9)}\t\t\t 加载时间: ${currentTimeMillis - friendLoadFinish}ms")
groupInfo.forEach {
if (it.value == -1) {
bot.logger.error("群组号码: ${fillUntil9(it.key)}\t 成员数量加载失败")
bot.logger.error("群组号码: ${fillUntil(it.key, 9)}\t 成员数量加载失败")
} else {
bot.logger.info("群组号码: ${fillUntil9(it.key)}\t 成员数量: ${it.value}\t BOT权限: " + bot.groups[it.key].botPermission.toString() + "")
bot.logger.info(
"群组号码: ${fillUntil(it.key, 9)}\t 成员数量: ${fillUntil(
it.value,
4
)}\t BOT权限: " + bot.groups[it.key].botPermission.toString() + ""
)
}
}
bot.logger.info("====================Mirai Bot List初始化完毕====================")
@ -248,19 +254,21 @@ 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 {
it.memberUin == owner -> MemberPermission.OWNER
it.dwFlag == 1L -> MemberPermission.ADMINISTRATOR.apply {
if (it.memberUin == bot.uin) {
group.botPermission = MemberPermission.ADMINISTRATOR
}
}
it.dwFlag == 1L -> MemberPermission.ADMINISTRATOR
else -> MemberPermission.MEMBER
}
)
)
} else {
group.owner.groupCard = it.sShowName ?: it.sName ?: it.nick
if (it.dwFlag == 1L) {
group.botPermission = MemberPermission.ADMINISTRATOR
}
}
}
size += data.members.size

View File

@ -8,6 +8,7 @@ import net.mamoe.mirai.qqandroid.QQAndroidBot
import net.mamoe.mirai.qqandroid.io.serialization.writeProtoBuf
import net.mamoe.mirai.qqandroid.network.QQAndroidClient
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.OidbSso
import net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY
import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacket
import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacketFactory
import net.mamoe.mirai.qqandroid.network.protocol.packet.buildOutgoingUniPacket
@ -47,14 +48,34 @@ internal object TroopManagement {
)
}
}
object Response : Packet
}
internal object MuteAll : OutgoingPacketFactory<LoginPacket.LoginPacketResponse>("OidbSvc.0x89a_0") {
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): LoginPacket.LoginPacketResponse {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
internal object MuteAll : OutgoingPacketFactory<MuteAll.Response>("OidbSvc.0x89a_0") {
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response {
return Response
}
operator fun invoke(
client: QQAndroidClient,
groupCode: Long
): OutgoingPacket {
return buildOutgoingUniPacket(client) {
writeProtoBuf(
OidbSso.OIDBSSOPkg.serializer(),
OidbSso.OIDBSSOPkg(
command = 2202,
serviceType = 0,
result = 0,
bodybuffer = EMPTY_BYTE_ARRAY//TODO
)
)
}
}
object Response : Packet
}
internal object EditNametag : OutgoingPacketFactory<LoginPacket.LoginPacketResponse>("OidbSvc.0x8fc_2") {

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

@ -12,31 +12,41 @@ class GentleImage {
// `Deferred<Image?>` causes a runtime ClassCastException
val image: Deferred<Image> by lazy {
GlobalScope.async {
//delay((Math.random() * 5000L).toLong())
class Result {
var id: String = ""
}
val image: Deferred<Image> by lazy { getImage(0) }
val seImage: Deferred<Image> by lazy { getImage(1) }
fun getImage(r18: Int): Deferred<Image> {
return GlobalScope.async {
withTimeoutOrNull(5 * 1000) {
withContext(Dispatchers.IO) {
val result = JSON.parseObject(
Jsoup.connect("http://dev.itxtech.org:10322/v2/randomImg.uue").ignoreContentType(true).timeout(10_0000).get().body().text(),
Result::class.java
)
val result =
JSON.parseObject(
Jsoup.connect("https://api.lolicon.app/setu/?r18=$r18").ignoreContentType(true).timeout(
10_0000
).get().body().text()
)
Jsoup.connect("http://dev.itxtech.org:10322/img.uue?size=large&id=${result.id}")
.userAgent(UserAgent.randomUserAgent)
.timeout(10_0000)
val url: String
val pid: String
with(result.getJSONArray("data").getJSONObject(0)) {
url = this.getString("url")
pid = this.getString("pid")
}
Jsoup
.connect(url)
.followRedirects(true)
.timeout(180_000)
.ignoreContentType(true)
.maxBodySize(Int.MAX_VALUE)
.execute()
.bodyStream()
.userAgent("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; ja-jp) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27")
.referrer("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=$pid")
.ignoreHttpErrors(true)
.maxBodySize(10000000)
.execute().also { check(it.statusCode() == 200) { "Failed to download image" } }
}
}?.uploadAsImage(contact) ?: error("Unable to download image")
}?.bodyStream()?.uploadAsImage(contact) ?: error("Unable to download image")
}
}
}

View File

@ -151,7 +151,7 @@ suspend fun main() {
file.sendAsImageTo(subject)
}
startsWith("随机图片", removePrefix = true) {
startsWith("色图", removePrefix = true) {
repeat(it.toIntOrNull() ?: 1) {
GlobalScope.launch {
delay(Random.Default.nextLong(100, 1000))
@ -160,6 +160,15 @@ suspend fun main() {
}
}
startsWith("不够色", removePrefix = true) {
repeat(it.toIntOrNull() ?: 1) {
GlobalScope.launch {
delay(Random.Default.nextLong(100, 1000))
Gentlemen.provide(subject).receive().seImage.await().send()
}
}
}
startsWith("添加好友", removePrefix = true) {
reply(bot.addFriend(it.toLong()).toString())
}