From dbf0f47327c84afb5d97c5c154ccc1f25e72f9f9 Mon Sep 17 00:00:00 2001 From: HoeenHero Date: Tue, 19 Oct 2021 21:08:53 -0400 Subject: [PATCH] RMT improvements, bug fixes --- src/client.ts | 4 ++-- src/command_base.ts | 4 ++-- src/commands/boosts.ts | 4 ++-- src/monitors/rmt.ts | 17 +++++++++++++---- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/client.ts b/src/client.ts index b8e1950..2982a7f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -61,7 +61,7 @@ export async function onError(err: Error | {} | null | undefined, detail = '') { if (Date.now() > lastErrorReport + (1000 * 60)) { try { const reportChannel = await client.channels.fetch(`${process.env.ERRCHANNEL}`); - if (reportChannel && ['text', 'news'].includes(reportChannel.type)) { + if (reportChannel && ['GUILD_TEXT', 'GUILD_NEWS'].includes(reportChannel.type)) { const stack = (err instanceof Error) ? err.stack : err; const msg = `${detail} ${stack}`.trim(); await (reportChannel as Discord.TextChannel).send(msg); @@ -119,7 +119,7 @@ export async function verifyData(data: Discord.Message | IDatabaseInsert) { } // Channel - if (data.guild && data.channel && ['text', 'news'].includes(data.channel.type) && !channels.has(data.channel.id)) { + if (data.guild && data.channel && ['GUILD_TEXT', 'GUILD_NEWS'].includes(data.channel.type) && !channels.has(data.channel.id)) { const channel = (data.channel as Discord.TextChannel | Discord.NewsChannel); const res = await database.queryWithResults('SELECT * FROM channels WHERE channelid = $1', [channel.id]); if (!res.length) { diff --git a/src/command_base.ts b/src/command_base.ts index 71c3e66..8929443 100644 --- a/src/command_base.ts +++ b/src/command_base.ts @@ -130,14 +130,14 @@ export abstract class BaseCommand { channelid = rawChannel.substring(2, rawChannel.length - 1); } else if (this.guild && allowName) { const targetChannel = this.guild.channels.cache - .find(channel => toID(channel.name) === toID(rawChannel) && ['news', 'text'].includes(channel.type)); + .find(channel => toID(channel.name) === toID(rawChannel) && ['GUILD_TEXT', 'GUILD_NEWS'].includes(channel.type)); if (targetChannel) channelid = targetChannel.id; } if (!channelid) channelid = rawChannel; const channel = (client.channels.cache.get(channelid) as DiscordChannel); // Validation for this type occurs below if (!channel) return; - if (!['text', 'news'].includes(channel.type)) return; + if (!['GUILD_TEXT', 'GUILD_NEWS'].includes(channel.type)) return; if (inServer) { if (!this.guild) return; if (channel.guild && channel.guild.id !== this.guild.id) return; diff --git a/src/commands/boosts.ts b/src/commands/boosts.ts index ad47cfb..0273da9 100644 --- a/src/commands/boosts.ts +++ b/src/commands/boosts.ts @@ -16,8 +16,8 @@ async function updateBoosters() { const res = await database.queryWithResults('SELECT userid FROM userlist WHERE serverid = $1 AND boosting IS NOT NULL', [guildId]); const boosting = res.map(r => r.userid); const logchannelResult = await database.queryWithResults('SELECT logchannel FROM servers WHERE serverid = $1', [guildId]); - const logChannel = (logchannelResult.length > 0 ? - client.channels.cache.get(logchannelResult[0].logchannel) : null) as DiscordChannel | null; + const logChannel = (logchannelResult.length > 0 + ? client.channels.cache.get(logchannelResult[0].logchannel) : null) as DiscordChannel | null; await guild.members.fetch(); for (const [id, gm] of guild.members.cache) { diff --git a/src/monitors/rmt.ts b/src/monitors/rmt.ts index b441c70..ec63c35 100644 --- a/src/monitors/rmt.ts +++ b/src/monitors/rmt.ts @@ -22,9 +22,8 @@ export class TeamRatingMonitor extends BaseMonitor { this.format = ''; this.teamPasteRegexp = /https:\/\/pokepast\.es\/[0-9a-z]{16}/; this.prefixRegexp = /^(?:SWSH|SS|USUM|SM|ORAS|XY|B2W2|BW2|BW|HGSS|DPP|DP|RSE|ADV|GSC|RBY)/i; - // TODO support ND as an alias of Natdex // eslint-disable-next-line max-len - this.formatRegexp = /\b((?:SWSH|SS|USUM|SM|ORAS|XY|B2W2|BW2|BW|HGSS|DPP|DP|RSE|ADV|GSC|RBY|Gen ?[1-8]\]?)? ?(?:(?:Nat|National) ?Dex|Doubles|D)? ?(?:[OURNPZ]U|AG|LC|VGC|OM|BS[SD]|(?:Over|Under|Rarely|Never|Zero)used|Ubers?|Monotype|Little ?Cup|Nat ?Dex|Anything ?Goes|Video ?Game ?Championships?|Battle ?(?:Spot|Stadium) ?(?:Singles?|Doubles?)|1v1|Other ?Meta(?:s|games?)?))\b/i; + this.formatRegexp = /\b((?:SWSH|SS|USUM|SM|ORAS|XY|B2W2|BW2|BW|HGSS|DPP|DP|RSE|ADV|GSC|RBY|Gen ?[1-8]\]?)? ?(?:(?:N|Nat|National)? ?(?:Dex|Doubles|D))? ?(?:[OURNPZ]U|AG|LC|VGC|OM|BS[SD]|(?:Over|Under|Rarely|Never|Zero)used|Ubers?|Monotype|Little ?Cup|Nat ?Dex|Anything ?Goes|Video ?Game ?Championships?|Battle ?(?:Spot|Stadium) ?(?:Singles?|Doubles?)|1v1|Other ?Meta(?:s|games?)?))\b/i; this.raters = []; } @@ -55,6 +54,10 @@ export class TeamRatingMonitor extends BaseMonitor { if (!formatid.startsWith('gen')) { formatid = `gen8${formatid}`; } + const ndOverride = /(gen(\d)(?:nationaldex|nd|natdex))/i.exec(formatid); + if (ndOverride?.length) { + formatid = formatid.replace(ndOverride[1], `gen${ndOverride[2]}natdex`); + } if (formatid === 'gen8natdexou') formatid = 'gen8natdex'; return formatid; } @@ -84,11 +87,17 @@ export class TeamRatingMonitor extends BaseMonitor { } } - if (!res.length) return false; + if (!res.length) { + void this.reply(`Team raters for ${this.format} would have been tagged, but none are online.`); + return false; + } this.raters = res.map(r => `<@${r.userid as string}>`); } const cooldown = cooldowns[this.channel.id]?.[this.format]; - if (cooldown && cooldown + (1000 * 60 * 60) >= Date.now()) return false; + if (cooldown && cooldown + (1000 * 60 * 60) >= Date.now()) { + void this.reply(`Team raters for ${this.format} would have been tagged, but this format was tagged too recently.`); + return false; + } if (!cooldowns[this.channel.id]) cooldowns[this.channel.id] = {}; cooldowns[this.channel.id][this.format] = Date.now(); return true;