Skip to content

Commit

Permalink
fix(analytics): handle anonymous users, fix #269
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Dec 18, 2023
1 parent 4fe9615 commit 1060ecc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion plugins/analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@koishijs/plugin-analytics",
"description": "Show statistics for Koishi application",
"version": "2.0.1",
"version": "2.0.2",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down
6 changes: 2 additions & 4 deletions plugins/analytics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class Analytics extends DataService<Analytics.Payload> {
})

ctx.on('message', (session) => {
if (session.bot.hidden) return
this.addAudit(this.messages, {
...this.createIndex(session),
type: 'receive',
Expand All @@ -78,7 +77,6 @@ class Analytics extends DataService<Analytics.Payload> {
})

ctx.on('send', (session) => {
if (session.bot.hidden) return
this.addAudit(this.messages, {
...this.createIndex(session),
type: 'send',
Expand All @@ -87,11 +85,10 @@ class Analytics extends DataService<Analytics.Payload> {
})

ctx.any().before('command/execute', ({ command, session }) => {
if (session.bot.hidden) return
this.addAudit(this.commands, {
...this.createIndex(session),
name: command.name,
userId: session.user['id'],
userId: session.user['id'] || 0,
channelId: session.channelId,
})
this.upload()
Expand Down Expand Up @@ -171,6 +168,7 @@ class Analytics extends DataService<Analytics.Payload> {
const data = await this.ctx.database
.select('analytics.command', {
date: { $gte: Time.getDateNumber() - 7 },
userId: { $gt: 0 },
})
.groupBy(['date'], {
count: row => $.count(row.userId),
Expand Down
2 changes: 1 addition & 1 deletion plugins/status/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"devDependencies": {
"@koishijs/client": "^5.21.0",
"@koishijs/plugin-analytics": "^2.0.1",
"@koishijs/plugin-analytics": "^2.0.2",
"@types/envinfo": "^7.8.3",
"@types/throttle-debounce": "^2.1.0",
"koishi": "^4.16.1"
Expand Down

0 comments on commit 1060ecc

Please sign in to comment.