mirror of
https://github.com/babalae/bettergi-scripts-list.git
synced 2026-05-06 00:16:03 +08:00
* refactor(ActivitySwitchNotice): 优化通知配置构建逻辑 - 将 configNotice 变量改为 let 声明以支持动态更新 - 新增 async 函数 buildConfigNotice 用于构建通知配置 - 在 sendNotice 函数中调用 buildConfigNotice 确保配置最新 - 在 sendText 函数中添加 buildConfigNotice 调用保证配置同步 * refactor(utils): 导出工具函数并移除全局挂载 - 将 activity.js 中的 activityMain 函数改为导出函数 - 将 campaignArea.js 中的 ocrDailyCommission、ocrWeeklyCount、campaignAreaMain、dailyCommissionMain 函数改为导出函数 - 将 mapMission.js 中的 ocrMapMission、openMap、mapMission 函数改为导出函数 - 将 tool.js 中的 findTextAndClick、getDayOfWeek 函数改为导出函数 - 将 uid.js 中的 saveOnlyNumber、ocrUID、compareUid、checkUid、check 函数改为导出函数 - 将 ws.js 中的 send、sendText 函数改为导出函数 - 移除所有 utils 文件中对 this 对象的挂载操作 - 在 main.js 中导入新的工具函数并移除重复定义的函数 * fix(ActivitySwitchNotice): 修复圣遗物空间检查功能中的显示和逻辑问题 - 修正圣遗物空间不足提醒消息中的标点符号格式 - 修复圣遗物空间阈值错误日志中的数字格式 - 移除不必要的延时操作以优化执行效率 - 调整代码结构以提高运行性能 fix(ActivitySwitchNotice): 修复圣遗物空间检查功能中的显示和逻辑问题 - 修正圣遗物空间不足提醒消息中的标点符号格式 - 修复圣遗物空间阈值错误日志中的数字格式 - 移除不必要的延时操作以优化执行效率 - 调整代码结构以提高运行性能 refactor(ActivitySwitchNotice): 优化圣遗物检查功能中的延迟配置 - 将硬编码的延迟时间替换为可配置的常量 - 统一延迟时间管理,提高代码可维护性 - 保持原有功能逻辑不变的情况下提升代码质量 feat(ActivitySwitchNotice): 更新版本并新增圣遗物空间检测提醒功能 - 将插件版本从 0.1.3 更新至 0.1.5 - 新增圣遗物剩余空间检测提醒功能 - 在版本历史中添加 0.1.5 版本记录 fix(ActivitySwitchNotice): 修复圣遗物剩余空间阈值解析错误 - 添加 try-catch 块处理 parseInt 异常情况 - 当阈值格式错误时默认使用 400 的阈值 - 添加警告日志记录格式错误的阈值设置 - 确保程序在无效配置下仍能正常运行 feat(bag): 添加圣遗物背包空间检查功能 - 新增 HolyRelics.js 工具模块实现圣遗物数量检查逻辑 - 集成 OCR 识别功能用于获取圣遗物数量信息 - 添加背包空间不足提醒功能,可自定义阈值 - 在 main.js 中集成圣遗物检查流程 - 添加新的配置选项包括打开背包按键和圣遗物阈值设置 - 扩展工具类增加 findText、findImg 和 OcrFind 等通用识别方法 - 实现自动打开背包并处理过期物品弹窗功能 * fix(HolyRelics): 修复圣遗物背包空间检测功能 - 添加了进入圣遗物背包的点击状态验证,避免无法进入时继续执行 - 增强了OCR文本解析逻辑,添加了字符串分割长度验证和数值解析校验 - 优化了阈值参数解析,在main.js中添加了更安全的数值转换和错误处理 - 修复了工具函数中资源释放问题,在isInMainUI函数中使用try-finally确保资源被正确释放 - 更新了提醒消息文本,明确标识阈值设置参数
101 lines
3.2 KiB
JavaScript
101 lines
3.2 KiB
JavaScript
import {sendText as wsSendText} from "./ws"
|
||
const NoticeType = Object.freeze({
|
||
bgi: 'bgi',//BGI通知
|
||
independence: 'independence',//独立通知
|
||
fromValue(value) {
|
||
return Object.keys(this).find(key => this[key] === value);
|
||
}
|
||
})
|
||
const NoticeMap = new Map([
|
||
['BGI通知', [{type: NoticeType.bgi}]],
|
||
['独立通知', [{type: NoticeType.independence}]],
|
||
['独立通知和BGI通知', [{type: NoticeType.independence}, {type: NoticeType.bgi}]],
|
||
])
|
||
let configNotice = {
|
||
noticeList: NoticeMap.get(settings.noticeType),
|
||
}
|
||
async function buildConfigNotice() {
|
||
configNotice = {
|
||
noticeList: NoticeMap.get(settings.noticeType),
|
||
}
|
||
}
|
||
/**
|
||
* 发送通知的异步函数
|
||
* @param {Map} map - 包含通知内容键值对的Map对象
|
||
* @param {string} title - 通知的标题
|
||
* @param {boolean} noNotice - 是否不发送通知的标志
|
||
*/
|
||
async function sendNotice(map = new Map(), title, noNotice = false) {
|
||
log.debug(`sendNotice: map.size=${map.size}, noNotice=${noNotice}`);
|
||
await buildConfigNotice()
|
||
// 如果设置了不发送通知且map为空,则记录日志并返回
|
||
if ((map.size <= 0) || noNotice) {
|
||
log.debug(`if sendNotice: map.size=${map.size}, noNotice=${noNotice}`);
|
||
log.info(`[sendNotice]无通知内容`)
|
||
return
|
||
}
|
||
// 按剩余小时升序排序(即将结束的在前)
|
||
const sortedEntries = Array.from(map.entries())
|
||
.sort((a, b) => a[1].hours - b[1].hours);
|
||
|
||
let noticeText = title ? title + "\n======\n" : "\n"
|
||
for (const [name, info] of sortedEntries) {
|
||
let common = info.common
|
||
common = common ? `(${common})` : ''
|
||
noticeText += `> ${common} ${name} ${info.text} (还剩 ${info.hours} 小时) ${info.desc}\n----\n`;
|
||
}
|
||
log.debug(`sendNotice: noticeText:{noticeText}`,noticeText);
|
||
// 发送通知
|
||
for (let noticeElement of configNotice.noticeList) {
|
||
switch (noticeElement.type) {
|
||
case NoticeType.independence:
|
||
await wsSendText(noticeText)
|
||
break
|
||
case NoticeType.bgi:
|
||
notification.send(noticeText)
|
||
break
|
||
}
|
||
}
|
||
log.debug(`sendNotice: --end`);
|
||
return
|
||
}
|
||
|
||
/**
|
||
* 异步发送通知的函数
|
||
* @param {string} noticeText - 通知内容文本
|
||
* @param {string} title - 通知标题
|
||
*/
|
||
async function sendText(noticeText, title, noNotice = false) {
|
||
// 检查是否有通知内容且设置了不发送通知的标志
|
||
if ((!noticeText) || noNotice) {
|
||
log.info(`sendText 无通知内容`) // 记录日志信息
|
||
return // 直接返回,不执行后续操作
|
||
}
|
||
await buildConfigNotice()
|
||
// 构建通知文本,如果有标题则先添加标题
|
||
let text = title ? title + "\n======\n" : "\n"
|
||
// 添加通知内容
|
||
text += noticeText
|
||
// 发送通知
|
||
for (let noticeElement of configNotice.noticeList) {
|
||
switch (noticeElement.type) {
|
||
case NoticeType.independence:
|
||
await wsSendText(text)
|
||
break
|
||
case NoticeType.bgi:
|
||
notification.send(text)
|
||
break
|
||
}
|
||
}
|
||
return
|
||
}
|
||
|
||
// this.noticeUtil = {
|
||
// sendNotice,
|
||
// sendText,
|
||
// }
|
||
|
||
export {
|
||
sendNotice,
|
||
sendText,
|
||
} |