Commit 3e5aa3a7 authored by nanahira's avatar nanahira

first

parent 630873b9
# 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/shadowban
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:
- tags
/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-shadowban # koishi-plugin-shadowban
Twitter Shadowban 测试器的 Koishi 插件 Twitter Shadowban 测试器的 Koishi 插件。
\ No newline at end of file
## 安装
### npm
```bash
npm install koishi-plugin-shadowban
```
### 直接安装
在 https://cdn02.moecube.com:444/nanahira/koishi-plugin/shadowban/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-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-beta.4"
},
"dependencies": {
"koishi-thirdeye": "^4.2.3",
"source-map-support": "^0.5.21"
},
"devDependencies": {
"@types/node": "^16.11.11",
"@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.4",
"prettier": "^2.5.1",
"raw-loader": "^4.0.2",
"ts-loader": "^9.2.6",
"typescript": "^4.5.2",
"webpack": "^5.64.4",
"webpack-cli": "^4.9.1",
"ws": "^8.3.0"
}
}
import 'source-map-support/register';
import { DefineSchema, RegisterSchema } from 'koishi-thirdeye';
@RegisterSchema()
export class ShadowbanPluginConfig {
@DefineSchema({
description: 'Shadowban API 地址。',
default: 'https://sbapi.lv5.ac:444',
})
endpoint: string;
getUrlForUsername(username: string) {
return `${this.endpoint}/${username}`;
}
}
export type ShadowbanPluginConfigLike = Partial<ShadowbanPluginConfig>;
import 'source-map-support/register';
import { Context, Logger, Quester, Session } from 'koishi';
import { ShadowbanPluginConfig, ShadowbanPluginConfigLike } from './config';
import {
KoishiPlugin,
InjectConfig,
UseCommand,
PutArg,
CommandUsage,
CommandExample,
Inject,
PutSession,
InjectLogger,
} from 'koishi-thirdeye';
export * from './config';
declare module 'koishi' {
interface Modules {
shadowban: typeof import('.');
}
}
interface ShadowbanResult {
profile: Profile;
tests: Tests;
}
interface Tests {
ghost: Ghost;
more_replies: Morereplies;
search: string | false;
typeahead: boolean;
}
interface Morereplies {
ban: boolean;
in_reply_to: string;
tweet: string;
}
interface Ghost {
ban: boolean;
}
interface Profile {
exists: boolean;
protected: boolean;
screen_name: string;
has_tweets: boolean;
suspended?: boolean;
}
@KoishiPlugin({ name: 'shadowban', schema: ShadowbanPluginConfig })
export default class ShadowbanPlugin {
constructor(private ctx: Context, config: ShadowbanPluginConfigLike) {}
@InjectConfig()
private config: ShadowbanPluginConfig;
@Inject('http', true)
private http: Quester;
@InjectLogger()
private logger: Logger;
private addLine<T>(
obj: T,
goodChecker: (o: T) => boolean,
goodMessage: string,
badMessage: string,
failMessage: string,
): string {
if (obj == null) {
return '\n[x] ' + failMessage;
}
const good = goodChecker(obj);
if (good) {
return `\n[+] ${goodMessage}`;
} else {
return `\n[-] ${badMessage}`;
}
}
@UseCommand('shadowban <username:string>', '测试 Twitter 帐号状态')
@CommandUsage('测试需要一定的时间,请耐心等待。')
@CommandExample('shadowban Nana_Yumesaki 获取 @Nana_Yumesaki 的状态')
async testShadowban(
@PutArg(0) username: string,
@PutSession() session: Session,
) {
await session.send(`正在测试 @${username} 的状态...`);
let result: ShadowbanResult;
try {
result = await this.http.get<ShadowbanResult>(
this.config.getUrlForUsername(username),
);
} catch (e) {
this.logger.error(
`Failed to fetch profile for @${username}: ${e.toString()}`,
);
return `无法获取 @${username} 的状态,请稍后再试。`;
}
if (!result.profile?.exists) {
return `@${username} 不存在。`;
}
let output = `@${username} 的状态:`;
if (result.profile.protected) {
output += '\n* 该帐号已被设置为受保护。';
}
if (!result.profile.has_tweets) {
output += '\n* 该帐号没有发布过推文。';
}
if (result.profile.suspended) {
output += '\n* 该帐号已被封禁。';
}
if (!result.tests) {
return output;
}
output += '\n';
const tests = result.tests;
output += this.addLine(
tests.typeahead,
(t) => t,
'No search suggestion ban. (未被封禁搜索建议)',
'Search suggestion ban. (封禁搜索建议)',
'无法获取搜索建议封禁状态',
);
output += this.addLine(
tests.search,
(t) => !!t,
'No search ban. (未被封禁搜索)',
'Search ban. (封禁搜索)',
'无法获取搜索封禁状态',
);
output += this.addLine(
tests.ghost?.ban,
(t) => !t,
'No ghost ban. (未被封禁)',
'Ghost ban. (封禁)',
'无法获取封禁状态',
);
output += this.addLine(
tests.more_replies?.ban,
(t) => !t,
'No reply deboosting detected. (未被隐藏回复)',
'Reply deboosting detected. (隐藏回复)',
'无法获取隐藏回复状态',
);
return output;
}
}
{
"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