chore: lint

This commit is contained in:
Il Harper 2024-03-10 01:14:56 +08:00
parent 71d8628e96
commit 461c8b5e25
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
7 changed files with 42 additions and 36 deletions

View File

@ -3,7 +3,6 @@
import Link from '@docusaurus/Link' import Link from '@docusaurus/Link'
// eslint-disable-next-line import/no-unresolved // eslint-disable-next-line import/no-unresolved
import Admonition from '@theme/Admonition' import Admonition from '@theme/Admonition'
import { clsx } from 'clsx'
const errorScopeMap = { const errorScopeMap = {
user: { user: {

View File

@ -2,10 +2,7 @@ import { cp, mkdir } from 'node:fs/promises'
import { join, resolve } from 'node:path' import { join, resolve } from 'node:path'
void (async () => { void (async () => {
const distPath = resolve( const distPath = resolve(__dirname, '../../build/dist/iife/')
__dirname,
'../../build/dist/iife/',
)
await mkdir(distPath, { recursive: true }) await mkdir(distPath, { recursive: true })
await cp(join(__dirname, 'lib/index.js'), join(distPath, 'chronocat.js')) await cp(join(__dirname, 'lib/index.js'), join(distPath, 'chronocat.js'))
})() })()

View File

@ -4,16 +4,16 @@ import { version as ccApiVersion } from '@chronocat/engine-chronocat-api/package
import { version as ccEventVersion } from '@chronocat/engine-chronocat-event/package.json' import { version as ccEventVersion } from '@chronocat/engine-chronocat-event/package.json'
import { apply as ccEvent } from '@chronocat/engine-chronocat-event' import { apply as ccEvent } from '@chronocat/engine-chronocat-event'
void chronocat().then(x => { void chronocat().then((x) => {
x?.load({ x?.load({
name: 'engine-chronocat-api', name: 'engine-chronocat-api',
version: ccApiVersion, version: ccApiVersion,
apply: ccApi apply: ccApi,
}) })
x?.load({ x?.load({
name: 'engine-chronocat-event', name: 'engine-chronocat-event',
version: ccEventVersion, version: ccEventVersion,
apply: ccEvent apply: ccEvent,
}) })
}) })

View File

@ -12,7 +12,8 @@ import { getAuthData } from '../authData'
import { baseDir } from '../baseDir' import { baseDir } from '../baseDir'
import { getConfig } from '../config' import { getConfig } from '../config'
import { logiriMessageCreated } from './logiri' import { logiriMessageCreated } from './logiri'
import { ColorFormatter, grey, red, yellow } from '../../utils/colors' import type { ColorFormatter } from '../../utils/colors'
import { grey, red, yellow } from '../../utils/colors'
interface LogOptions { interface LogOptions {
code?: number code?: number

View File

@ -9,14 +9,18 @@ export const logiriMessageCreated = async (data: object) => {
const messages = await new LogiriMessager().send(d.message?.content) const messages = await new LogiriMessager().send(d.message?.content)
return messages.map( return messages.map(
(x) => (x) =>
`${blue(link( `${blue(
link(
d.channel?.id === d.guild?.id d.channel?.id === d.guild?.id
? `${d.channel?.name}(${d.channel?.id})` ? `${d.channel?.name}(${d.channel?.id})`
: `${d.guild?.name}(${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.guild?.avatar,
))}${grey('-')}${cyan(link( ),
)}${grey('-')}${cyan(
link(
`${d.user?.name || d.member?.nick}(${d.user?.id})`, `${d.user?.name || d.member?.nick}(${d.user?.id})`,
d.user?.avatar, d.user?.avatar,
))}${grey(':')} ${x}`, ),
)}${grey(':')} ${x}`,
) )
} }

View File

@ -68,13 +68,14 @@ export class LogiriMessager {
const id = author?.attrs['user-id'] as string | undefined const id = author?.attrs['user-id'] as string | undefined
this.children.push( this.children.push(
grey(id grey(
id
? `${link( ? `${link(
`[回复${id}]`, `[回复${id}]`,
`http://thirdqq.qlogo.cn/headimg_dl?dst_uin=${id}&spec=640`, `http://thirdqq.qlogo.cn/headimg_dl?dst_uin=${id}&spec=640`,
)} ` )} `
: `[回复] `) : `[回复] `,
, ),
) )
return return
} }

View File

@ -1,10 +1,12 @@
import * as fs from 'node:fs' import * as cp from 'node:child_process'
import * as crypto from 'node:crypto' import * as crypto from 'node:crypto'
import * as fs from 'node:fs'
const watchFolder = process.argv[2] const watchFolder = process.argv[2]
if (!watchFolder) { if (!watchFolder) {
console.error('Usage: node -r esbuild-register runOnChanged <folder> <command>') console.error(
'Usage: node -r esbuild-register runOnChanged <folder> <command>',
)
process.exit(1) process.exit(1)
} }
const command = process.argv.slice(3).join(' ') const command = process.argv.slice(3).join(' ')
@ -12,10 +14,10 @@ const command = process.argv.slice(3).join(' ')
// create or compare hash of files in the folder // create or compare hash of files in the folder
let hasChanged = false let hasChanged = false
let hashes = new Map() let hashes = new Map<string, string>()
const sha1 = (data: string) => crypto.createHash('sha1').update(data).digest('hex')
const sha1 = (data: string) =>
crypto.createHash('sha1').update(data).digest('hex')
const hashFile = (file: string) => { const hashFile = (file: string) => {
const hash = sha1(fs.readFileSync(file, 'utf8')) const hash = sha1(fs.readFileSync(file, 'utf8'))
@ -28,7 +30,7 @@ const hashFile = (file: string) => {
const hashFilepath = `${watchFolder}/.runOnChanged.hashes.json` const hashFilepath = `${watchFolder}/.runOnChanged.hashes.json`
const hashFolder = (folder: string) => { const hashFolder = (folder: string) => {
const files = fs.readdirSync(folder) const files = fs.readdirSync(folder)
files.forEach((file: any) => { files.forEach((file) => {
const path = `${folder}/${file}` const path = `${folder}/${file}`
if (file.endsWith('.runOnChanged.hashes.json')) return if (file.endsWith('.runOnChanged.hashes.json')) return
@ -42,7 +44,10 @@ const hashFolder = (folder: string) => {
} }
if (fs.existsSync(hashFilepath)) { if (fs.existsSync(hashFilepath)) {
const oldHashes = JSON.parse(fs.readFileSync(hashFilepath, 'utf8')) const oldHashes = JSON.parse(fs.readFileSync(hashFilepath, 'utf8')) as Record<
string,
string
>
hashes = new Map(Object.entries(oldHashes)) hashes = new Map(Object.entries(oldHashes))
} }
@ -51,8 +56,7 @@ hashFolder(watchFolder)
if (hasChanged) { if (hasChanged) {
console.log('[+] Files have changed, rebuilding...') console.log('[+] Files have changed, rebuilding...')
fs.writeFileSync(hashFilepath, JSON.stringify(Object.fromEntries(hashes))) fs.writeFileSync(hashFilepath, JSON.stringify(Object.fromEntries(hashes)))
require('child_process').execSync(command, { stdio: 'inherit' }) cp.execSync(command, { stdio: 'inherit' })
} else { } else {
console.log('[-] Files not changed :)') console.log('[-] Files not changed :)')
} }