-
-
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
1 parent
0a0d6fc
commit 6962409
Showing
7 changed files
with
102 additions
and
1 deletion.
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,51 @@ | ||
import * as app from "../app.js" | ||
|
||
let used = false | ||
|
||
export default new app.Command({ | ||
name: "active", | ||
description: "Update the active list", | ||
channelType: "guild", | ||
middlewares: [ | ||
app.staffOnly(), | ||
app.hasConfigKey("active_role_id"), | ||
app.isNotInUse(() => used), | ||
], | ||
async run(message) { | ||
used = true | ||
|
||
const waiting = await message.send( | ||
`${app.emote(message, "WAIT")} Fetching members...` | ||
) | ||
|
||
const config = await app.getConfig(message.guild, true) | ||
|
||
const members = (await message.guild.members.fetch()).filter( | ||
(member) => !member.user.bot | ||
) | ||
|
||
await waiting.edit( | ||
`${app.emote(message, "WAIT")} Looking for active members...` | ||
) | ||
|
||
for (const [, member] of members) { | ||
const isActive = await app.isActive(member) | ||
|
||
if (isActive) { | ||
if (!member.roles.cache.has(config.active_role_id!)) | ||
await member.roles.add(config.active_role_id!) | ||
} else if (member.roles.cache.has(config.active_role_id!)) { | ||
await member.roles.remove(config.active_role_id!) | ||
} | ||
} | ||
|
||
used = false | ||
|
||
return waiting.edit( | ||
`${app.emote( | ||
message, | ||
"CHECK" | ||
)} Successfully applied active role to active members.` | ||
) | ||
}, | ||
}) |
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
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,17 @@ | ||
import * as app from "../app.js" | ||
|
||
import active from "../tables/active.js" | ||
|
||
export async function isActive( | ||
member: app.GuildMember, | ||
period = 1000 * 60 * 60 * 24 * 7, | ||
messageCount = 50 | ||
): Promise<boolean> { | ||
const rowsInPeriod = await active.query | ||
.where("author_id", member.id) | ||
.where("guild_id", member.guild.id) | ||
.where("created_timestamp", ">", Date.now() - period) | ||
.count("*") | ||
|
||
return rowsInPeriod.length > messageCount | ||
} |
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,17 @@ | ||
import * as app from "../app.js" | ||
|
||
export interface Active { | ||
author_id: string | ||
guild_id: string | ||
created_timestamp: number | ||
} | ||
|
||
export default new app.Table<Active>({ | ||
name: "active", | ||
description: "Represent a message counter with date", | ||
setup: (table) => { | ||
table.string("author_id").notNullable() | ||
table.string("guild_id").notNullable() | ||
table.integer("created_timestamp", 15).notNullable().defaultTo(Date.now()) | ||
}, | ||
}) |
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