Skip to content

Commit

Permalink
fix(core): use $ prefix instead of _
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 4, 2020
1 parent 797bde2 commit f32a7e8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/koishi-core/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ export class Command {

// check authority and usage
const code = this._checkUser(meta, options)
this.context.logger('test').info(code)
if (code) return this._sendHint(code, meta)

// execute command
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-core/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface UserData {
id: number
flag: number
authority: number
usage: Record<string, Usage> & { _date?: number }
usage: Record<string, Usage> & { $date?: number }
}

export type User<K extends UserField = UserField> = Observed<Pick<UserData, K | 'id'>>
Expand Down
8 changes: 4 additions & 4 deletions packages/koishi-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ export function getTargetId (target: string | number) {
const ONE_DAY = 86400000

export function getUsage (name: string, user: Pick<UserData, 'usage'>, time = Date.now()) {
const _date = getDateNumber(time)
if (user.usage._date !== _date) {
const $date = getDateNumber(time)
if (user.usage.$date !== $date) {
const oldUsage = user.usage
const newUsage = { _date } as any
const newUsage = { $date } as any
for (const key in oldUsage) {
if (key === '_date') continue
if (key === '$date') continue
const { last } = oldUsage[key]
if (time.valueOf() - last < ONE_DAY) {
newUsage[key] = { last, count: 0 }
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-common/src/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ registerUserAction('clearUsage', async (meta, user, ...commands) => {

registerUserAction('showUsage', async (meta, user, ...commands) => {
const { usage } = user
if (!commands.length) commands = Object.keys(usage).filter(k => !k.startsWith('_'))
if (!commands.length) commands = Object.keys(usage).filter(k => !k.startsWith('$'))
if (!commands.length) return meta.$send('用户今日没有调用过指令。')
return meta.$send([
'用户今日各指令的调用次数为:',
Expand Down

0 comments on commit f32a7e8

Please sign in to comment.