Commit a98c42bc authored by nanahira's avatar nanahira

i18n

parent 60db9354
# compiled output
/dist
/node_modules
# Logs
logs
*.log
......@@ -6,105 +10,29 @@ yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
/build
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/data
/output
/dest
/config.yaml
.idea
/config.yaml
\ No newline at end of file
......@@ -3,7 +3,7 @@ import TargetPlugin from '../src';
import ConsolePlugin from '@koishijs/plugin-console';
import * as SandboxPlugin from '@koishijs/plugin-sandbox';
import DatabasePlugin from '@koishijs/plugin-database-memory';
// import CachePlugin from '@koishijs/plugin-cache-lru';
import * as Help from '@koishijs/plugin-help';
import ExtrasInDev from './extras';
const app = new Context({
......@@ -18,9 +18,9 @@ app.plugin(ConsolePlugin, {
open: false,
});
app.plugin(SandboxPlugin);
app.plugin(Help);
// Some services
// app.plugin(CachePlugin);
app.plugin(DatabasePlugin);
// Some extras
......
......@@ -19,6 +19,7 @@
"devDependencies": {
"@koishijs/plugin-console": "^5.0.2",
"@koishijs/plugin-database-memory": "^2.2.0",
"@koishijs/plugin-help": "^2.0.1",
"@koishijs/plugin-sandbox": "^2.5.0",
"@types/jest": "^29.2.0",
"@types/lodash": "^4.14.175",
......@@ -1462,6 +1463,15 @@
"koishi": "^4.10.10"
}
},
"node_modules/@koishijs/plugin-help": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@koishijs/plugin-help/-/plugin-help-2.0.1.tgz",
"integrity": "sha512-pgB6ZdRjR/K8ucOkbdJV+8vAbVCLtQTb//NXmw7ba+BWkJB51cVTZF6EnQJ73F7P2imZpgY0O/j6ABypjeaoHg==",
"dev": true,
"peerDependencies": {
"koishi": "^4.11.0"
}
},
"node_modules/@koishijs/plugin-sandbox": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@koishijs/plugin-sandbox/-/plugin-sandbox-2.5.0.tgz",
......@@ -9613,6 +9623,13 @@
"@minatojs/driver-memory": "^2.1.0"
}
},
"@koishijs/plugin-help": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@koishijs/plugin-help/-/plugin-help-2.0.1.tgz",
"integrity": "sha512-pgB6ZdRjR/K8ucOkbdJV+8vAbVCLtQTb//NXmw7ba+BWkJB51cVTZF6EnQJ73F7P2imZpgY0O/j6ABypjeaoHg==",
"dev": true,
"requires": {}
},
"@koishijs/plugin-sandbox": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@koishijs/plugin-sandbox/-/plugin-sandbox-2.5.0.tgz",
......
......@@ -11,9 +11,16 @@ import {
DefinePlugin,
LifecycleEvents,
InjectLogger,
UseCommand,
PutOption,
PutArg,
PutSession,
CommandLocale,
} from 'koishi-thirdeye';
import { Logger } from 'koishi';
import { Logger, Session } from 'koishi';
import initSqlJs from 'sql.js';
import * as localeZh from './locales/zh';
import * as localeEn from './locales/en';
export * from './config';
......@@ -78,50 +85,60 @@ export default class YGOCardPlugin
this.dbs.forEach((db) => db.close());
}
onApply() {
const ctx = this.ctx;
ctx
.command(
`${this.config.commandName} <cardQuery:string>`,
'查询 YGOPro 卡片',
)
.option('count', '-c <count:posint>', {
fallback: this.config.matchCount,
})
.usage(`使用 ${this.config.commandName} 卡号或关键词 搜索卡片。`)
.example(
`${this.config.commandName} 10000 搜索卡号为 10000 的卡片。 ${this.config.commandName} 青眼白龙 搜索卡名或描述中包含『青眼白龙』的卡片。`,
)
.action(async ({ session, options }, value) => {
const cards = this.queryInAllDBs(value, options.count);
if (!cards.length) {
return `没有找到卡片 ${value} 。`;
}
if (cards.length === 1) {
return cards[0].getDisplayString(this.config);
}
await session.send(
`卡片 ${value} 匹配下列结果:\n--------------------\n${cards
.map((c, i) => `${i + 1}\t${c.getIdAndName()}`)
.join(
'\n',
)}\n--------------------\n输入编号或卡片密码查询对应的卡片。`,
);
const reply = await session.prompt();
if (!reply) {
return;
}
const replyNumber = parseInt(reply);
const card =
cards[replyNumber - 1] ||
cards.find((c) => c.id === replyNumber) ||
cards.find((c) => c.name === value) ||
cards.find((c) => c.name.includes(value)) ||
cards.find((c) => c.desc.includes(value));
if (!card) {
return '没有找到卡片。';
}
return card.getDisplayString(this.config);
});
@UseCommand('{{commandName}} [query]')
@CommandLocale('zh', localeZh.cardCommand)
@CommandLocale('en', localeEn.cardCommand)
async onCardCommand(
@PutArg(0) query: string,
@PutOption('count', '-c <count:posint>') count: number,
@PutSession() session: Session,
) {
if (!query) {
await session.send(<i18n path={'.prompt-input'} />);
query = await session.prompt();
}
if (!query) return;
if (!count) {
count = this.config.matchCount;
}
const cards = this.queryInAllDBs(query, count);
if (!cards.length) {
return <i18n path={'.not-found'} />;
}
if (cards.length === 1) {
return cards[0].getDisplayString(this.config);
}
const itemLines = cards.map((c, i) => `${i + 1}. ${c.getIdAndName()}`);
const borderLength = Math.max(...itemLines.map((l) => l.length)) + 1;
await session.send(
<>
<i18n path={'.select-prefix-part1'} />
{query}
<i18n path={'.select-prefix-part2'} />
{'\n'}
{_.repeat('-', borderLength)}
{'\n'}
{itemLines.join('\n')}
{'\n'}
{_.repeat('-', borderLength)}
{'\n'}
<i18n path={'.select-suffix'} />
</>,
);
const reply = await session.prompt();
if (!reply) {
return;
}
const replyNumber = parseInt(reply);
const card =
cards[replyNumber - 1] ||
cards.find((c) => c.id === replyNumber) ||
cards.find((c) => c.name === reply) ||
cards.find((c) => c.name.includes(reply)) ||
cards.find((c) => c.desc.includes(reply));
if (!card) {
return <i18n path={'.not-found'} />;
}
return card.getDisplayString(this.config);
}
}
import { CommandLocaleDef } from 'koishi-thirdeye';
export const cardCommand: CommandLocaleDef = {
description: 'Search for YGOPro Cards.',
usage: 'Use {{commandName}} Card ID or Keywords to search for cards.',
examples: '{{commandName}} 10000\n{{commandName}} Cyber Dragon',
messages: {
'not-found': 'Card Not Found.',
'prompt-input': 'Please enter the card you want to search for.',
'select-prefix-part1': 'The keyword "',
'select-prefix-part2': '" matches with the following cards:',
'select-suffix':
'Please enter the number or card ID to search for the corresponding card.',
},
};
import { CommandLocaleDef } from 'koishi-thirdeye';
export const cardCommand: CommandLocaleDef = {
description: '查询 YGOPro 卡片。',
usage: '使用 {{commandName}} 卡号或关键词 搜索卡片。',
examples: '{{commandName}} 10000\n{{commandName}} 青眼白龙',
messages: {
'not-found': '没有找到卡片。',
'prompt-input': '请输入要查询的卡片。',
'select-prefix-part1': "'",
'select-prefix-part2': "' 匹配下列结果:",
'select-suffix': '输入编号或卡片密码查询对应的卡片。',
},
};
......@@ -8,7 +8,9 @@
"experimentalDecorators": true,
"declaration": true,
"sourceMap": true,
"skipLibCheck": true
"skipLibCheck": true,
"jsx": "react-jsx",
"jsxImportSource": "@satorijs/element"
},
"compileOnSave": true,
"allowJs": true,
......@@ -16,6 +18,10 @@
"*.ts",
"src/**/*.ts",
"tests/**/*.ts",
"dev/**/*.ts"
"dev/**/*.ts",
"*.tsx",
"src/**/*.tsx",
"tests/**/*.tsx",
"dev/**/*.tsx"
]
}
const path = require('path');
const packgeInfo = require('./package.json');
const { ESBuildMinifyPlugin } = require('esbuild-loader');
function externalsFromDep() {
return Object.fromEntries(
......@@ -16,7 +15,7 @@ function externalsFromDep() {
const packAll = !!process.env.PACK_ALL;
module.exports = {
entry: './src/index.ts',
entry: './src/index.tsx',
mode: 'production',
target: 'node',
devtool: 'source-map',
......@@ -42,15 +41,8 @@ module.exports = {
},
externals: {
koishi: 'koishi',
'@satorijs/satori': '@satorijs/satori',
cordis: 'cordis',
'@satorijs/element': '@satorijs/element',
'@satorijs/element/jsx-runtime': '@satorijs/element',
...(packAll ? {} : externalsFromDep()),
},
optimization: {
minimizer: [
new ESBuildMinifyPlugin({
keepNames: true,
}),
],
},
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment