-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
454 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,6 @@ lib | |
*.tgz | ||
tsconfig.tsbuildinfo | ||
pnpm-lock.yaml | ||
kotori.dev.yml | ||
kotori.dev.yml | ||
|
||
scripts/*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ adapter: | |
|
||
plugin: | ||
console: | ||
test: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "@kotori-bot/core", | ||
"version": "1.0.0", | ||
"description": "Kotori Core", | ||
"main": "lib/index.js", | ||
"license": "GPL-3.0", | ||
"author": "Hotaru <biyuehuya@gmail.com>", | ||
"keywords": [ | ||
"chatbot", | ||
"bot", | ||
"kotori" | ||
], | ||
"files": [ | ||
"lib" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/kotorijs/kotori/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/kotorijs/kotori.git" | ||
}, | ||
"homepage": "https://kotori.js.org", | ||
"dependencies": { | ||
"@kotori-bot/i18n": "workspace:^", | ||
"@kotori-bot/logger": "workspace:^", | ||
"@kotori-bot/tools": "workspace:^", | ||
"tsukiko": "^1.2.1" | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { loadConfig, obj } from '@kotori-bot/tools'; | ||
import path from 'path'; | ||
import { Parser } from 'tsukiko'; | ||
import { | ||
type AdapterConstructor, | ||
type BaseDir, | ||
type GlobalConfig, | ||
type GlobalOptions, | ||
type KotoriConfig, | ||
type PackageInfo, | ||
packageInfoSchema, | ||
kotoriConfigSchema, | ||
} from '../types'; | ||
import type Api from '../components/api'; | ||
import { CoreError } from '../utils/errror'; | ||
import { DEFAULT_COMMAND_PREFIX, DEFAULT_ENV, DEFAULT_LANG, DEFAULT_MODULES_DIR, DEFAULT_ROOT_DIR } from '../consts'; | ||
|
||
export const defaultConfig = { | ||
baseDir: { | ||
root: path.resolve(DEFAULT_ROOT_DIR), | ||
modules: path.resolve(DEFAULT_MODULES_DIR), | ||
}, | ||
config: { | ||
global: { | ||
lang: DEFAULT_LANG, | ||
'command-prefix': DEFAULT_COMMAND_PREFIX, | ||
}, | ||
adapter: {}, | ||
}, | ||
options: { | ||
env: DEFAULT_ENV, | ||
}, | ||
}; | ||
|
||
export class Core { | ||
protected readonly adapterStack: obj<[AdapterConstructor, Parser<unknown>?]> = {}; | ||
|
||
protected readonly botStack: obj<Api[]> = {}; | ||
|
||
public readonly baseDir: BaseDir; | ||
|
||
public readonly config: GlobalConfig; | ||
|
||
public readonly options: GlobalOptions; | ||
|
||
public readonly package: PackageInfo; | ||
|
||
public constructor(config?: KotoriConfig) { | ||
const info = loadConfig(path.join(__dirname, '../../package.json')) as unknown; | ||
if (!info || Object.values(info).length === 0) throw new CoreError('Cannot find kotori-bot package.json'); | ||
const result = packageInfoSchema.parseSafe(info); | ||
if (!result.value) throw new CoreError(`File package.json format error: ${result.error.message}`); | ||
this.package = result.data; | ||
const handle = kotoriConfigSchema.parseSafe(config); | ||
if (!handle.value) throw new CoreError('Unexpected error in parsing config (basedir,kotori,options)'); | ||
this.baseDir = handle.data!.baseDir; | ||
this.config = handle.data!.config; | ||
this.options = handle.data!.options; | ||
} | ||
} | ||
|
||
export default Core; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Logger from '@kotori-bot/logger'; | ||
import { Http } from '@kotori-bot/tools'; | ||
import Locale from './utils/i18n'; | ||
import Internal from './base/internal'; | ||
import { KotoriConfig } from './types'; | ||
|
||
export class Context extends Internal { | ||
public http = new Http({ validateStatus: () => true }); | ||
|
||
public logger = Object.assign( | ||
Logger, | ||
new Proxy(Logger.debug, { | ||
apply: (target, _, argArray) => { | ||
if (this.options.env === 'dev') target(argArray); | ||
}, | ||
}), | ||
); | ||
|
||
public readonly i18n: Locale; | ||
|
||
private initialize() { | ||
this.registeMessageEvent(); | ||
this.midware((next, session) => { | ||
const { selfId } = session.api.adapter; | ||
if (session.userId !== selfId) next(); | ||
}, 50); | ||
} | ||
|
||
public constructor(Config?: KotoriConfig) { | ||
super(Config); | ||
this.i18n = new Locale(this.config.global.lang); | ||
this.initialize(); | ||
} | ||
} | ||
|
||
export default Context; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { none } from '@kotori-bot/tools'; | ||
import Context from './context'; | ||
|
||
export * from './components/adapter'; | ||
export * from './components/api'; | ||
export * from './components/elements'; | ||
export * from './context'; | ||
export * from './utils/errror'; | ||
export * from './consts'; | ||
export * from './types'; | ||
export * from '@kotori-bot/tools'; | ||
export * from 'tsukiko'; | ||
|
||
export class ContextInstance { | ||
protected constructor() { | ||
none(); | ||
} | ||
|
||
private static instance: Context = {} as Context; | ||
|
||
protected static setInstance(ctx: Context) { | ||
this.instance = ctx; | ||
} | ||
|
||
public static getInstance() { | ||
return this.instance; | ||
} | ||
|
||
public static getMixin() { | ||
return Object.assign(ContextInstance.getInstance() /* , Context */); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": "../../tsconfig.node.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"outDir": "./lib" | ||
}, | ||
"references": [ | ||
{ | ||
"path": "../i18n" | ||
}, | ||
{ | ||
"path": "../logger" | ||
}, | ||
{ | ||
"path": "../tools" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
require('../lib/cli'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import cac from 'cac'; | ||
import Loader from '@kotori-bot/loader'; | ||
import { readFileSync } from 'fs'; | ||
|
||
const program = cac(); | ||
|
||
const pkg = JSON.parse(readFileSync(`${__dirname}/../package.json`).toString()); | ||
|
||
program.version(pkg.verion); | ||
|
||
program | ||
.command('serve') | ||
.option('--mode [value]', 'Set running mode of program') | ||
.option('--dir [path]', 'Set running root dir of program') | ||
.action((...args) => { | ||
console.log(args); | ||
new Loader().run(); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.