-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/xyz/cssxsh/mirai/device/MiraiDeviceReset.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package xyz.cssxsh.mirai.device | ||
|
||
import net.mamoe.mirai.console.events.* | ||
import net.mamoe.mirai.event.* | ||
import net.mamoe.mirai.network.* | ||
import net.mamoe.mirai.utils.* | ||
|
||
/** | ||
* 自动重载 Device Info | ||
*/ | ||
public object MiraiDeviceReset : SimpleListenerHost() { | ||
|
||
@EventHandler | ||
public fun ConsoleEvent.handle() { | ||
try { | ||
val failure = this as? AutoLoginEvent.Failure ?: return | ||
val exception = failure.cause.suppressedExceptions | ||
.firstNotNullOfOrNull { it as? WrongPasswordException } ?: return | ||
val message = exception.message ?: return | ||
if ("""code=(45|235)""".toRegex() !in message) return | ||
val success = with(failure.bot.configuration.workingDir) { | ||
val file = resolve("device.json") | ||
val backup = resolve("device.${System.currentTimeMillis()}.json") | ||
file.renameTo(backup) | ||
} | ||
if (success) { | ||
bot.logger.info { "device.json 可能已经被拉黑, 将重新生成,请稍后重新尝试手动重新登陆" } | ||
} | ||
} catch (_: ClassNotFoundException) { | ||
// ... | ||
} | ||
} | ||
} |