Miao-Yunzai/apps/status.ts

158 lines
3.7 KiB
TypeScript
Raw Normal View History

2024-06-11 22:10:46 +08:00
import { ConfigController as cfg } from 'yunzai/config'
2024-06-11 21:03:42 +08:00
import moment from 'moment'
2024-06-12 10:47:19 +08:00
import { Plugin } from 'yunzai/core'
2024-06-15 11:18:45 +08:00
/**
* tudo
*/
2024-06-11 21:03:42 +08:00
/**
2024-06-17 22:52:15 +08:00
*
2024-06-11 21:03:42 +08:00
*/
2024-06-12 10:47:19 +08:00
export class status extends Plugin {
2024-06-11 21:03:42 +08:00
/**
name: '其他功能',
dsc: '#状态',
*/
constructor() {
2024-06-12 22:36:39 +08:00
super()
this.rule = [
{
2024-06-15 11:39:06 +08:00
reg: /^#状态$/,
2024-06-12 22:36:39 +08:00
fnc: this.status.name
}
]
2024-06-11 21:03:42 +08:00
}
/**
2024-06-17 22:52:15 +08:00
*
* @returns
2024-06-11 21:03:42 +08:00
*/
async status() {
if (this.e.isMaster) return this.statusMaster()
if (!this.e.isGroup) {
2024-06-17 11:01:50 +08:00
this.e.reply('请群聊查看')
2024-06-11 21:03:42 +08:00
return
}
return this.statusGroup()
}
async statusMaster() {
2024-06-17 22:52:15 +08:00
let runTime = moment().diff(
moment.unix(this.e.bot.stat.start_time),
'seconds'
)
2024-06-11 21:03:42 +08:00
let Day = Math.floor(runTime / 3600 / 24)
let Hour = Math.floor((runTime / 3600) % 24)
let Min = Math.floor((runTime / 60) % 60)
2024-06-17 22:52:15 +08:00
let data = ''
2024-06-11 21:03:42 +08:00
if (Day > 0) {
2024-06-17 22:52:15 +08:00
data = `${Day}${Hour}小时${Min}分钟`
2024-06-11 21:03:42 +08:00
} else {
2024-06-17 22:52:15 +08:00
data = `${Hour}小时${Min}分钟`
2024-06-11 21:03:42 +08:00
}
2024-06-17 22:52:15 +08:00
let format = bytes => {
2024-06-11 21:03:42 +08:00
return (bytes / 1024 / 1024).toFixed(2) + 'MB'
}
let msg = '-------状态-------'
2024-06-17 22:52:15 +08:00
msg += `\n运行时间${data}`
2024-06-11 21:03:42 +08:00
msg += `\n内存使用${format(process.memoryUsage().rss)}`
msg += `\n当前版本v${cfg.package.version}`
msg += '\n-------累计-------'
msg += await this.getCount()
2024-06-17 11:01:50 +08:00
await this.e.reply(msg)
2024-06-11 21:03:42 +08:00
}
async statusGroup() {
let msg = '-------状态-------'
msg += await this.getCount(this.e.group_id)
2024-06-17 11:01:50 +08:00
await this.e.reply(msg)
2024-06-11 21:03:42 +08:00
}
2024-06-17 22:52:15 +08:00
date = null
month = null
key = null
msgKey = null
screenshotKey = null
async getCount(groupId: number | string = '') {
2024-06-11 21:03:42 +08:00
this.date = moment().format('MMDD')
this.month = Number(moment().month()) + 1
this.key = 'Yz:count:'
if (groupId) {
this.key += `group:${groupId}:`
}
this.msgKey = {
day: `${this.key}sendMsg:day:`,
month: `${this.key}sendMsg:month:`
}
this.screenshotKey = {
day: `${this.key}screenshot:day:`,
month: `${this.key}screenshot:month:`
}
let week = {
msg: 0,
screenshot: 0
}
for (let i = 0; i <= 6; i++) {
let date = moment().startOf('week').add(i, 'days').format('MMDD')
week.msg += Number(await redis.get(`${this.msgKey.day}${date}`)) ?? 0
2024-06-17 22:52:15 +08:00
week.screenshot +=
Number(await redis.get(`${this.screenshotKey.day}${date}`)) ?? 0
2024-06-11 21:03:42 +08:00
}
let count = {
total: {
2024-06-17 22:52:15 +08:00
msg: (await redis.get(`${this.key}sendMsg:total`)) || 0,
screenshot: (await redis.get(`${this.key}screenshot:total`)) || 0
2024-06-11 21:03:42 +08:00
},
today: {
2024-06-17 22:52:15 +08:00
msg: (await redis.get(`${this.msgKey.day}${this.date}`)) || 0,
screenshot:
(await redis.get(`${this.screenshotKey.day}${this.date}`)) || 0
2024-06-11 21:03:42 +08:00
},
week,
month: {
2024-06-17 22:52:15 +08:00
msg: (await redis.get(`${this.msgKey.month}${this.month}`)) || 0,
screenshot:
(await redis.get(`${this.screenshotKey.month}${this.month}`)) || 0
2024-06-11 21:03:42 +08:00
}
}
let msg = ''
if (groupId) {
msg = `\n发送消息${count.today.msg}`
msg += `\n生成图片${count.today.screenshot}`
} else {
msg = `\n发送消息${count.total.msg}`
msg += `\n生成图片${count.total.screenshot}`
}
2024-06-17 22:52:15 +08:00
if (Number(count.month.msg) > 200) {
2024-06-11 21:03:42 +08:00
msg += '\n-------本周-------'
msg += `\n发送消息${count.week.msg}`
msg += `\n生成图片${count.week.screenshot}`
}
2024-06-17 22:52:15 +08:00
if (Number(moment().format('D')) >= 8 && Number(count.month.msg) > 400) {
2024-06-11 21:03:42 +08:00
msg += '\n-------本月-------'
msg += `\n发送消息${count.month.msg}`
msg += `\n生成图片${count.month.screenshot}`
}
return msg
}
}