Commit 10f10185 authored by nanahira's avatar nanahira

first

parent a171a75a
Pipeline #9723 passed with stages
in 1 minute and 43 seconds
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# 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
/config.yaml
.git*
Dockerfile
.dockerignore
webpack.config.js
dist/*
build/*
\ No newline at end of file
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# 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
/config.yaml
\ No newline at end of file
stages:
- build
- deploy
variables:
GIT_DEPTH: "1"
build:
stage: build
tags:
- linux
script:
- npm ci
- npm run build
artifacts:
paths:
- dist/
upload_to_minio:
stage: deploy
dependencies:
- build
tags:
- linux
script:
- aws s3 --endpoint=https://minio.mycard.moe:9000 sync --delete dist/full/ s3://nanahira/koishi-plugin/myplugin
only:
- master
deploy_npm:
stage: deploy
dependencies:
- build
tags:
- linux
script:
- apt update;apt -y install coreutils
- echo $NPMRC | base64 --decode > ~/.npmrc
- npm publish . --access public
only:
- master
/install-npm.sh
.git*
/data
/output
/config.yaml
.idea
.dockerignore
Dockerfile
/src
/dist/full
{
"singleQuote": true,
"trailingComma": "all"
}
\ No newline at end of file
The MIT License (MIT)
Copyright (c) 2021 Nanahira
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Koishi Plugin Mcinfo
# koishi-plugin-mcinfo
Koishi 的 Minecraft 服务器信息查询插件。
\ No newline at end of file
Koishi 的 Minecraft 服务器信息查询插件。
## 安装
### npm
```bash
npm install koishi-plugin-mcinfo
```
### 直接安装
在 https://cdn02.moecube.com:444/nanahira/koishi-plugin/mcinfo/index.js 下载即可。
## 配置
无。
#!/bin/bash
npm install --save \
source-map-support \
koishi-thirdeye
npm install --save-peer \
koishi@latest
npm install --save-dev \
@types/node \
typescript \
'@typescript-eslint/eslint-plugin@^4.28.2' \
'@typescript-eslint/parser@^4.28.2 '\
'eslint@^7.30.0' \
'eslint-config-prettier@^8.3.0' \
'eslint-plugin-prettier@^3.4.0' \
prettier \
raw-loader \
ts-loader \
webpack \
webpack-cli \
ws
This diff is collapsed.
{
"name": "koishi-plugin-mcinfo",
"description": "Koishi 的 Minecraft 服务器信息查询插件。",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"lint": "eslint --fix .",
"build": "webpack && env PACK_ALL=1 webpack"
},
"repository": {
"type": "git",
"url": "https://code.mycard.moe/3rdeye/koishi-plugin-mcinfo.git"
},
"author": "Nanahira <nanahira@momobako.com>",
"license": "MIT",
"keywords": [
"Koishi.js",
"qqbot",
"cqhttp",
"onebot"
],
"bugs": {
"url": "https://code.mycard.moe/3rdeye/koishi-plugin-mcinfo/issues"
},
"homepage": "https://code.mycard.moe/3rdeye/koishi-plugin-mcinfo",
"dependencies": {
"koishi-thirdeye": "^8.3.2",
"minecraft-protocol": "^1.30.0",
"source-map-support": "^0.5.21"
},
"peerDependencies": {
"koishi": "^4.2.1"
},
"devDependencies": {
"@types/node": "^17.0.18",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.1",
"prettier": "^2.5.1",
"raw-loader": "^4.0.2",
"ts-loader": "^9.2.6",
"typescript": "^4.5.5",
"webpack": "^5.69.1",
"webpack-cli": "^4.9.2",
"ws": "^8.5.0"
}
}
import 'source-map-support/register';
import {
DefinePlugin,
BasePlugin,
UseCommand,
CommandUsage,
CommandExample,
PutOption,
InjectLogger,
} from 'koishi-thirdeye';
import { ping, NewPingResult } from 'minecraft-protocol';
import { Logger, segment } from 'koishi';
@DefinePlugin({ name: 'mcinfo' })
export default class MinecraftInfoPlugin extends BasePlugin<any> {
private getServerText(result: NewPingResult) {
let text = '';
if (result.favicon?.startsWith('data:image/png;base64,')) {
const base64Text = result.favicon.slice(22).replace(/\n/g, '');
text += segment.image(`base64://${base64Text}`);
text += '\n';
}
if (result.version) {
text += `版本: ${result.version.name}\n`;
}
if (result.players) {
text += `玩家: ${result.players.online}/${result.players.max}\n`;
for (const player of result.players.sample || []) {
text += `* ${player.name}\n`;
}
}
text += `延迟: ${result.latency} ms`;
if (result.description) {
text += '\n\n';
if (typeof result.description === 'string') {
text += result.description;
} else {
text += `${result.description.text}${(result.description.extra || [])
.map((m) => m?.text || '')
.join('')}`;
}
}
return text;
}
@InjectLogger()
private logger: Logger;
@UseCommand('mcinfo', '查询 Minecraft 服务器信息。')
@CommandUsage('查询指定的 Minecraft 服务器信息。')
@CommandExample('mcinfo -h 2b2t.org')
@CommandExample('mcinfo -h 2b2t.org -p 25565')
async onQueryServer(
@PutOption('host', '-h <host:string> 服务器地址') host: string,
@PutOption('port', '-p <port:posint> 服务器端口,默认 25565') port: number,
) {
if (!host) {
return '请指定服务器地址。';
}
if (!port && host.includes(':')) {
const splited = host.split(':');
host = splited[0];
port = parseInt(splited[1], 10) || 25565;
}
const hostString = port ? `${host}:${port}` : host;
try {
const result = (await ping({ host, port })) as NewPingResult;
return `${hostString}\n${this.getServerText(result)}`;
} catch (e) {
this.logger.error(
`Failed to query Minecraft server ${hostString}: ${e.message}`,
);
return `连接服务器 ${hostString} 失败,请检查服务器地址是否正确。`;
}
}
}
{
"compilerOptions": {
"outDir": "dist",
"module": "commonjs",
"target": "es2021",
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": true,
"sourceMap": true,
"skipLibCheck": true
},
"compileOnSave": true,
"allowJs": true,
"include": [
"*.ts",
"src/**/*.ts"
]
}
const path = require('path');
const packgeInfo = require('./package.json');
function externalsFromDep() {
return Object.fromEntries(
[
...Object.keys(packgeInfo.dependencies || {}),
...Object.keys(packgeInfo.peerDependencies || {}),
]
.filter((dep) => dep !== 'source-map-support')
.map((dep) => [dep, dep]),
);
}
const packAll = !!process.env.PACK_ALL;
module.exports = {
entry: './src/index.ts',
mode: 'production',
target: 'node',
devtool: 'source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{ test: /\.mustache$/, use: 'raw-loader' },
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'index.js',
library: {
type: 'commonjs',
},
path: path.resolve(__dirname, packAll ? 'dist/full' : 'dist'),
},
externals: {
koishi: 'koishi',
...(packAll ? {} : externalsFromDep()),
},
};
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