|
@@ -5,12 +5,38 @@ import { logger } from "src/logging";
|
|
|
import { GuildGreeting } from "@shared/db/entity/GuildGreeting";
|
|
|
import { client } from "src/client";
|
|
|
import { formatString } from "src/util";
|
|
|
+import { GuildVerification } from "@shared/db/entity/GuildVerification";
|
|
|
+import { tryDo } from "@shared/common/async_utils";
|
|
|
|
|
|
@Plugin
|
|
|
export class GreetPlugin {
|
|
|
@Event("guildMemberAdd")
|
|
|
async showGreetMessage(data: BotEventData, member: GuildMember | PartialGuildMember): Promise<void> {
|
|
|
- await this.displayGreet(member, g => g.onJoinMessage);
|
|
|
+ const greetInfo = await this.displayGreet(member, g => g.onJoinMessage);
|
|
|
+ if (!greetInfo || !greetInfo.onJoinPrivateMessage) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const verificationGuilds = getRepository(GuildVerification);
|
|
|
+ const guild = await verificationGuilds.findOne(member.guild.id);
|
|
|
+ if (!guild) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const dmResult = await tryDo(member.createDM());
|
|
|
+ if (!dmResult.ok) {
|
|
|
+ logger.warn("greet: failed to create DM with user %s#%s (%s): %s", member.user?.username, member.user?.discriminator, member.id, dmResult.error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const sendResult = await tryDo(dmResult.result.send(formatString(greetInfo.onJoinPrivateMessage, {
|
|
|
+ memberID: member.id,
|
|
|
+ memberTag: member.user?.tag ?? member.displayName,
|
|
|
+ guildName: member.guild.name
|
|
|
+ })));
|
|
|
+ if (!sendResult.ok) {
|
|
|
+ logger.warn("greet: failed to send DM greeting to %s#%s (%s): %s", member.user?.username, member.user?.discriminator, member.id, sendResult.error);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Event("guildMemberRemove")
|
|
@@ -21,7 +47,7 @@ export class GreetPlugin {
|
|
|
private async displayGreet(member: GuildMember | PartialGuildMember, select: (greeting: GuildGreeting) => string) {
|
|
|
const result = await this.getGreeting(member);
|
|
|
if (!result)
|
|
|
- return;
|
|
|
+ return undefined;
|
|
|
const { guildGreeting, greetingChannel } = result;
|
|
|
|
|
|
await greetingChannel.send(formatString(select(guildGreeting), {
|
|
@@ -29,6 +55,7 @@ export class GreetPlugin {
|
|
|
memberTag: member.user?.tag ?? member.displayName,
|
|
|
guildName: member.guild.name
|
|
|
}));
|
|
|
+ return guildGreeting;
|
|
|
}
|
|
|
|
|
|
private async getGreeting(member: GuildMember | PartialGuildMember) {
|