Skip to content

Commit

Permalink
refactor: 重构用户配置类
Browse files Browse the repository at this point in the history
  • Loading branch information
TomyJan committed May 30, 2024
1 parent c9adeb1 commit d931236
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 166 deletions.
7 changes: 4 additions & 3 deletions apps/gameCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import plugin from '../../../lib/plugins/plugin.js'
import puppeteer from '../../../lib/puppeteer/puppeteer.js'
import gameCardData from '../model/gameCard.js'
import md5 from 'md5'
import { saveAccCurPnsUidIndex } from '../model/userConfig.js'
import userConfig from '../model/userConfig.js'
import kuroLogger from '../components/logger.js'

export class gameCard extends plugin {
Expand Down Expand Up @@ -34,8 +34,9 @@ export class gameCard extends plugin {
.replace(/#| /g, '')
kuroLogger.debug('战双卡片索引:', index)
if (index) {
if (await saveAccCurPnsUidIndex(this.e.user_id, index - 1))
await this.reply(`已切换至第 ${index} 个账号`)
let user = new userConfig()
if (await user.saveCurGameUidByIndex(this.e.user_id, index - 1, 2))
await this.reply(`已切换至第 ${index} 个账号, UID: ${(await user.getCurGameUidLocal(this.e.user_id, 2))?.gameUid}`)
else await this.reply(`切换账号失败`)
}
let data = await gameCardData.get(this.e, 'gameCardPns', this.e.user_id)
Expand Down
4 changes: 2 additions & 2 deletions components/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { sleepAsync } from '../model/utils.js'

class Logger {
constructor(
logLevel = config.getConfig().logger.logLevel || 'info',
logLevel = config.getConfig()?.logger?.logLevel || 'info',
logDirectory = dataPath + '/logs'
) {
this.logLevel = logLevel.toLowerCase()
Expand All @@ -32,7 +32,7 @@ class Logger {
if (logType === 'ERROR') logger.error(chalk.red(logToConsole))

// 保存日志到文件
if (config.getConfig().logger.saveToFile) {
if (config.getConfig()?.logger?.saveToFile || false) {
const logToFile = `[${this.getTimeForLog()}] ${baseLogContent}`
const currentLogFilePath = path.join(
this.logDirectory,
Expand Down
2 changes: 1 addition & 1 deletion model/autoTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import cfg from '../../../lib/config/config.js'
import config from '../components/config.js'

export async function initAutoTask() {
if (!config.getConfig().autoTask.enabled) {
if (!config.getConfig()?.autoTask?.enabled) {
kuroLogger.info(pluginThemeColor(`自动任务已被禁用, 取消载入定时任务`))
return false
}
Expand Down
6 changes: 4 additions & 2 deletions model/gameCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
_ResPath,
} from '../data/system/pluginConstants.js'
import kuroApi from './kuroApi.js'
import { getAccCurPnsUidIndex } from './userConfig.js'
import userConfig from './userConfig.js'

export default class gameCard {
constructor(e, model) {
Expand Down Expand Up @@ -47,10 +47,12 @@ export default class gameCard {
}
kuroLogger.debug('账号数组:', JSON.stringify(accArr))

let user = new userConfig()

let ret = {
tplFile: `${resPath}/html/${model}/index.html`,
accArr,
accCurPnsUidIndex: (await getAccCurPnsUidIndex(e.user_id)) + 1,
accCurPnsUidIndex: (await user.getCurGameUidIndex(e.user_id, 2)) + 1,
pluResPath: _ResPath,
pluginName,
pluginVer,
Expand Down
Loading

0 comments on commit d931236

Please sign in to comment.