mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-25 03:30:15 +08:00
[core] Handle UnsupportedOperationException on EncryptService initialize & add special signals
This commit is contained in:
parent
96e93e670e
commit
685fb2d3d9
@ -45,17 +45,27 @@ internal class EncryptServiceHolderImpl(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
EncryptService.factory?.let { globalService ->
|
EncryptService.factory?.let { globalService ->
|
||||||
service0 = globalService.createForBot(
|
try {
|
||||||
EncryptServiceContext(bot.id, buildTypeSafeMap {
|
service0 = globalService.createForBot(
|
||||||
set(EncryptServiceContext.KEY_BOT_PROTOCOL, bot.configuration.protocol)
|
EncryptServiceContext(bot.id, buildTypeSafeMap {
|
||||||
set(EncryptServiceContext.KEY_DEVICE_INFO, ssoProcessorContext.device)
|
set(EncryptServiceContext.KEY_BOT_PROTOCOL, bot.configuration.protocol)
|
||||||
set(EncryptServiceContext.KEY_BOT_WORKING_DIR, bot.configuration.workingDirPath)
|
set(EncryptServiceContext.KEY_DEVICE_INFO, ssoProcessorContext.device)
|
||||||
set(EncryptServiceContext.KEY_BOT_CACHING_DIR, bot.configuration.actualCacheDir().absolutePath)
|
set(EncryptServiceContext.KEY_BOT_WORKING_DIR, bot.configuration.workingDirPath)
|
||||||
}),
|
set(EncryptServiceContext.KEY_BOT_CACHING_DIR, bot.configuration.actualCacheDir().absolutePath)
|
||||||
|
}),
|
||||||
|
|
||||||
bot.childScope(name = "Encrypt Service"),
|
bot.childScope(name = "Encrypt Service"),
|
||||||
)
|
)
|
||||||
isAvailable = true
|
|
||||||
|
isAvailable = true
|
||||||
|
} catch (error: UnsupportedOperationException) {
|
||||||
|
bot.logger.warning("$globalService is not yet supported EncryptService with bot $bot", error)
|
||||||
|
isAvailable = false
|
||||||
|
service0 = null
|
||||||
|
} catch (_: EncryptService.SignalServiceNotAvailable) {
|
||||||
|
isAvailable = false
|
||||||
|
service0 = null
|
||||||
|
} /* catch (error: Throwable) { throw error } */ // crash bot initialize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,4 +122,7 @@ public interface EncryptService {
|
|||||||
return loader.service
|
return loader.service
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// special error: no service used
|
||||||
|
public object SignalServiceNotAvailable : RuntimeException()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user