Skip to content

Commit

Permalink
Merge pull request #49 from JS-banana/dev
Browse files Browse the repository at this point in the history
feat: 纪念日调整为数组形式,支持多个
  • Loading branch information
JS-banana authored Aug 16, 2023
2 parents fafceec + ade6e03 commit a4a13a8
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 31 deletions.
32 changes: 23 additions & 9 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ loveMsg:
# 支持数组形式:默认随机取其中一条消息发送,一条消息时固定发送本条消息(['消息1', '消息2','消息3'])
# 如果要使换行符 \n 生效,需要使用双引号 ""
weather_low_message:
- "❄️啦啦啦~这里是来自崽崽的暖心提醒哦:\n今日最低温度仅为🥶 {low},可冷可冷了~鱼崽崽可要注意保暖哦~"
- "❄️啦啦啦~这里是来自崽崽的暖心提醒哦:\n今日最低温度仅为🥶 {low},宝宝要注意保暖哦~"

# 高温提醒: 是否开启
weather_hight_show: true
# 高温提醒: 30 => 最高温度高于 30℃ 时触发
weather_hight_tem: 30
# 高温提醒: 提醒内容,这里的 {hight} 为固定替换温度值
weather_hight_message:
- "🔥啦啦啦~这里是来自崽崽的暖心提醒哦:\n今日最高温度高达🥵 {hight},这也忒热了~鱼崽崽可要注意防暑哦~"
- "🔥啦啦啦~这里是来自崽崽的暖心提醒哦:\n今日最高温度高达🥵 {hight},宝宝要注意防暑哦~"

#
# 第二卡片:用于展示纪念日、生日提醒、彩蛋等
Expand All @@ -76,18 +76,32 @@ loveMsg:
tips_card_url: https://api.vvhan.com/api/moyu

# 🧡
# 纪念日
# 纪念日: 存在多格时,按数组形式一一对应
#
# 需要提醒的纪念日: 相恋日期
memorial_day: 2021/03/26
memorial_day:
- 2021/03/26
- 2023/10/04
# 需要提醒的纪念日: 是否开启
memorial_day_show: true
memorial_day_show:
- true
- true
# 需要提醒的纪念日: 提醒内容,这里的 {day} 为固定替换模板,不可更改
memorial_day_message: 👫还有{day}天就是我们的恋爱纪念日啦~
memorial_day_message:
- 👫还有{day}天就是我们的恋爱纪念日啦~
- 👫还有{day}天,我们就结婚啦~
# 需要提醒的纪念日: 提醒内容,当天
memorial_day_message_now: 👫执子之手,与子偕老。宝~,今天可是我们恋爱{year}周年啦
memorial_day_message_now:
- 👫执子之手,与子偕老。宝~,今天可是我们恋爱{year}周年啦
- "👫执子之手,与子偕老。宝~,今天我们正式结为夫妇啦\n可能此时此刻,我已经迎娶你到家了\n老婆老婆老婆,你是我的老婆啦\n余生与你相伴~"
# 需要提醒的纪念日: 倒计时多久时开始提醒,单位天
memorial_day_day: 32
memorial_day_day:
- 32
- 56
# 需要独立卡片显示: 当天默认启用独立卡片显示
memorial_card_show:
- true
- false

# 👧
# 女朋友生日
Expand Down Expand Up @@ -128,7 +142,7 @@ loveMsg:
# - 🎃注意:如何辨别彩蛋?存在关键字“彩蛋”的消息,会被认为一条彩蛋
# - 🎃生日当天必出现的信息,根据排序筛选: 女友生日 => 倒数第二条,男友生日 => 倒数第一条
#
my_love_message_show: true
my_love_message_show: false
# 为确保随机的概率相对稳定,需要设定一个固定值
# 设置彩蛋的概率最大公约数为64,即约 1/64 的概率
my_love_message_egg_probability: 38
Expand Down
4 changes: 2 additions & 2 deletions src/libs/LoveMsg/templates/_loveMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const getLoveMessage = (
birthdayInfo.isEmpty = false
} else {
// 过滤掉彩蛋的内容,重新随机
const filterEggs = config.my_love_message_content.filter((n) => !n.includes('彩蛋'))
const filterEggs = config.my_love_message_content.filter(n => !n.includes('彩蛋'))
len = getRandomRange(1, filterEggs.length)
}
}
Expand All @@ -46,8 +46,8 @@ export const getLoveMessage = (
const text = config.my_love_message_content[len - 1]

if (text) template += `\n${text}`
template += '\n'
}
template += '\n'

