From 830458d5d217c2bb52b96ef7621d24396c87a401 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Tue, 26 Jul 2022 22:57:58 +0800 Subject: [PATCH] add support for DMs --- src/constants.ts | 2 ++ src/index.ts | 33 ++++++++++++++++++++++----------- src/logs.ts | 2 +- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index e3fe6c0..31de9aa 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,6 +2,8 @@ export const GUILD_ID = '923671181020766230'; export const DEBUG_CHANNEL_ID = '977401259260788756'; export const POLYCAT_CHANNEL_ID = '977797790749032448'; +export const DM_TESTERS = ['952235800110694471']; + export const ETA_REGEX = /\beta\b/i; export const ETA_MESSAGES = [ 'Sometime', diff --git a/src/index.ts b/src/index.ts index fd5ff87..7d1b06f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,12 @@ -import { Client, Message, EmbedBuilder, type EmbedData } from 'discord.js'; +import { + Client, + Message, + EmbedBuilder, + type EmbedData, + GatewayIntentBits, + Partials, + ChannelType, +} from 'discord.js'; import * as BuildConfig from './constants'; import { commands } from './commands'; @@ -51,15 +59,16 @@ export const getTags = async (): Promise => { const client = new Client({ intents: [ - 'Guilds', - 'GuildMessages', - 'MessageContent', - 'DirectMessages', - 'GuildMembers', - 'GuildPresences', - 'GuildMessageReactions', - 'GuildBans', + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildMessages, + GatewayIntentBits.MessageContent, + GatewayIntentBits.DirectMessages, + GatewayIntentBits.GuildMembers, + GatewayIntentBits.GuildPresences, + GatewayIntentBits.GuildMessageReactions, + GatewayIntentBits.GuildBans, ], + partials: [Partials.Channel], }); client.once('ready', async () => { @@ -80,7 +89,9 @@ client.once('ready', async () => { if ( process.env.NODE_ENV === 'development' && - e.channelId !== BuildConfig.DEBUG_CHANNEL_ID + e.channelId !== BuildConfig.DEBUG_CHANNEL_ID && + e.channel.type === ChannelType.DM && + !BuildConfig.DM_TESTERS.includes(e.author.id) ) { return; } else if ( @@ -152,7 +163,7 @@ async function parseMsgForTags(e: Message) { ); if (tag) { - const requesterAvatarURL = e.author.avatar; + const requesterAvatarURL = e.author.avatarURL(); const tagRequester = { text: `Requested by ${e.author.tag}`, ...(requesterAvatarURL ? { icon_url: requesterAvatarURL } : null), diff --git a/src/logs.ts b/src/logs.ts index e0ac83d..21f0311 100644 --- a/src/logs.ts +++ b/src/logs.ts @@ -230,7 +230,7 @@ export async function parseLog(s: string): Promise { const embed = new EmbedBuilder() .setTitle('pastebin.com detected') .setDescription( - 'Please use https://mclo.gs or another paste provider and send logs using the Log Upload feature in PolyMC. (See !log)' + 'Please use https://mclo.gs or another paste provider and send logs using the Log Upload feature in PolyMC. (See ?log)' ) .setColor(COLORS.red); return embed;