diff options
Diffstat (limited to 'src/api/routes/guilds/#guild_id/prune.ts')
-rw-r--r-- | src/api/routes/guilds/#guild_id/prune.ts | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/src/api/routes/guilds/#guild_id/prune.ts b/src/api/routes/guilds/#guild_id/prune.ts index 2c77340d..7fa31ed2 100644 --- a/src/api/routes/guilds/#guild_id/prune.ts +++ b/src/api/routes/guilds/#guild_id/prune.ts @@ -23,12 +23,7 @@ import { IsNull, LessThan } from "typeorm"; const router = Router(); //Returns all inactive members, respecting role hierarchy -const inactiveMembers = async ( - guild_id: string, - user_id: string, - days: number, - roles: string[] = [], -) => { +const inactiveMembers = async (guild_id: string, user_id: string, days: number, roles: string[] = []) => { const date = new Date(); date.setDate(date.getDate() - days); //Snowflake should have `generateFromTime` method? Or similar? @@ -55,9 +50,7 @@ const inactiveMembers = async ( //I'm sure I can do this in the above db query ( and it would probably be better to do so ), but oh well. if (roles.length && members.length) - members = members.filter((user) => - user.roles?.some((role) => roles.includes(role.id)), - ); + members = members.filter((user) => user.roles?.some((role) => roles.includes(role.id))); const me = await Member.findOneOrFail({ where: { id: user_id, guild_id }, @@ -73,8 +66,8 @@ const inactiveMembers = async ( member.roles?.some( (role) => role.position < myHighestRole || //roles higher than me can't be kicked - me.id === guild.owner_id, //owner can kick anyone - ), + me.id === guild.owner_id //owner can kick anyone + ) ); return members; @@ -95,15 +88,10 @@ router.get( let roles = req.query.include_roles; if (typeof roles === "string") roles = [roles]; //express will return array otherwise - const members = await inactiveMembers( - req.params.guild_id, - req.user_id, - days, - roles as string[], - ); + const members = await inactiveMembers(req.params.guild_id, req.user_id, days, roles as string[]); res.send({ pruned: members.length }); - }, + } ); router.post( @@ -127,19 +115,12 @@ router.post( if (typeof roles === "string") roles = [roles]; const { guild_id } = req.params; - const members = await inactiveMembers( - guild_id, - req.user_id, - days, - roles as string[], - ); + const members = await inactiveMembers(guild_id, req.user_id, days, roles as string[]); - await Promise.all( - members.map((x) => Member.removeFromGuild(x.id, guild_id)), - ); + await Promise.all(members.map((x) => Member.removeFromGuild(x.id, guild_id))); res.send({ purged: members.length }); - }, + } ); export default router; |