Miao-Yunzai/plugins/system/status.js

125 lines
3.4 KiB
JavaScript
Raw Normal View History

2023-05-11 16:03:18 +08:00
import cfg from '../../lib/config/config.js'
import moment from 'moment'
export class status extends plugin {
2023-07-28 19:36:51 +08:00
constructor() {
2023-05-11 16:03:18 +08:00
super({
name: '其他功能',
dsc: '#状态',
event: 'message',
rule: [
{
reg: '^#状态$',
fnc: 'status'
}
]
})
}
2023-07-28 19:36:51 +08:00
async status() {
2023-05-11 16:03:18 +08:00
if (this.e.isMaster) return this.statusMaster()
2023-07-28 19:36:51 +08:00
if (!this.e.isGroup) return this.reply('请群聊查看')
2023-05-11 16:03:18 +08:00
return this.statusGroup()
}
2023-07-28 19:36:51 +08:00
async statusMaster() {
2023-05-11 16:03:18 +08:00
let runTime = moment().diff(moment.unix(this.e.bot.stat.start_time), 'seconds')
let Day = Math.floor(runTime / 3600 / 24)
let Hour = Math.floor((runTime / 3600) % 24)
let Min = Math.floor((runTime / 60) % 60)
if (Day > 0) {
runTime = `${Day}${Hour}小时${Min}分钟`
} else {
runTime = `${Hour}小时${Min}分钟`
}
let format = (bytes) => {
return (bytes / 1024 / 1024).toFixed(2) + 'MB'
}
let msg = '-------状态-------'
msg += `\n运行时间:${runTime}`
msg += `\n内存使用:${format(process.memoryUsage().rss)}`
msg += `\n当前版本v${cfg.package.version}`
msg += '\n-------累计-------'
msg += await this.getCount()
await this.reply(msg)
}
2023-07-28 19:36:51 +08:00
async statusGroup() {
2023-05-11 16:03:18 +08:00
let msg = '-------状态-------'
msg += await this.getCount(this.e.group_id)
await this.reply(msg)
}
2023-07-28 19:36:51 +08:00
async getCount(groupId = '') {
2023-05-11 16:03:18 +08:00
this.date = moment().format('MMDD')
this.month = Number(moment().month()) + 1
this.key = 'Yz:count:'
2023-07-28 19:36:51 +08:00
if (groupId) this.key += `group:${groupId}:`
2023-05-11 16:03:18 +08:00
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
week.screenshot += Number(await redis.get(`${this.screenshotKey.day}${date}`)) ?? 0
}
let count = {
total: {
msg: await redis.get(`${this.key}sendMsg:total`) || 0,
screenshot: await redis.get(`${this.key}screenshot:total`) || 0
},
today: {
msg: await redis.get(`${this.msgKey.day}${this.date}`) || 0,
screenshot: await redis.get(`${this.screenshotKey.day}${this.date}`) || 0
},
week,
month: {
msg: await redis.get(`${this.msgKey.month}${this.month}`) || 0,
screenshot: await redis.get(`${this.screenshotKey.month}${this.month}`) || 0
}
}
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}`
}
if (count.month.msg > 200) {
msg += '\n-------本周-------'
msg += `\n发送消息:${count.week.msg}`
msg += `\n生成图片:${count.week.screenshot}`
}
if (moment().format('D') >= 8 && count.month.msg > 400) {
msg += '\n-------本月-------'
msg += `\n发送消息:${count.month.msg}`
msg += `\n生成图片:${count.month.screenshot}`
}
return msg
}
}