Fix for awaitMessages, Util

This commit is contained in:
Dragon Fire
2024-03-19 23:50:10 -04:00
parent cec26b124e
commit e93556e87b
6 changed files with 15 additions and 10 deletions
+4 -4
View File
@@ -2,9 +2,9 @@
const util = require('util'); const util = require('util');
/* eslint-disable no-unused-vars, prefer-destructuring */ /* eslint-disable no-unused-vars, prefer-destructuring */
const discord = require('discord.js'); const discord = require('discord.js');
const Util = require('../../util/Util');
/* eslint-enable no-unused-vars, prefer-destructuring */ /* eslint-enable no-unused-vars, prefer-destructuring */
const tags = require('common-tags'); const tags = require('common-tags');
const { escapeRegex, splitMessage } = require('../../util/Util');
const Command = require('../../framework/Command'); const Command = require('../../framework/Command');
const nl = '!!NL!!'; const nl = '!!NL!!';
@@ -90,14 +90,14 @@ module.exports = class EvalCommand extends Command {
const prepend = `\`\`\`javascript\n${prependPart}\n`; const prepend = `\`\`\`javascript\n${prependPart}\n`;
const append = `\n${appendPart}\n\`\`\``; const append = `\n${appendPart}\n\`\`\``;
if (input) { if (input) {
return splitMessage(tags.stripIndents` return Util.splitMessage(tags.stripIndents`
*Executed in ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.* *Executed in ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.*
\`\`\`javascript \`\`\`javascript
${inspected} ${inspected}
\`\`\` \`\`\`
`, { maxLength: 1900, prepend, append }); `, { maxLength: 1900, prepend, append });
} else { } else {
return splitMessage(tags.stripIndents` return Util.splitMessage(tags.stripIndents`
*Callback executed after ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.* *Callback executed after ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.*
\`\`\`javascript \`\`\`javascript
${inspected} ${inspected}
@@ -109,7 +109,7 @@ module.exports = class EvalCommand extends Command {
get sensitivePattern() { get sensitivePattern() {
if (!this._sensitivePattern) { if (!this._sensitivePattern) {
let pattern = ''; let pattern = '';
if (this.client.token) pattern += escapeRegex(this.client.token); if (this.client.token) pattern += Util.escapeRegex(this.client.token);
Object.defineProperty(this, '_sensitivePattern', { value: new RegExp(pattern, 'gi'), configurable: false }); Object.defineProperty(this, '_sensitivePattern', { value: new RegExp(pattern, 'gi'), configurable: false });
} }
return this._sensitivePattern; return this._sensitivePattern;
+2 -1
View File
@@ -46,7 +46,8 @@ module.exports = class Battler {
} }
return false; return false;
}; };
const turn = await msg.channel.awaitMessages(filter, { const turn = await msg.channel.awaitMessages({
filter,
max: 1, max: 1,
time: 30000 time: 30000
}); });
+2 -1
View File
@@ -71,7 +71,8 @@ module.exports = class Game {
reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅'); reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅');
return true; return true;
}; };
const votes = await this.channel.awaitMessages(filter, { const votes = await this.channel.awaitMessages({
filter,
max: this.players.size, max: this.players.size,
time: 90000 time: 90000
}); });
+2 -1
View File
@@ -23,7 +23,8 @@ module.exports = class Player {
${valid.map((p, i) => `**${i + 1}.** ${p.user.tag}`).join('\n')} ${valid.map((p, i) => `**${i + 1}.** ${p.user.tag}`).join('\n')}
`); `);
const filter = res => valid[Number.parseInt(res.content, 10) - 1]; const filter = res => valid[Number.parseInt(res.content, 10) - 1];
const decision = await this.user.dmChannel.awaitMessages(filter, { const decision = await this.user.dmChannel.awaitMessages({
filter,
max: 1, max: 1,
time: 120000 time: 120000
}); });
+2 -1
View File
@@ -84,7 +84,8 @@ module.exports = class PhoneCall {
const voicemailValidation = await verify(this.origin, null); const voicemailValidation = await verify(this.origin, null);
if (voicemailValidation) { if (voicemailValidation) {
await this.origin.send('☎️ Please leave your message (max 280 characters) after the beep. _Beep_.'); await this.origin.send('☎️ Please leave your message (max 280 characters) after the beep. _Beep_.');
const voicemail = await this.origin.awaitMessages(res => res.content && res.content.length <= 280, { const voicemail = await this.origin.awaitMessages({
filter: res => res.content && res.content.length <= 280,
time: 30000, time: 30000,
max: 1 max: 1
}); });
+3 -2
View File
@@ -302,7 +302,8 @@ module.exports = class Util {
return (user ? res.author.id === user.id : true) return (user ? res.author.id === user.id : true)
&& (yes.includes(value) || no.includes(value) || extraYes.includes(value) || extraNo.includes(value)); && (yes.includes(value) || no.includes(value) || extraYes.includes(value) || extraNo.includes(value));
}; };
const verify = await channel.awaitMessages(filter, { const verify = await channel.awaitMessages({
filter,
max: 1, max: 1,
time time
}); });
@@ -325,7 +326,7 @@ module.exports = class Util {
if (!num) return false; if (!num) return false;
return num > 0 && num <= arr.length; return num > 0 && num <= arr.length;
}; };
const msgs = await msg.channel.awaitMessages(filter, { max: 1, time }); const msgs = await msg.channel.awaitMessages({ filter, max: 1, time });
if (!msgs.size) return defalt; if (!msgs.size) return defalt;
return arr[Number.parseInt(msgs.first().content, 10) - 1]; return arr[Number.parseInt(msgs.first().content, 10) - 1];
} }