Retry fetch group on fail

This commit is contained in:
Him188 2020-02-18 13:35:28 +08:00
parent 2b4d9a8e79
commit fc4fb4f297

View File

@ -215,12 +215,11 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
.sendAndExpect<FriendList.GetTroopListSimplify.Response>(retry = 2)
troopListData.groups.forEach { troopNum ->
launch {
try {
suspend fun loadGroup() {
tryNTimesOrException(3) {
bot.groups.delegate.addLast(
@Suppress("DuplicatedCode")
GroupImpl(
(GroupImpl(
bot = bot,
coroutineContext = bot.coroutineContext,
id = troopNum.groupCode,
@ -242,13 +241,20 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
this.delegate.groupCode = troopNum.groupCode
},
members = bot.queryGroupMemberList(troopNum.groupUin, troopNum.groupCode, troopNum.dwGroupOwnerUin)
)
))
)
} catch (e: Exception) {
}?.let {
logger.error("${troopNum.groupCode}的列表拉取失败, 一段时间后将会重试")
logger.error(e)
logger.error(it)
this@QQAndroidBotNetworkHandler.launch {
delay(10_000)
loadGroup()
}
}
}
launch {
loadGroup()
}
}
logger.info("群组列表与群成员加载完成, 共 ${troopListData.groups.size}")
} catch (e: Exception) {