Commit f5165e01 authored by nanahira's avatar nanahira

base dice

parent 8174f8df
# 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/dicex
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 Dicex
# koishi-plugin-myplugin
Koishi 骰娘插件+1
\ No newline at end of file
Koishi 骰娘插件 +1
## 安装
### npm
```bash
npm install koishi-plugin-myplugin
```
### 直接安装
在 https://cdn02.moecube.com:444/nanahira/koishi-plugin/myplugin/index.js 下载即可。
## 配置
详见 `config.ts` 部分,或详见 Schema 描述配置。
#!/bin/bash
npm install --save \
source-map-support \
koishi-thirdeye
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 \
koishi@latest \
ws
This diff is collapsed.
{
"name": "koishi-plugin-myplugin",
"description": "一个 Koishi 插件",
"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-myplugin.git"
},
"author": "Nanahira <nanahira@momobako.com>",
"license": "MIT",
"keywords": [
"Koishi.js",
"qqbot",
"cqhttp",
"onebot"
],
"bugs": {
"url": "https://code.mycard.moe/3rdeye/koishi-plugin-myplugin/issues"
},
"homepage": "https://code.mycard.moe/3rdeye/koishi-plugin-myplugin",
"peerDependencies": {
"koishi": "^4.0.0-rc.0"
},
"dependencies": {
"koishi-thirdeye": "^6.0.2",
"source-map-support": "^0.5.21"
},
"devDependencies": {
"@types/node": "^17.0.4",
"@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",
"koishi": "^4.0.0-rc.0",
"prettier": "^2.5.1",
"raw-loader": "^4.0.2",
"ts-loader": "^9.2.6",
"typescript": "^4.5.4",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"ws": "^8.4.0"
}
}
import 'source-map-support/register';
import { DefineSchema, RegisterSchema, SchemaProperty } from 'koishi-thirdeye';
@RegisterSchema()
export class DicePluginConfig {
constructor(config: DicePluginConfigLike) {}
@SchemaProperty({ description: '掷骰的最大点数。', default: 1 << 16 })
maxPoint: number;
@SchemaProperty({ description: '单次调用中最大掷骰次数。', default: 64 })
maxTimes: number;
}
export type DicePluginConfigLike = Partial<DicePluginConfig>;
import 'source-map-support/register';
import { Context, NextFunction, Random, Session } from 'koishi';
import { DicePluginConfig, DicePluginConfigLike } from './config';
import {
KoishiPlugin,
InjectConfig,
UseCommand,
CommandShortcut,
CommandUserFields,
CommandExample,
PutSession,
PutArg,
UseMiddleware,
} from 'koishi-thirdeye';
export * from './config';
declare module 'koishi' {
interface Modules {
dicex: typeof import('.');
}
}
const regexp = /^((\d*)d)?(\d+)(\+((\d*)d)?(\d+))*$/i;
@KoishiPlugin({ name: 'dicex', schema: DicePluginConfig })
export default class DicePlugin {
constructor(private ctx: Context, config: DicePluginConfigLike) {}
@InjectConfig()
private config: DicePluginConfig;
@UseCommand('roll [expr:string]', '掷骰')
@CommandShortcut('掷骰', { fuzzy: true })
@CommandUserFields(['name', 'timers'])
@CommandExample('roll 2d6+d10')
onRoll(@PutSession() session: Session, @PutArg(0) message = '1d6') {
if (!regexp.test(message)) return '表达式语法错误。';
const { maxPoint = 1 << 16, maxTimes = 64 } = this.config;
const expressions = message.split('+');
let hasMultiple = false;
let output = `${session.username} 掷骰:${message}=`;
let total = 0;
for (const expr of expressions) {
const [, dice, _times, _max] = /^((\d*)d)?(\d+)$/i.exec(expr);
const max = +_max;
if (!max || max > maxPoint) {
return `点数必须在 1 到 ${maxPoint} 之间。`;
}
if (!dice) {
output += max + '+';
total += max;
continue;
}
const times = +(_times || 1);
if (!times || times > maxTimes) {
return `次数必须在 1 到 ${maxTimes} 之间。`;
}
const values = [];
for (let index = 0; index < times; index += 1) {
const value = Random.int(max) + 1;
values.push(value);
total += value;
}
if (times > 1) hasMultiple = true;
if (times > 1 && expressions.length > 1) {
output += '(';
}
output += values.join('+');
if (times > 1 && expressions.length > 1) {
output += ')';
}
output += '+';
}
output = output.slice(0, -1);
if (hasMultiple || expressions.length > 1) {
output += '=' + total;
}
return output;
}
@UseMiddleware()
onRollCompat(session: Session, next: NextFunction) {
const { content, prefix } = session.parsed;
if (!prefix || content[0] !== 'r') return next();
const expr = content.slice(1);
if (!regexp.test(expr)) return next();
return session.execute({ name: 'roll', args: [expr] });
}
}
{
"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