Skip to content

Commit

Permalink
fixed active auto update
Browse files Browse the repository at this point in the history
  • Loading branch information
GhomKrosmonaute committed Oct 23, 2023
1 parent 158b53e commit f676d12
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/app/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export const orm = new ORM({
logger,
})

export * from "@ghom/orm"
export * from "@ghom/orm"
2 changes: 1 addition & 1 deletion src/commands/active.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default new app.Command({
if (await app.hasActivity(config._id, message.args.interval))
return await app.sendLog(
message.guild,
`Ignored automated active list hourly update, no activity in the last hour.`
`Ignored automated active list update, no activity detected in the last period.`
)

const found = await app.updateActive(message.guild, {
Expand Down
30 changes: 18 additions & 12 deletions src/namespaces/active.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,28 @@ export async function updateActive(
return activeMembers.length
}

/**
* @fixme
* @param guild_id
* @param period
*/
export async function hasActivity(
guild_id: number,
period: number
): Promise<boolean> {
return app.orm
.raw(
`select
count(*) > 0 as hasActivity
from message
where
guild_id = ${guild_id}
and
unixepoch(datetime(created_at, 'localtime')) >
unixepoch(datetime('now', '-${period} hours', 'localtime'))`
)
.then((result) => !!result[0]?.hasActivity)
return true
// return app.orm
// .raw(
// `select
// count(*) > 0 as hasActivity
// from message
// where
// guild_id = ${guild_id}
// and
// unixepoch(datetime(created_at, 'localtime')) >
// unixepoch(datetime('now', '-${period} hours', 'localtime'))`
// )
// .then((result) => !!result[0]?.hasActivity)
}

export interface ActiveLadderLine {
Expand Down

0 comments on commit f676d12

Please sign in to comment.