mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-04-29 14:17:30 +00:00
fix: 修正了数据库命名错误的问题.
由于 MessageDigest 不适用于多线程环境, 导致用于创建数据库名称的数据会不断累加, 最终出现 botToken 无法对应数据库的问题.
This commit is contained in:
parent
37f0d4e6b8
commit
19c601817c
@ -8,7 +8,8 @@ final class ByteUtils {
|
||||
public static String bytesToHexString(byte[] bytes) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (byte aByte : bytes) {
|
||||
builder.append(Integer.toHexString(aByte));
|
||||
String hexBit = Integer.toHexString(aByte & 0xFF);
|
||||
builder.append(hexBit.length() == 1 ? "0" + hexBit : hexBit);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
@ -8,10 +8,8 @@ import java.nio.charset.StandardCharsets
|
||||
import java.security.MessageDigest
|
||||
|
||||
internal object BotDBMaker {
|
||||
|
||||
private val digest: MessageDigest = MessageDigest.getInstance("SHA-256")
|
||||
|
||||
fun getBotMaker(botAccount: BotAccount): DBContext {
|
||||
val digest: MessageDigest = MessageDigest.getInstance("SHA-256")
|
||||
val digestBytes = digest.digest(botAccount.token.toByteArray(StandardCharsets.UTF_8))
|
||||
val dbPath = AppPaths.DATA_DB.path + "${digestBytes.toHaxString()}.db"
|
||||
val db = DBMaker.fileDB(dbPath)
|
||||
|
Loading…
Reference in New Issue
Block a user