mirror of
https://github.com/babalae/bettergi-scripts-list.git
synced 2026-03-19 03:59:51 +08:00
* refactor(utils): 重构工具模块导入导出结构并优化功能实现 - 将各个工具模块改为ES6模块化导入导出方式 - 新增通用文本识别点击工具函数findTextAndClick - 优化campaignArea模块中的征讨领域识别逻辑 - 统一uid识别和通知发送的调用方式 - 移除eval动态加载改用静态导入 - 更新版本号至0.1.1 * config(ActivitySwitchNotice): 更新默认显示天数设置 - 移除周一到周五的默认显示配置 - 保留周日和周六作为默认显示选项 * feat(ActivitySwitchNotice): 更新版本历史记录 - 周本提醒日升为多选功能实现 - 适配新秘境征讨UI界面调整
96 lines
3.1 KiB
JavaScript
96 lines
3.1 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}]],
|
||
])
|
||
const 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}`);
|
||
|
||
// 如果设置了不发送通知且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 // 直接返回,不执行后续操作
|
||
}
|
||
// 构建通知文本,如果有标题则先添加标题
|
||
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,
|
||
} |