Skip to content

Commit

Permalink
feat(koishi): support , and _ as number delim, fix #1386
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 9, 2024
1 parent 809e6da commit be8bcb2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/command/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ export class Commander {
this.domain('boolean', () => true)

this.domain('number', (source, session) => {
const value = +source
// support `,` and `_` as delimiters
// https://github.com/koishijs/koishi/issues/1386
const value = +source.replace(/[,_]/g, '')
if (Number.isFinite(value)) return value
throw new Error('internal.invalid-number')
}, { numeric: true })
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ declare module './context' {
}

namespace Context {
// https://github.com/typescript-eslint/typescript-eslint/issues/6720
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Database<C extends Context = Context> {
getUser<K extends FlatKeys<User>>(platform: string, pid: string, modifier?: Driver.Cursor<K>): Promise<FlatPick<User, K>>
setUser(platform: string, pid: string, data: Update<User>): Promise<void>
createUser(platform: string, pid: string, data: Partial<User>): Promise<User>
getChannel<K extends FlatKeys<Channel>>(platform: string, id: MaybeArray<string>, modifier?: Driver.Cursor<K>): Promise<FlatPick<Channel, K> | FlatPick<Channel, K>[]>
getChannel<K extends FlatKeys<Channel>>(platform: string, id: string, modifier?: Driver.Cursor<K>): Promise<FlatPick<Channel, K | 'id' | 'platform'>>
getChannel<K extends FlatKeys<Channel>>(platform: string, ids: string[], modifier?: Driver.Cursor<K>): Promise<FlatPick<Channel, K>[]>
getAssignedChannels<K extends Channel.Field>(fields?: K[], selfIdMap?: Dict<string[]>): Promise<Pick<Channel, K>[]>
setChannel(platform: string, id: string, data: Update<Channel>): Promise<void>
createChannel(platform: string, id: string, data: Partial<Channel>): Promise<Channel>
Expand Down Expand Up @@ -89,8 +92,6 @@ export class KoishiDatabase {
constructor(public ctx: Context) {
ctx.plugin(minato.Database)

ctx.set('koishi.database', this)

ctx.mixin('koishi.database', {
getUser: 'database.getUser',
setUser: 'database.setUser',
Expand Down

0 comments on commit be8bcb2

Please sign in to comment.