heybox-bot
Version:
A heybox chat bot frame
193 lines • 7.74 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("node:fs"));
const node_process_1 = __importDefault(require("node:process"));
const rootDirectory = node_process_1.default.cwd();
const args = [];
args.push(...node_process_1.default.argv.slice(2));
const initPackageJson = {
name: 'bot-name',
version: '1.0.0',
description: '',
main: 'src/index.js',
types: 'src/index.d.ts',
scripts: {
dev: 'pnpx nodemon exec babel-node',
build: 'tsc --declaration'
},
author: 'author',
license: 'LGPL-3.0-or-later',
dependencies: {
'heybox-bot': '^1.2.44'
},
devDependencies: {
'@eslint/js': '^9.24.0',
'@types/nodemon': '^1.19.6',
'@types/ws': '^8.18.1',
eslint: '^9.24.0',
'eslint-config-prettier': '^9.1.0',
'eslint-plugin-prettier': '^5.2.6',
globals: '^15.15.0',
prettier: '^3.5.3',
'ts-node': '^10.9.2',
typescript: '^5.8.3',
'typescript-eslint': '^8.29.1'
}
};
const initTsConfigJson = {
compilerOptions: {
target: 'es2017',
module: 'commonjs',
strict: true,
esModuleInterop: true,
skipLibCheck: true,
baseUrl: './',
paths: {
'@/*': ['src/*']
}
},
include: ['src/**/*.ts'],
exclude: ['src/**/*.d.ts', 'src/**/*.js']
};
const initPrettierrcJs = '//此处的规则供参考,其中多半其实都是默认值,可以根据个人习惯改写\n' +
'module.exports = {\n' +
' tabWidth: 2, //缩进长度\n' +
' semi: true, //句末使用分号\n' +
' singleQuote: true, //使用单引号\n' +
' printWidth: 120, //单行长度\n' +
" trailingComma: 'none', //多行时尽可能打印尾随逗号\n" +
" quoteProps: 'preserve', //仅在必需时为对象的key添加引号\n" +
' bracketSameLine: true, //多属性html标签的‘>’折行放置\n' +
' jsxBracketSameLine: true, //多属性html标签的‘>’折行放置\n' +
" arrowParens: 'avoid', //单参数箭头函数参数周围使用圆括号-eg: (x) => x\n" +
" htmlWhitespaceSensitivity: 'ignore', //对HTML全局空白不敏感\n" +
' useTabs: false, //使用空格代替tab缩进\n' +
' jsxSingleQuote: true, // jsx中使用单引号\n' +
' bracketSpacing: true, //在对象前后添加空格-eg: { foo: bar }\n' +
' requirePragma: false, //无需顶部注释即可格式化\n' +
' insertPragma: false, //在已被preitter格式化的文件顶部加上标注\n' +
" proseWrap: 'preserve', //不知道怎么翻译\n" +
' vueIndentScriptAndStyle: false, //不对vue中的script及style标签缩进\n' +
" endOfLine: 'lf', //结束行形式\n" +
" embeddedLanguageFormatting: 'auto', //对引用代码进行格式化\n" +
'};';
const initEslintConfigMjs = "import globals from 'globals';\n" +
"import pluginJs from '@eslint/js';\n" +
"import tseslint from 'typescript-eslint';\n" +
"import configPrettier from 'eslint-config-prettier';\n" +
"import pluginPrettier from 'eslint-plugin-prettier/recommended';\n" +
'\n' +
'export default [\n' +
" { files: ['**/*.{js,mjs,cjs,ts,vue}'] },\n" +
' { languageOptions: { globals: globals.browser } },\n' +
' { languageOptions: { globals: { uni: true, wx: true } } },\n' +
' pluginJs.configs.recommended,\n' +
' ...tseslint.configs.recommended,\n' +
' pluginPrettier,\n' +
' configPrettier,\n' +
" { files: ['**/*.vue'], languageOptions: { parserOptions: { parser: tseslint.parser } } },\n" +
' {\n' +
' rules: {\n' +
" '@typescript-eslint/no-explicit-any': 'off'\n" +
' }\n' +
' },\n' +
' {\n' +
' ignores: [\n' +
" '.prettierrc.js',\n" +
" 'postcss.config.js',\n" +
" 'tailwind.config.js',\n" +
" 'shims-uni.d.ts',\n" +
" '**/shime-uni.d.ts',\n" +
" 'eslint.config.mjs'\n" +
' ]\n' +
' }\n' +
'];\n';
const initNodemonJson = {
watch: ['src'],
ext: '.ts',
exec: 'tsx src/index.ts'
};
const initIndexTs = "import { HeyBoxBot } from 'heybox-bot';\n" +
"import { CommandSource } from 'heybox-bot/dist/command';\n" +
"import { RawData } from 'ws';\n" +
'\n' +
"const bot: HeyBoxBot = new HeyBoxBot({ token:'your token' });\n" +
'\n' +
'new (class MyBot {\n' +
" @bot.command('/test')\n" +
' public test(source: CommandSource) {\n' +
" source.success('test');\n" +
' }\n' +
'\n' +
" @bot.subscribe('websocket-message')\n" +
' public onWebsocketMsg(bot: HeyBoxBot, msg: RawData) {\n' +
" console.log(msg.toString('utf-8'));\n" +
' }\n' +
'})()\n' +
'\n' +
'bot.start();\n';
if (args.findIndex(arg => arg === 'init'))
init();
function init() {
console.log('HeyBox Bot initializing...');
const sourcePath = `${rootDirectory}/src`;
if (!fs.existsSync(sourcePath))
fs.mkdirSync(sourcePath);
const packageJsonPath = `${rootDirectory}/package.json`;
if (!fs.existsSync(packageJsonPath))
fs.writeFileSync(packageJsonPath, JSON.stringify(initPackageJson, null, 2));
const tsconfigJsonPath = `${rootDirectory}/tsconfig.json`;
if (!fs.existsSync(tsconfigJsonPath))
fs.writeFileSync(tsconfigJsonPath, JSON.stringify(initTsConfigJson, null, 2));
const prettierrcJs = `${rootDirectory}/.prettierrc.js`;
if (!fs.existsSync(prettierrcJs))
fs.writeFileSync(prettierrcJs, initPrettierrcJs);
const eslintConfigMjs = `${rootDirectory}/eslint.config.mjs`;
if (!fs.existsSync(eslintConfigMjs))
fs.writeFileSync(eslintConfigMjs, initEslintConfigMjs);
const nodemonJson = `${rootDirectory}/nodemon.json`;
if (!fs.existsSync(nodemonJson))
fs.writeFileSync(nodemonJson, JSON.stringify(initNodemonJson, null, 2));
const indexTs = `${rootDirectory}/src/index.ts`;
if (!fs.existsSync(indexTs))
fs.writeFileSync(indexTs, initIndexTs);
console.log('HeyBox Bot initialized!');
}
//# sourceMappingURL=index.js.map