Commit a98c42bc authored by nanahira's avatar nanahira

i18n

parent 60db9354
# compiled output
/dist
/node_modules
# Logs # Logs
logs logs
*.log *.log
...@@ -6,105 +10,29 @@ yarn-debug.log* ...@@ -6,105 +10,29 @@ yarn-debug.log*
yarn-error.log* yarn-error.log*
lerna-debug.log* lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html) # OS
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json .DS_Store
# Runtime data # Tests
pids /coverage
*.pid /.nyc_output
*.seed
*.pid.lock # IDEs and editors
/.idea
# Directory for instrumented libs generated by jscoverage/JSCover .project
lib-cov .classpath
.c9/
# Coverage directory used by tools like istanbul *.launch
coverage .settings/
*.lcov *.sublime-workspace
# nyc test coverage # IDE - VSCode
.nyc_output .vscode/*
!.vscode/settings.json
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) !.vscode/tasks.json
.grunt !.vscode/launch.json
!.vscode/extensions.json
# Bower dependency directory (https://bower.io/)
bower_components /data
# 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
/output /output
/dest /config.yaml
/config.yaml \ No newline at end of file
.idea
...@@ -3,7 +3,7 @@ import TargetPlugin from '../src'; ...@@ -3,7 +3,7 @@ import TargetPlugin from '../src';
import ConsolePlugin from '@koishijs/plugin-console'; import ConsolePlugin from '@koishijs/plugin-console';
import * as SandboxPlugin from '@koishijs/plugin-sandbox'; import * as SandboxPlugin from '@koishijs/plugin-sandbox';
import DatabasePlugin from '@koishijs/plugin-database-memory'; 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'; import ExtrasInDev from './extras';
const app = new Context({ const app = new Context({
...@@ -18,9 +18,9 @@ app.plugin(ConsolePlugin, { ...@@ -18,9 +18,9 @@ app.plugin(ConsolePlugin, {
open: false, open: false,
}); });
app.plugin(SandboxPlugin); app.plugin(SandboxPlugin);
app.plugin(Help);
// Some services // Some services
// app.plugin(CachePlugin);
app.plugin(DatabasePlugin); app.plugin(DatabasePlugin);
// Some extras // Some extras
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
"devDependencies": { "devDependencies": {
"@koishijs/plugin-console": "^5.0.2", "@koishijs/plugin-console": "^5.0.2",
"@koishijs/plugin-database-memory": "^2.2.0", "@koishijs/plugin-database-memory": "^2.2.0",
"@koishijs/plugin-help": "^2.0.1",
"@koishijs/plugin-sandbox": "^2.5.0", "@koishijs/plugin-sandbox": "^2.5.0",
"@types/jest": "^29.2.0", "@types/jest": "^29.2.0",
"@types/lodash": "^4.14.175", "@types/lodash": "^4.14.175",
...@@ -1462,6 +1463,15 @@ ...@@ -1462,6 +1463,15 @@
"koishi": "^4.10.10" "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": { "node_modules/@koishijs/plugin-sandbox": {
"version": "2.5.0", "version": "2.5.0",
"resolved": "https://registry.npmjs.org/@koishijs/plugin-sandbox/-/plugin-sandbox-2.5.0.tgz", "resolved": "https://registry.npmjs.org/@koishijs/plugin-sandbox/-/plugin-sandbox-2.5.0.tgz",
...@@ -9613,6 +9623,13 @@ ...@@ -9613,6 +9623,13 @@
"@minatojs/driver-memory": "^2.1.0" "@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": { "@koishijs/plugin-sandbox": {
"version": "2.5.0", "version": "2.5.0",
"resolved": "https://registry.npmjs.org/@koishijs/plugin-sandbox/-/plugin-sandbox-2.5.0.tgz", "resolved": "https://registry.npmjs.org/@koishijs/plugin-sandbox/-/plugin-sandbox-2.5.0.tgz",
......
...@@ -11,9 +11,16 @@ import { ...@@ -11,9 +11,16 @@ import {
DefinePlugin, DefinePlugin,
LifecycleEvents, LifecycleEvents,
InjectLogger, InjectLogger,
UseCommand,
PutOption,
PutArg,
PutSession,
CommandLocale,
} from 'koishi-thirdeye'; } from 'koishi-thirdeye';
import { Logger } from 'koishi'; import { Logger, Session } from 'koishi';
import initSqlJs from 'sql.js'; import initSqlJs from 'sql.js';
import * as localeZh from './locales/zh';
import * as localeEn from './locales/en';
export * from './config'; export * from './config';
...@@ -78,50 +85,60 @@ export default class YGOCardPlugin ...@@ -78,50 +85,60 @@ export default class YGOCardPlugin
this.dbs.forEach((db) => db.close()); this.dbs.forEach((db) => db.close());
} }
onApply() { @UseCommand('{{commandName}} [query]')
const ctx = this.ctx; @CommandLocale('zh', localeZh.cardCommand)
ctx @CommandLocale('en', localeEn.cardCommand)
.command( async onCardCommand(
`${this.config.commandName} <cardQuery:string>`, @PutArg(0) query: string,
'查询 YGOPro 卡片', @PutOption('count', '-c <count:posint>') count: number,
) @PutSession() session: Session,
.option('count', '-c <count:posint>', { ) {
fallback: this.config.matchCount, if (!query) {
}) await session.send(<i18n path={'.prompt-input'} />);
.usage(`使用 ${this.config.commandName} 卡号或关键词 搜索卡片。`) query = await session.prompt();
.example( }
`${this.config.commandName} 10000 搜索卡号为 10000 的卡片。 ${this.config.commandName} 青眼白龙 搜索卡名或描述中包含『青眼白龙』的卡片。`, if (!query) return;
) if (!count) {
.action(async ({ session, options }, value) => { count = this.config.matchCount;
const cards = this.queryInAllDBs(value, options.count); }
if (!cards.length) { const cards = this.queryInAllDBs(query, count);
return `没有找到卡片 ${value} 。`; if (!cards.length) {
} return <i18n path={'.not-found'} />;
if (cards.length === 1) { }
return cards[0].getDisplayString(this.config); if (cards.length === 1) {
} return cards[0].getDisplayString(this.config);
await session.send( }
`卡片 ${value} 匹配下列结果:\n--------------------\n${cards const itemLines = cards.map((c, i) => `${i + 1}. ${c.getIdAndName()}`);
.map((c, i) => `${i + 1}\t${c.getIdAndName()}`) const borderLength = Math.max(...itemLines.map((l) => l.length)) + 1;
.join( await session.send(
'\n', <>
)}\n--------------------\n输入编号或卡片密码查询对应的卡片。`, <i18n path={'.select-prefix-part1'} />
); {query}
const reply = await session.prompt(); <i18n path={'.select-prefix-part2'} />
if (!reply) { {'\n'}
return; {_.repeat('-', borderLength)}
} {'\n'}
const replyNumber = parseInt(reply); {itemLines.join('\n')}
const card = {'\n'}
cards[replyNumber - 1] || {_.repeat('-', borderLength)}
cards.find((c) => c.id === replyNumber) || {'\n'}
cards.find((c) => c.name === value) || <i18n path={'.select-suffix'} />
cards.find((c) => c.name.includes(value)) || </>,
cards.find((c) => c.desc.includes(value)); );
if (!card) { const reply = await session.prompt();
return '没有找到卡片。'; if (!reply) {
} return;
return card.getDisplayString(this.config); }
}); 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 @@ ...@@ -8,7 +8,9 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"declaration": true, "declaration": true,
"sourceMap": true, "sourceMap": true,
"skipLibCheck": true "skipLibCheck": true,
"jsx": "react-jsx",
"jsxImportSource": "@satorijs/element"
}, },
"compileOnSave": true, "compileOnSave": true,
"allowJs": true, "allowJs": true,
...@@ -16,6 +18,10 @@ ...@@ -16,6 +18,10 @@
"*.ts", "*.ts",
"src/**/*.ts", "src/**/*.ts",
"tests/**/*.ts", "tests/**/*.ts",
"dev/**/*.ts" "dev/**/*.ts",
"*.tsx",
"src/**/*.tsx",
"tests/**/*.tsx",
"dev/**/*.tsx"
] ]
} }
const path = require('path'); const path = require('path');
const packgeInfo = require('./package.json'); const packgeInfo = require('./package.json');
const { ESBuildMinifyPlugin } = require('esbuild-loader');
function externalsFromDep() { function externalsFromDep() {
return Object.fromEntries( return Object.fromEntries(
...@@ -16,7 +15,7 @@ function externalsFromDep() { ...@@ -16,7 +15,7 @@ function externalsFromDep() {
const packAll = !!process.env.PACK_ALL; const packAll = !!process.env.PACK_ALL;
module.exports = { module.exports = {
entry: './src/index.ts', entry: './src/index.tsx',
mode: 'production', mode: 'production',
target: 'node', target: 'node',
devtool: 'source-map', devtool: 'source-map',
...@@ -42,15 +41,8 @@ module.exports = { ...@@ -42,15 +41,8 @@ module.exports = {
}, },
externals: { externals: {
koishi: 'koishi', koishi: 'koishi',
'@satorijs/satori': '@satorijs/satori', '@satorijs/element': '@satorijs/element',
cordis: 'cordis', '@satorijs/element/jsx-runtime': '@satorijs/element',
...(packAll ? {} : externalsFromDep()), ...(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