diff --git a/packages/shell/src/services/logger/index.ts b/packages/shell/src/services/logger/index.ts index ea48505..9d500e8 100644 --- a/packages/shell/src/services/logger/index.ts +++ b/packages/shell/src/services/logger/index.ts @@ -5,15 +5,23 @@ import { mkdir, open, rm, writeFile } from 'node:fs/promises' import { join } from 'node:path' import { env, platform } from 'node:process' import type { Event } from '../../satori/types' +import type { ColorFormatter } from '../../utils/colors' +import { grey, red, yellow } from '../../utils/colors' import { exists } from '../../utils/fs' import { formatTimeforFilename, p2, p4 } from '../../utils/string' import { timeout } from '../../utils/time' import { getAuthData } from '../authData' import { baseDir } from '../baseDir' import { getConfig } from '../config' -import { logiriMessageCreated } from './logiri' -import type { ColorFormatter } from '../../utils/colors' -import { grey, red, yellow } from '../../utils/colors' +import { + logiriFriendRequest, + logiriGuildMemberAdded, + logiriGuildRequest, + logiriMessageCreated, + logiriMessageDeleted, + logiriUnsafeGuildMute, + logiriUnsafeGuildUnmute, +} from './logiri' interface LogOptions { code?: number @@ -43,6 +51,12 @@ class ChronocatLogger { constructor() { this.logiri = new Logiri() this.logiri.register(logiriMessageCreated) + this.logiri.register(logiriMessageDeleted) + this.logiri.register(logiriGuildRequest) + this.logiri.register(logiriFriendRequest) + this.logiri.register(logiriGuildMemberAdded) + this.logiri.register(logiriUnsafeGuildMute) + this.logiri.register(logiriUnsafeGuildUnmute) this.init = (async () => { const dir = join(baseDir, 'logs') diff --git a/packages/shell/src/services/logger/logiri.ts b/packages/shell/src/services/logger/logiri.ts index f349b04..f384271 100644 --- a/packages/shell/src/services/logger/logiri.ts +++ b/packages/shell/src/services/logger/logiri.ts @@ -1,5 +1,6 @@ import { link } from 'logiri' import type { Event } from '../../satori/types' +import { ChannelType } from '../../satori/types' import { blue, cyan, grey } from '../../utils/colors' import { send } from './messager' @@ -10,14 +11,18 @@ export const logiriMessageCreated = async (data: object) => { const message = rawMessage.join('').replace(/\r/g, '').replace(/\n/g, ' ') return [message].map( (x) => - `${blue( - link( - d.channel?.id === d.guild?.id - ? `${d.channel?.name}(${d.channel?.id})` - : `${d.guild?.name}(${d.guild?.id})/${d.channel?.name}(${d.channel?.id})`, - d.guild?.avatar, - ), - )}${grey('-')}${cyan( + `${ + d.channel?.type === ChannelType.DIRECT + ? '' + : blue( + link( + d.channel?.id === d.guild?.id + ? `${d.channel?.name}(${d.channel?.id})` + : `${d.guild?.name}(${d.guild?.id})/${d.channel?.name}(${d.channel?.id})`, + d.guild?.avatar, + ), + ) + }${d.channel?.type === ChannelType.DIRECT ? '' : grey('-')}${cyan( link( `${d.user?.name || d.member?.nick}(${d.user?.id})`, d.user?.avatar, @@ -25,3 +30,99 @@ export const logiriMessageCreated = async (data: object) => { )}${grey(':')} ${x}`, ) } + +export const logiriMessageDeleted = async (data: object) => { + const d = data as Event + if (d.type !== 'message-deleted') return + const rawMessage = await send(d.message?.content) + const message = rawMessage.join('').replace(/\r/g, '').replace(/\n/g, ' ') + return [message].map( + (x) => + `${ + d.channel?.type === ChannelType.DIRECT + ? '' + : blue( + link( + d.channel?.id === d.guild?.id + ? `${d.channel?.name}(${d.channel?.id})` + : `${d.guild?.name}(${d.guild?.id})/${d.channel?.name}(${d.channel?.id})`, + d.guild?.avatar, + ), + ) + }${d.channel?.type === ChannelType.DIRECT ? '' : grey('-')}${cyan( + link( + `${d.user?.name || d.member?.nick}(${d.user?.id})`, + d.user?.avatar, + ), + )}${grey(':')} ${x}`, + ) +} + +export const logiriGuildRequest = async (data: object) => { + const d = data as Event + if (d.type !== 'guild-request') return + return [ + `${grey('用户')} ${cyan( + link(`${d.user?.name || d.member?.nick}(${d.user?.id})`, d.user?.avatar), + )} ${grey('申请加入群')} ${blue( + link(`${d.guild?.name}(${d.guild?.id})`, d.guild?.avatar), + )}`, + ] +} + +export const logiriFriendRequest = async (data: object) => { + const d = data as Event + if (d.type !== 'friend-request') return + return [ + `${grey('用户')} ${cyan( + link(`${d.user?.name || d.member?.nick}(${d.user?.id})`, d.user?.avatar), + )} ${grey('申请添加好友')}`, + ] +} + +export const logiriGuildMemberAdded = async (data: object) => { + const d = data as Event + if (d.type !== 'guild-member-added') return + return [ + `${grey('用户')} ${cyan( + link(`${d.user?.name || d.member?.nick}(${d.user?.id})`, d.user?.avatar), + )} ${grey('由')} ${cyan( + link( + `${d.operator?.name || d.operator?.nick}(${d.operator?.id})`, + d.operator?.avatar, + ), + )} ${grey('批准/邀请加入了群')} ${blue( + link(`${d.guild?.name}(${d.guild?.id})`, d.guild?.avatar), + )}`, + ] +} + +export const logiriUnsafeGuildMute = async (data: object) => { + const d = data as Event + if (d.type !== 'unsafe-guild-mute') return + return [ + `${grey('用户')} ${cyan( + link(`${d.user?.name || d.member?.nick}(${d.user?.id})`, d.user?.avatar), + )} ${grey('由管理')} ${cyan( + link( + `${d.operator?.name || d.operator?.nick}(${d.operator?.id})`, + d.operator?.avatar, + ), + )} ${grey('禁言')}`, + ] +} + +export const logiriUnsafeGuildUnmute = async (data: object) => { + const d = data as Event + if (d.type !== 'unsafe-guild-unmute') return + return [ + `${grey('用户')} ${cyan( + link(`${d.user?.name || d.member?.nick}(${d.user?.id})`, d.user?.avatar), + )} ${grey('由管理')} ${cyan( + link( + `${d.operator?.name || d.operator?.nick}(${d.operator?.id})`, + d.operator?.avatar, + ), + )} ${grey('解除禁言')}`, + ] +} diff --git a/packages/shell/src/services/logger/messager.ts b/packages/shell/src/services/logger/messager.ts index 7e460ec..de8d64b 100644 --- a/packages/shell/src/services/logger/messager.ts +++ b/packages/shell/src/services/logger/messager.ts @@ -1,6 +1,7 @@ import h from '@satorijs/element' import { link } from 'logiri' import { grey } from '../../utils/colors' +import { PLATFORM } from '../../utils/consts' type DisplayComponent = string @@ -40,6 +41,10 @@ const visit = async (element: h): Promise => { return [link('[语音]', attrs['src'] as string)] } + case 'video': { + return [link('[视频]', attrs['src'] as string)] + } + case 'file': { return [link('[文件]', attrs['src'] as string)] } @@ -65,10 +70,51 @@ const visit = async (element: h): Promise => { ] } - case 'chronocat:poke': { + case `${PLATFORM}:poke`: { return ['[戳一戳]'] } + case `${PLATFORM}:pcpoke`: { + return ['[窗口抖动]'] + } + + case `${PLATFORM}:face`: { + let result = '' + + let description = '表情' + if (attrs['unsafe-super']) description = '超级表情' + if (attrs['unsafe-market-emoticon']) description = 'Emoticon 表情' + + result = link( + `[${description}]`, + h.select(children, 'img')?.[0]?.attrs['src'] as string | undefined, + ) + + if (attrs['unsafe-result-id']) + result += ` 掷骰结果:${attrs['unsafe-result-id']}` + if (attrs['unsafe-chain-count']) + result += ` 接龙个数:${attrs['unsafe-chain-count']}` + return [result] + } + + case `${PLATFORM}:marketface`: { + return [ + link( + `[商城表情]`, + h.select(children, 'img')?.[0]?.attrs['src'] as string | undefined, + ), + ] + } + + case `${PLATFORM}:facebubble`: { + return [ + link( + `[气泡表情]`, + h.select(children, 'img')?.[0]?.attrs['src'] as string | undefined, + ), + ] + } + case 'message': { if ('forward' in attrs) { if ('id' in attrs) {