Miao-Yunzai/apps/status.ts

145 lines
3.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { ConfigController as cfg } from 'yunzai/config'
import moment from 'moment'
import { Plugin } from 'yunzai/core'
/**
* tudo
*/
/**
*
*/
export class status extends Plugin {
/**
name: '其他功能',
dsc: '#状态',
*/
constructor() {
super()
this.rule = [
{
reg: /^#状态$/,
fnc: this.status.name
}
]
}
/**
*
* @returns
*/
async status() {
if (this.e.isMaster) return this.statusMaster()
if (!this.e.isGroup) {
this.e.reply('请群聊查看')
return
}
return this.statusGroup()
}
async statusMaster() {
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.e.reply(msg)
}
async statusGroup() {
let msg = '-------状态-------'
msg += await this.getCount(this.e.group_id)
await this.e.reply(msg)
}
async getCount(groupId:number | string = '') {
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
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
}
}