Commit ce2605e2 authored by nanahira's avatar nanahira

first

parent 56518c32
# 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/guild-verifier
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 Guild Verifier
# koishi-plugin-guild-verifier
Koishi 群组邀请审核插件
\ No newline at end of file
Koishi 群组邀请审核插件。
## 安装
### npm
```bash
npm install koishi-plugin-guild-verifier
```
### 直接安装
在 https://cdn02.moecube.com:444/nanahira/koishi-plugin/guild-verifier/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@next \
ws
This diff is collapsed.
{
"name": "koishi-plugin-guild-verifier",
"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-guild-verifier.git"
},
"author": "Nanahira <nanahira@momobako.com>",
"license": "MIT",
"keywords": [
"Koishi.js",
"qqbot",
"cqhttp",
"onebot"
],
"bugs": {
"url": "https://code.mycard.moe/3rdeye/koishi-plugin-guild-verifier/issues"
},
"homepage": "https://code.mycard.moe/3rdeye/koishi-plugin-guild-verifier",
"peerDependencies": {
"koishi": "^4.0.0-beta.4"
},
"dependencies": {
"koishi-thirdeye": "^5.0.4",
"source-map-support": "^0.5.21"
},
"devDependencies": {
"@types/node": "^17.0.0",
"@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-beta.5",
"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.3.0"
}
}
import 'source-map-support/register';
import { DefineSchema, RegisterSchema, SchemaProperty } from 'koishi-thirdeye';
@RegisterSchema()
export class GuildVerifierConfig {
constructor(config: GuildVerifierConfigLike) {}
@SchemaProperty({ type: String, description: '管理员 ID。', default: [] })
adminIds: string[];
isAdmin(id: string) {
return this.adminIds.includes(id);
}
@SchemaProperty({ description: '通知群组 ID。' })
notifyGuildId: string;
}
export type GuildVerifierConfigLike = Partial<GuildVerifierConfig>;
import 'source-map-support/register';
import { Bot, Context, Logger, Session } from 'koishi';
import { GuildVerifierConfig, GuildVerifierConfigLike } from './config';
import {
KoishiPlugin,
InjectConfig,
OnPlatform,
UseEvent,
OnPrivate,
UseCommand,
CommandUsage,
PutSession,
PutBot,
Put,
PutArg,
InjectLogger,
} from 'koishi-thirdeye';
export * from './config';
declare module 'koishi' {
interface Modules {
myplugin: typeof import('.');
}
}
@OnPlatform('onebot')
@KoishiPlugin({ name: 'myplugin', schema: GuildVerifierConfig })
export default class GuildVerifier {
constructor(private ctx: Context, config: GuildVerifierConfigLike) {}
@InjectConfig()
private config: GuildVerifierConfig;
@UseEvent('guild-request')
private async onGuildRequest(session: Session) {
if (session.userId && this.config.isAdmin(session.userId)) {
return session.bot.handleGuildRequest(session.messageId, true);
}
if (!this.config.notifyGuildId) {
return;
}
return session.bot.sendMessage(
this.config.notifyGuildId,
`${session.username || '未知用户'}(${session.userId}) 邀请我加入群 ${
session.guildName
}(${session.guildId}) 。\n请私聊发送我 verify.accept ${
session.messageId
} 同意。\n请私聊发送我 verify.reject ${session.messageId} 拒绝。`,
);
}
@OnPrivate()
@UseCommand('verify', '处理邀请入群请求', { empty: true })
verifyCommand() {}
@InjectLogger()
private logger: Logger;
async handleRequest(session: Session, messageId: string, accept: boolean) {
if (!this.config.isAdmin(session.userId)) {
return '你没有权限操作。';
}
try {
await session.bot.handleGuildRequest(messageId, accept);
} catch (e) {
this.logger.error(
`handleGuildRequest for $${messageId} failed: ${e.toString()}`,
);
return `操作失败:${e.toString()}`;
}
return `操作成功。`;
}
@OnPrivate()
@UseCommand('verify.accept <messageId:string>', '同意邀请入群请求')
@CommandUsage('需要具有处理权限。')
accept(@PutSession() session: Session, @PutArg(0) messageId: string) {
return this.handleRequest(session, messageId, true);
}
@OnPrivate()
@UseCommand('verify.reject <messageId:string>', '拒绝邀请入群请求')
@CommandUsage('需要具有处理权限。')
reject(@PutSession() session: Session, @PutArg(0) messageId: string) {
return this.handleRequest(session, messageId, false);
}
}
{
"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