misc fixes

This commit is contained in:
Erik 2022-07-28 10:46:43 +03:00
parent 79f09fe03c
commit 8db0c0d368
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
5 changed files with 18 additions and 11 deletions

View File

@ -94,15 +94,17 @@ class ApiClientUtil {
const { guildId } = message; const { guildId } = message;
const evalFunc = (client, { guildId }) => { const evalFunc = (client, { guildId }) => {
const guild = client.guilds.cache.get(guildId); try {
if (!guild) return null; const wrapper = client.getGuildWrapper(guildId);
const wrapper = new client.wrapperClasses.GuildWrapper(client, guild); return wrapper.toJSON();
return wrapper.toJSON(); } catch {
return null;
}
}; };
this.client.logger.debug(`guild-live request - shard: ${message.shard}, message id ${message.id}`); this.client.logger.debug(`guild-live request - shard: ${message.shard}, message id ${message.id}`);
const result = await this.client.shardingManager.broadcastEval(evalFunc, { context: { guildId } }); const result = await this.client.shardingManager.broadcastEval(evalFunc, { context: { guildId } });
const guild = result.find((elem) => elem !== undefined); const guild = result.find((elem) => elem !== null);
return guild; return guild;
} }

View File

@ -70,7 +70,7 @@ class Logger {
const maximumCharacters = Math.max(...Constants.Types.map((t) => t.length)); const maximumCharacters = Math.max(...Constants.Types.map((t) => t.length));
const spacers = maximumCharacters - type.length; const spacers = maximumCharacters - type.length;
const text = `${chalk[color](type)}${" ".repeat(spacers)} ${header} : ${string}`; const text = `${chalk[color](type)}${" ".repeat(spacers)} ${header}: ${string}`;
const strippedText = text.replace(stripRegex, ''); const strippedText = text.replace(stripRegex, '');
console.log(text); //eslint-disable-line no-console console.log(text); //eslint-disable-line no-console

View File

@ -3,6 +3,7 @@ const { Routes } = require('discord-api-types/v9');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const hash = require('object-hash'); const hash = require('object-hash');
const { inspect } = require('util');
class SlashCommandManager { class SlashCommandManager {
@ -43,7 +44,7 @@ class SlashCommandManager {
this.client.logger.write('info', `Commands hash: ${cmdHash}, ${guilds.length} out of date`); this.client.logger.write('info', `Commands hash: ${cmdHash}, ${guilds.length} out of date`);
if (!guilds.length) return; if (!guilds.length) return;
const promises = []; const promises = [];
//console.log(JSON.stringify(commands)); //fs.writeFileSync(path.join(process.cwd(), 'commands.json'), JSON.stringify(commands));
for(const guild of guilds) { for(const guild of guilds) {
promises.push(this.rest.put( promises.push(this.rest.put(
Routes.applicationGuildCommands(clientId, guild), Routes.applicationGuildCommands(clientId, guild),
@ -72,6 +73,10 @@ class SlashCommandManager {
str += `${command.name}: `; str += `${command.name}: `;
const options = Object.keys(invalid[key].options); const options = Object.keys(invalid[key].options);
for (const optKey of options) { for (const optKey of options) {
if (!command.options[optKey]) {
this.client.logger.warn(`Missing properties for ${command.name}: ${optKey}\nOptions: ${inspect(command.options)}`);
continue;
}
str += `${command.options[optKey].name}\t`; str += `${command.options[optKey].name}\t`;
} }
str += `\n\n`; str += `\n\n`;

View File

@ -37,7 +37,7 @@ class RateLimiter {
if (!channel || !(channel instanceof TextChannel)) reject(new Error('Missing channel')); if (!channel || !(channel instanceof TextChannel)) reject(new Error('Missing channel'));
if (!message || !(message instanceof Message)) reject(new Error('Missing message')); if (!message || !(message instanceof Message)) reject(new Error('Missing message'));
if (!channel.permissionsFor(channel.guild.members.me).has('ManageMessages')) reject(new Error('Missing permission ManageMessages')); if (!channel.permissionsFor(this.client.user).has('ManageMessages')) reject(new Error('Missing permission ManageMessages'));
if (!this.deleteQueue[channel.id]) this.deleteQueue[channel.id] = []; if (!this.deleteQueue[channel.id]) this.deleteQueue[channel.id] = [];
this.deleteQueue[channel.id].push({ message, resolve, reject }); this.deleteQueue[channel.id].push({ message, resolve, reject });
@ -106,7 +106,7 @@ class RateLimiter {
if (!channel || !(channel instanceof TextChannel)) reject(new Error('Missing channel.')); if (!channel || !(channel instanceof TextChannel)) reject(new Error('Missing channel.'));
if (!message || !message.length) reject(new Error('Missing message.')); if (!message || !message.length) reject(new Error('Missing message.'));
if (!channel.permissionsFor(channel.guild.members.me).has('SendMessages')) reject(new Error('Missing permission SendMessages')); if (!channel.permissionsFor(this.client.user).has('SendMessages')) reject(new Error('Missing permission SendMessages'));
//Initiate queue //Initiate queue
if (!this.sendQueue[channel.id]) this.sendQueue[channel.id] = []; if (!this.sendQueue[channel.id]) this.sendQueue[channel.id] = [];
@ -173,7 +173,7 @@ class RateLimiter {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!channel || !(channel instanceof TextChannel)) reject(new Error('Missing channel')); if (!channel || !(channel instanceof TextChannel)) reject(new Error('Missing channel'));
if (!channel.permissionsFor(channel.guild.members.me).has('SendMessages')) reject(new Error('Missing permission SendMessages')); if (!channel.permissionsFor(this.client.user).has('SendMessages')) reject(new Error('Missing permission SendMessages'));
if (!message) reject(new Error('Missing message')); if (!message) reject(new Error('Missing message'));
if (limit === null) limit = 15; if (limit === null) limit = 15;

View File

@ -217,7 +217,7 @@ class InteractionWrapper {
} }
isContextMenu() { isContextMenu() {
return this.interaction.isContextMenu(); return this.interaction.isContextMenuCommand();
} }
isSelectMenu() { isSelectMenu() {