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 {
|
||||
EncryptService.factory?.let { globalService ->
|
||||
service0 = globalService.createForBot(
|
||||
EncryptServiceContext(bot.id, buildTypeSafeMap {
|
||||
set(EncryptServiceContext.KEY_BOT_PROTOCOL, bot.configuration.protocol)
|
||||
set(EncryptServiceContext.KEY_DEVICE_INFO, ssoProcessorContext.device)
|
||||
set(EncryptServiceContext.KEY_BOT_WORKING_DIR, bot.configuration.workingDirPath)
|
||||
set(EncryptServiceContext.KEY_BOT_CACHING_DIR, bot.configuration.actualCacheDir().absolutePath)
|
||||
}),
|
||||
try {
|
||||
service0 = globalService.createForBot(
|
||||
EncryptServiceContext(bot.id, buildTypeSafeMap {
|
||||
set(EncryptServiceContext.KEY_BOT_PROTOCOL, bot.configuration.protocol)
|
||||
set(EncryptServiceContext.KEY_DEVICE_INFO, ssoProcessorContext.device)
|
||||
set(EncryptServiceContext.KEY_BOT_WORKING_DIR, bot.configuration.workingDirPath)
|
||||
set(EncryptServiceContext.KEY_BOT_CACHING_DIR, bot.configuration.actualCacheDir().absolutePath)
|
||||
}),
|
||||
|
||||
bot.childScope(name = "Encrypt Service"),
|
||||
)
|
||||
isAvailable = true
|
||||
bot.childScope(name = "Encrypt Service"),
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// special error: no service used
|
||||
public object SignalServiceNotAvailable : RuntimeException()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user