-
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
186 changed files
with
952 additions
and
1,460 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Kotori, { CommandAccess } from 'kotori-bot'; | ||
import { join } from 'path'; | ||
|
||
/* 设置 i18n */ | ||
Kotori.i18n.use(join(__dirname, '../locales')); | ||
|
||
/* 事件监听 */ | ||
Kotori.on('group_decrease', (session) => { | ||
session.quick([ | ||
session.userId === session.operatorId ? '%target% 默默的退出了群聊' : '%target% 被 %target% 制裁了...', | ||
{ | ||
target: session.userId, | ||
operator: session.operatorId | ||
} | ||
]); | ||
}); | ||
|
||
/* 中间件注册 */ | ||
ctx.midware((next, session) => { | ||
if (session.message.startWith === '说' || session.message.includes('说')) { | ||
session.message = `${session.api.adapter.config['command-prefix']}echo`; | ||
} | ||
next(); | ||
}, 10); | ||
|
||
/* 指令注册 */ | ||
Kotori.command('echo <content> [num:number=3]') | ||
.action((data, session) => { | ||
Kotori.logger.debug(data, data.args[0]); | ||
Kotori.logger.debug(message); | ||
return [`返回消息:~%message%`, { message: data.args[0] }]; | ||
}) | ||
.alias('print') | ||
.scope(CommandAccess.GROUP); | ||
|
||
/* 正则注册 */ | ||
Kotori.regexp(/^(.*)#print$/, (match) => match[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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Context, CommandAccess, ModuleConfig, Tsu } from 'kotori-bot'; | ||
|
||
/* 设置 i18n */ | ||
export const lang = [__dirname, '../locales']; // or: const lang = path.join(__dirname, '../locales'); | ||
|
||
/* 自定义插件配置 */ | ||
export const kotoriConfigSchema = Tsu.Object({ | ||
config1: Tsu.Number().range(0, 10), | ||
config2: Tsu.Boolean(), | ||
config3: Tsu.Union([Tsu.Literal('on'), Tsu.Literal('off')]) | ||
}); | ||
export type Config = ModuleConfig & Tsu.infer<typeof kotoriConfigSchema>; | ||
|
||
/* 设置依赖服务 */ | ||
export const inject = ['database']; | ||
|
||
/* 插件入口 */ | ||
export function main(ctx: Context, config: Config) { | ||
/* 事件监听 */ | ||
ctx.on('group_decrease', (session) => { | ||
session.quick([ | ||
session.userId === session.operatorId ? '%target% 默默的退出了群聊' : '%target% 被 %target% 制裁了...', | ||
{ | ||
target: session.userId, | ||
operator: session.operatorId | ||
} | ||
]); | ||
}); | ||
|
||
/* 中间件注册 */ | ||
ctx.midware((next, session) => { | ||
if (session.message.startWith === '说' || session.message.includes('说')) { | ||
session.message = `${session.api.adapter.config['command-prefix']}echo`; | ||
} | ||
next(); | ||
}, 10); | ||
|
||
/* 指令注册 */ | ||
ctx | ||
.command('echo <content> [num:number=3]') | ||
.action((data, session) => { | ||
ctx.logger.debug(data, data.args[0]); | ||
ctx.logger.debug(message); | ||
return [`返回消息:~%message%`, { message: data.args[0] }]; | ||
}) | ||
.alias('print') | ||
.scope(CommandAccess.GROUP); | ||
|
||
/* 正则注册 */ | ||
ctx.regexp(/^(.*)#print$/, (match) => match[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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Context, CommandAccess, ModuleConfig, Tsu } from 'kotori-bot'; | ||
|
||
/* 设置 i18n */ | ||
export const lang = [__dirname, '../locales']; | ||
|
||
/* 自定义插件配置 */ | ||
export const kotoriConfigSchema = Tsu.Object({ | ||
config1: Tsu.Number().range(0, 10), | ||
config2: Tsu.Boolean(), | ||
config3: Tsu.Union([Tsu.Literal('on'), Tsu.Literal('off')]) | ||
}); | ||
export type Config = ModuleConfig & Tsu.infer<typeof kotoriConfigSchema>; | ||
|
||
/* 设置依赖服务 */ | ||
export const inject = ['database']; | ||
|
||
/* 插件入口 */ | ||
export class Main { | ||
private ctx: Context; | ||
|
||
private config: Config; | ||
|
||
constructor(Ctx: Context, Config: Config) { | ||
this.ctx = Ctx; | ||
this.config = Config; | ||
|
||
/* 事件监听 */ | ||
this.ctx.on('group_decrease', (session) => { | ||
session.quick([ | ||
session.userId === session.operatorId ? '%target% 默默的退出了群聊' : '%target% 被 %target% 制裁了...', | ||
{ | ||
target: session.userId, | ||
operator: session.operatorId | ||
} | ||
]); | ||
}); | ||
|
||
/* 中间件注册 */ | ||
this.ctx.midware((next, session) => { | ||
if (session.message.startWith === '说' || session.message.includes('说')) { | ||
session.message = `${session.api.adapter.config['command-prefix']}echo`; | ||
} | ||
next(); | ||
}, 10); | ||
|
||
/* 指令注册 */ | ||
this.ctx | ||
.command('echo <content> [num:number=3]') | ||
.action((data, session) => { | ||
ctx.logger.debug(data, data.args[0]); | ||
ctx.logger.debug(message); | ||
return [`返回消息:~%message%`, { message: data.args[0] }]; | ||
}) | ||
.alias('print') | ||
.scope(CommandAccess.GROUP); | ||
|
||
/* 正则注册 */ | ||
this.ctx.regexp(/^(.*)#print$/, (match) => match[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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { plugin, Tsu, ModuleConfig, EventsList, CommandAccess, CommandAction } from 'kotori-bot'; | ||
|
||
const test = plugin({ | ||
name: 'kotori-plugin-testing', | ||
kotori: { | ||
enforce: 'post', | ||
meta: { | ||
languages: ['en_US', 'ja_JP', 'zh_TW', 'zh_CN'] | ||
} | ||
} | ||
}); // or: const test = plugin(loadConfig(`${__dirname}/../package.json`)); | ||
|
||
const kotoriConfigSchema = Tsu.Object({ | ||
config1: Tsu.Number().range(0, 10), | ||
config2: Tsu.Boolean(), | ||
config3: Tsu.Union([Tsu.Literal('on'), Tsu.Literal('off')]) | ||
}); | ||
type Config = ModuleConfig & Tsu.infer<typeof kotoriConfigSchema>; | ||
|
||
/* 插件入口 */ | ||
@test.import({ | ||
lang: [__dirname, '../locales'], // 设置 i18n | ||
config: kotoriConfigSchema, // 自定义插件配置 | ||
inject: ['database'] // 设置全局的依赖服务 | ||
}) | ||
class Test { | ||
constructor(private Ctx: Context, private Config: Config) { }; | ||
|
||
/* 事件监听 */ | ||
@test.event({ type: 'group_decrease', inject: ['console'] /* 设置该方法特有的依赖服务 */ }); | ||
groupDecrease(session: EventsList['group_decrease']) { | ||
session.quick([ | ||
session.userId === session.operatorId ? '%target% 默默的退出了群聊' : '%target% 被 %target% 制裁了...', | ||
{ | ||
target: session.userId, | ||
operator: session.operatorId | ||
} | ||
]); | ||
} | ||
|
||
/* 中间件注册 */ | ||
@test.midware(/* {priority: 10} 设置*/) | ||
midware(next: () => void, session: EventsList['midwares']) { | ||
if (session.message.startWith === '说' || session.message.includes('说')) { | ||
session.message = `${session.api.adapter.config['command-prefix']}echo`; | ||
} | ||
next(); | ||
}; | ||
|
||
/* 指令注册 */ | ||
@test.command({ | ||
template: 'echo <content> [num:number=3]', | ||
scope: CommandAccess.GROUP | ||
/* 可在此处传入额外配置也可以链式 */ | ||
}).alias('print') | ||
echo(data: Parameters<CommandAction>[0], session: Parameters<CommandAction>[1]) { | ||
session.ctx.logger.debug(data, data.args[0]); | ||
session.ctx.logger.debug(session); | ||
return [`返回消息:~%message%`, { message: data.args[0] }]; | ||
} | ||
|
||
/* 正则注册 */ | ||
@test.regexp({ regexp: /^(.*)#print$/ }) | ||
print(match: RegExpExecArray) { | ||
return match[1]; | ||
}; | ||
} |
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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
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 |
---|---|---|
@@ -1,31 +1,40 @@ | ||
import { join } from 'path'; | ||
import { loadConfig } from '@kotori-bot/tools'; | ||
import { KotoriConfig as KotoriConfigType, PackageInfo, kotoriConfigSchema, packageInfoSchema } from '../types'; | ||
import { CoreConfig, PackageInfo, coreConfigSchema, packageInfoSchema } from '../types/index'; | ||
import { CoreError } from '../utils/errror'; | ||
|
||
type ConfigType = KotoriConfigType & { pkg: PackageInfo }; | ||
type ConfigType = CoreConfig & { pkg: PackageInfo }; | ||
|
||
export class KotoriConfig implements ConfigType { | ||
declare module '../context/index' { | ||
interface Context { | ||
readonly pkg: PackageInfo; | ||
readonly baseDir: CoreConfig['baseDir']; | ||
readonly config: CoreConfig['config']; | ||
readonly options: CoreConfig['options']; | ||
} | ||
} | ||
|
||
export class Config implements ConfigType { | ||
readonly pkg: PackageInfo; | ||
|
||
readonly baseDir: KotoriConfigType['baseDir']; | ||
readonly baseDir: CoreConfig['baseDir']; | ||
|
||
readonly config: KotoriConfigType['config']; | ||
readonly config: CoreConfig['config']; | ||
|
||
readonly options: KotoriConfigType['options']; | ||
readonly options: CoreConfig['options']; | ||
|
||
constructor(config?: KotoriConfigType) { | ||
constructor(config?: CoreConfig) { | ||
const info = loadConfig(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.pkg = result.data; | ||
const handle = kotoriConfigSchema.parseSafe(config); | ||
const handle = coreConfigSchema.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 KotoriConfig; | ||
export default Config; |
Oops, something went wrong.