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) let data = '' if (Day > 0) { data = `${Day}天${Hour}小时${Min}分钟` } else { data = `${Hour}小时${Min}分钟` } let format = bytes => { return (bytes / 1024 / 1024).toFixed(2) + 'MB' } let msg = '-------状态-------' msg += `\n运行时间:${data}` 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) } date = null month = null key = null msgKey = null screenshotKey = null 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 (Number(count.month.msg) > 200) { msg += '\n-------本周-------' msg += `\n发送消息:${count.week.msg}条` msg += `\n生成图片:${count.week.screenshot}次` } if (Number(moment().format('D')) >= 8 && Number(count.month.msg) > 400) { msg += '\n-------本月-------' msg += `\n发送消息:${count.month.msg}条` msg += `\n生成图片:${count.month.screenshot}次` } return msg } }