Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
RMT improvements, bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HoeenCoder committed Oct 20, 2021
1 parent ceb73df commit dbf0f47
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/command_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/boosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 13 additions & 4 deletions src/monitors/rmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit dbf0f47

Please sign in to comment.