feat: 设置默认设备

This commit is contained in:
bietiaop 2024-08-20 13:44:52 +08:00
parent 8425503797
commit c6a41ab210
5 changed files with 76 additions and 7 deletions

View file

@ -325,6 +325,13 @@ export class Help extends ZZZPlugin {
needSK: false,
commands: ['删除+角色名+面板图', '删除+角色名+角色图'],
},
{
title: '设置默认设备',
desc: '设置默认设备信息,当用户没有绑定设备时,会使用默认设备信息',
needCK: false,
needSK: false,
commands: ['设置默认设备'],
},
],
},
];

View file

@ -72,6 +72,10 @@ export class Panel extends ZZZPlugin {
reg: `^${rulePrefix}(插件)?检查更新$`,
fnc: 'hasUpdate',
},
{
reg: `${rulePrefix}设置默认设备`,
fnc: 'setDefaultDevice',
},
],
});
@ -90,5 +94,7 @@ export class Panel extends ZZZPlugin {
this.getChangeLog = manage.version.getChangeLog;
this.getCommitLog = manage.version.getCommitLog;
this.hasUpdate = manage.version.hasUpdate;
this.setDefaultDevice = manage.device.setDefaultDevice;
this.toSetDefaultDevice = manage.device.toSetDefaultDevice;
}
}

53
apps/manage/device.js Normal file
View file

@ -0,0 +1,53 @@
import settings from '../../lib/settings.js';
export async function setDefaultDevice() {
this.setContext('toSetDefaultDevice');
await this.reply(
`请发送默认设备信息,或者发送“取消”取消设置默认设备信息`,
false,
{ at: true, recallMsg: 100 }
);
}
export async function toSetDefaultDevice() {
const msg = this.e.msg.trim();
if (!msg) {
this.reply('请发送设备信息', false, { at: true, recallMsg: 100 });
return false;
}
if (msg.includes('取消')) {
await this.reply('已取消', false, { at: true, recallMsg: 100 });
this.finish('toSetDefaultDevice');
return false;
}
try {
const info = JSON.parse(msg);
if (!info) {
this.reply('设备信息格式错误', false, { at: true, recallMsg: 100 });
return false;
}
if (
!info?.deviceName ||
!info?.deviceBoard ||
!info?.deviceModel ||
!info?.oaid ||
!info?.deviceFingerprint ||
!info?.deviceProduct
) {
this.reply('设备信息格式错误', false, { at: true, recallMsg: 100 });
return false;
}
settings.setConfig('device', {
productName: info.deviceProduct,
productType: info.deviceName,
modelName: info.deviceModel,
oaid: info.oaid,
deviceInfo: info.deviceFingerprint,
board: info.deviceBoard,
});
this.reply('默认设备信息设置成功', false, { at: true, recallMsg: 100 });
} catch (error) {
this.reply('设备信息格式错误', false, { at: true, recallMsg: 100 });
} finally {
this.finish('toSetDefaultDevice');
}
}

View file

@ -10,6 +10,8 @@ import * as panel from './panel.js';
import * as version from './version.js';
import * as device from './device.js';
export default {
assets,
guides,
@ -17,4 +19,5 @@ export default {
alias,
panel,
version,
device,
};

View file

@ -3,7 +3,7 @@ import chokidar from 'chokidar';
import fs from 'fs';
import path from 'path';
import { configPath, dataPath, defPath, pluginName } from './path.js';
/** @typedef {'alias'|'config'|'gacha'|'panel'|'guide'|'device'} App */
class Setting {
constructor() {
/** 默认设置 */
@ -113,7 +113,7 @@ class Setting {
/**
* 获取对应模块默认配置
* @param {'alias'|'config'|'gacha'|'panel'} app
* @param {App} app
* @returns {object}
*/
getdefSet(app) {
@ -122,7 +122,7 @@ class Setting {
/**
* 获取对应模块用户配置配置文件名
* @param {'alias'|'config'|'gacha'|'panel'} app
* @param {App} app
* @returns {object}
*/
getConfig(app) {
@ -153,7 +153,7 @@ class Setting {
/**
* 设置对应模块用户配置
* @param {'alias'|'config'|'gacha'|'panel'|'guide'} app
* @param {App} app
* @param {object} obj
* @returns
*/
@ -167,7 +167,7 @@ class Setting {
/**
* 设置对应模块用户配置
* @param {'alias'|'config'|'gacha'|'panel'|'guide'} app
* @param {App} app
* @param {string} key
* @param {string} value
* @returns {boolean}
@ -182,7 +182,7 @@ class Setting {
/**
* 向数组中添加元素
* @param {'alias'|'config'|'gacha'|'panel'|'guide'} app
* @param {App} app
* @param {string} key
* @param {string} value
* @returns {boolean}
@ -199,7 +199,7 @@ class Setting {
/**
* 从数组中删除元素
* @param {'alias'|'config'|'gacha'|'panel'|'guide'} app
* @param {App} app
* @param {string} key
* @param {string} value
* @returns {boolean}