From af7902e7dea4915613d0e6407edf65a51a6e7ff4 Mon Sep 17 00:00:00 2001 From: Dragory Date: Thu, 12 Jul 2018 03:02:47 +0300 Subject: [PATCH] Add guild member join logging --- src/plugins/Logs.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/plugins/Logs.ts b/src/plugins/Logs.ts index 3eb5857d..a57ab382 100644 --- a/src/plugins/Logs.ts +++ b/src/plugins/Logs.ts @@ -1,10 +1,11 @@ -import { Plugin } from "knub"; +import { decorators as d, Plugin } from "knub"; import { GuildServerLogs } from "../data/GuildServerLogs"; import { LogType } from "../data/LogType"; import { TextChannel } from "eris"; -import { formatTemplateString } from "../utils"; +import { formatTemplateString, stripObjectToScalars } from "../utils"; import DefaultLogMessages from "../data/DefaultLogMessages.json"; import moment from "moment-timezone"; +import humanizeDuration from "humanize-duration"; interface ILogChannel { include?: LogType[]; @@ -72,4 +73,19 @@ export class LogsPlugin extends Plugin { return formatted; } } + + @d.event("guildMemberAdd") + onMemberJoin(_, member) { + const newThreshold = moment().valueOf() - 1000 * 60 * 60; + const accountAge = humanizeDuration(moment().valueOf() - member.createdAt, { + largest: 2, + round: true + }); + + this.log(LogType.MEMBER_JOIN, { + member: stripObjectToScalars(member, ["user"]), + new: member.createdAt >= newThreshold ? " :new:" : "", + account_age: accountAge + }); + } }