return template
}
74 changes: 59 additions & 15 deletions src/libs/LoveMsg/templates/_memorial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@ interface IBirthdayInfo {
isEmpty: boolean
}

const getMemorialText = (
currentDay: string,
memorial_day: string,
memorial_day_day: number,
memorial_day_message: string,
memorial_day_message_now: string) => {
const currentYear = currentDay.substring(0, 4)

let text = ''
let now = false
// 相差天数
const DAY = dayjs(currentYear + memorial_day.substring(5)).diff(currentDay, 'day')
// 当天
if (DAY === 0) {
now = true
const year = dayjs(currentDay).diff(memorial_day, 'year')
text = memorial_day_message_now.replace('{year}', `${year > 0 ? year : ''}`)
}
// 倒计时
if (DAY > 0 && DAY <= memorial_day_day) text = memorial_day_message.replace('{day}', `${DAY}`)

return {
text,
now
}
}

/**
* 纪念日 日期相关
*/
Expand All @@ -25,6 +52,7 @@ export const getContentByDay = (
memorial_day_message,
memorial_day_message_now,
memorial_day_day,
memorial_card_show,
// 女朋友生日
girl_birthday_show,
girl_birthday_date,
Expand All @@ -42,23 +70,39 @@ export const getContentByDay = (
/**
* 相识纪念日的逻辑处理
*/
if (memorial_day_show) {
let text = ''
// 相差天数
const DAY = dayjs(currentYear + memorial_day.substring(5)).diff(currentDay, 'day')
// 当天
if (DAY === 0) {
const year = dayjs(currentDay).diff(memorial_day, 'year')
text = memorial_day_message_now.replace('{year}', `${year}`)
memorial_day_show.forEach((isShow, index) => {
if (isShow) {
const obj = getMemorialText(
currentDay,
memorial_day[index],
memorial_day_day[index],
memorial_day_message[index],
memorial_day_message_now[index])
//
if (obj.text) {
template += `\n${obj.text}`
// 手动开启或者当天
if (memorial_card_show[index] || obj.now) birthdayInfo.isEmpty = false
}
}
// 倒计时
if (DAY > 0 && DAY <= memorial_day_day) text = memorial_day_message.replace('{day}', `${DAY}`)
})
// if (memorial_day_show) {
// let text = ''
// // 相差天数
// const DAY = dayjs(currentYear + memorial_day.substring(5)).diff(currentDay, 'day')
// // 当天
// if (DAY === 0) {
// const year = dayjs(currentDay).diff(memorial_day, 'year')
// text = memorial_day_message_now.replace('{year}', `${year}`)
// }
// // 倒计时
// if (DAY > 0 && DAY <= memorial_day_day) text = memorial_day_message.replace('{day}', `${DAY}`)

if (text) {
template += `\n${text}`
birthdayInfo.isEmpty = false
}
}
// if (text) {
// template += `\n${text}`
// birthdayInfo.isEmpty = false
// }
// }

/**
* 女朋友生日
Expand Down
12 changes: 7 additions & 5 deletions typings/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ interface loveMsgProps {
tips_card_url: string

/* 需要提醒的纪念日: 日期 */
memorial_day: string
memorial_day: string[]
/* 需要提醒的纪念日: 是否开启 */
memorial_day_show: boolean
memorial_day_show: boolean[]
/* 需要提醒的纪念日: 提醒内容,这里的 {day} 为固定替换模板,不可更改 */
memorial_day_message: string
memorial_day_message: string[]
/* 需要提醒的纪念日: 提醒内容,当天 */
memorial_day_message_now: string
memorial_day_message_now: string[]
/* 需要提醒的纪念日: 倒计时多久时开始提醒,单位天 */
memorial_day_day: number
memorial_day_day: number[]
/* 需要独立卡片显示: 当天默认启用独立卡片显示 */
memorial_card_show: boolean[]

/* 女朋友的生日 是否开启 */
girl_birthday_show: boolean
Expand Down

0 comments on commit a4a13a8

Please sign in to comment.