misc fixes

This commit is contained in:
Erik 2022-07-22 14:34:35 +03:00
parent ad720f5fdb
commit 0c5841111c
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
11 changed files with 49 additions and 50 deletions

View File

@ -1,4 +1,4 @@
const { Client, Collection, DataResolver } = require('discord.js');
const { Client, Collection, DataResolver, ActivityType } = require('discord.js');
const chalk = require('chalk');
const { inspect } = require('util');
@ -69,8 +69,6 @@ class DiscordClient extends Client {
this.emit('rateLimit', ...args);
});
this.ws.on('onmessage', (data) => console.log(data));
// this.once('ready', () => {
// this._setActivity();
@ -206,16 +204,16 @@ class DiscordClient extends Client {
const result = await this.shard.broadcastEval((client) => client.guilds.cache.size).catch(() => null);
if (!result) return;
const guildCount = result.reduce((p, v) => p+v, 0);
this.user.setActivity(`${guildCount} servers`, { type: 'WATCHING' });
this.user.setActivity(`${guildCount} servers`, { type: ActivityType.Watching });
},
1: async () => {
const result = await this.shard.broadcastEval((client) => client.users.cache.size).catch(() => null);
if (!result) return;
const userCount = result.reduce((p, v) => p+v, 0);
this.user.setActivity(`${userCount} users`, { type: 'LISTENING' });
this.user.setActivity(`${userCount} users`, { type: ActivityType.Listening });
},
2: async () => {
this.user.setActivity("for /help", { type: 'LISTENING' });
this.user.setActivity("for /help", { type: ActivityType.Listening });
}
};

View File

@ -1,10 +1,6 @@
const { EmbedBuilder } = require("discord.js");
const { EmbedBuilder, ChannelType } = require("discord.js");
const { SlashCommand } = require("../../../interfaces");
const Tiers = {
NONE: 0
};
class GuildCommand extends SlashCommand {
constructor(client) {
@ -38,13 +34,13 @@ class GuildCommand extends SlashCommand {
for (const channel of guild.channels.cache.values()) {
if (channel.type === 'GUILD_VOICE') vc++;
if (channel.type === 'GUILD_TEXT') tc++;
if (channel.type === 'GUILD_CATEGORY') cat++;
if (channel.type === 'GUILD_NEWS') news++;
if (channel.type === 'GUILD_NEWS_THREAD') newsThread++;
if (channel.type === 'GUILD_PUBLIC_THREAD') publicThread++;
if (channel.type === 'GUILD_PRIVATE_THREAD') privateThread++;
if (channel.type === ChannelType.GuildVoice) vc++;
if (channel.type === ChannelType.GuildText) tc++;
if (channel.type === ChannelType.GuildCategory) cat++;
if (channel.type === ChannelType.GuildNews) news++;
if (channel.type === ChannelType.GuildNewsThread) newsThread++;
if (channel.type === ChannelType.GuildPublicThread) publicThread++;
if (channel.type === ChannelType.GuildPrivateThread) privateThread++;
totalChannels++;
}
@ -91,7 +87,7 @@ class GuildCommand extends SlashCommand {
roleCount: guild.roles.cache.size,
emojiCount: guild.emojis.cache.filter((e) => !e.animated).size,
gifEmojiCount: guild.emojis.cache.filter((e) => e.animated).size,
emojiTotal: 50 + 50 * Tiers[guild.premiumTier]
emojiTotal: 50 + 50 * guild.premiumTier
}),
inline: true
}

View File

@ -1,5 +1,6 @@
const { Infraction } = require('../../interfaces/');
const { Collection } = require('@discordjs/collection');
const { MessageType } = require('discord.js');
const Arguments = ['users', 'bots', 'humans', 'contains', 'startswith', 'endswith', 'emojis', 'reactions', 'text', 'invites', 'links', 'emojis', 'reactions', 'images', 'attachments'];
@ -43,7 +44,7 @@ class PruneInfraction extends Infraction {
const hasOld = messages.some((m) => m.createdTimestamp >= Date.now() + 1209600000); //I hope Node.js can handle these large of numbers.. e_e (2 weeks)
const hasUndeletable = messages.some((m) => m.deletable);
messages = messages.filter((m) => m.deletable && m.type !== 'APPLICATION_COMMAND');
messages = messages.filter((m) => m.deletable && m.type !== MessageType.ChatInputCommand);
if (messages.size === 0) return this._fail('C_PRUNE_NOTDELETABLE');
const filtered = await this.filterMessages(messages);

View File

@ -1,4 +1,4 @@
const { EmbedBuilder, Message, ChannelType, ComponentType } = require('discord.js');
const { EmbedBuilder, Message, ChannelType, ComponentType, ButtonStyle } = require('discord.js');
const { Util } = require('../../../utilities');
const { InvokerWrapper, MessageWrapper } = require('../../client/wrappers');
const { Observer, CommandError } = require('../../interfaces/');
@ -482,7 +482,7 @@ class CommandHandler extends Observer {
{
label: 'Support',
type: ComponentType.Button,
style: 'LINK',
style: ButtonStyle.Link,
url: this.client._options.discord.invite
}
]

View File

@ -124,7 +124,7 @@ class MessageLog extends Setting {
if (!values.length) return { error: true, index: 'RESOLVE_FAIL', params: { type: list === 'bypass' ? 'roles' : 'channels' } };
const { modified } = this[method](setting[list], values.map((o) => o.id));
if(modified.length) {
index = `SETTING_SUCCESS_${list.toUpperCase()}`;
index = `SETTING_SUCCESS_${method.toUpperCase()}`;
langParams.updated = list;
langParams.modified = modified.map((o) => o.name).join('__, __');
}

View File

@ -116,7 +116,10 @@ class InviteFilterSetting extends FilterSetting {
return { id: word };
}); // TODO Figure out guild ID validation here
if (!params.length && ![silent, enabled].some((o) => o !== undefined)) return { error: true, index: 'RESOLVE_FAIL', params: { type: list === 'bypass' ? 'roles' : 'channels' } };
if (!params.length && ![silent, enabled].some((o) => o !== undefined))
// eslint-disable-next-line no-nested-ternary
return { error: true, index: 'RESOLVE_FAIL', params: { type: ['bypass', 'ignore'].includes(list) ? list === 'bypass' ? 'roles' : 'channels' : 'guilds' } };
const { modified } = this[method](setting[list], params.map((o) => o.id));
if (modified.length) {
index = `SETTING_SUCCESS_${method.toUpperCase()}`;

View File

@ -143,8 +143,8 @@ class LinkFilterSetting extends FilterSetting {
const { modified } = this[method](setting[list], params.map((o) => o.id || o));
if (modified.length) {
index = `SETTING_SUCCESS_${method.toUpperCase()}`;
langParams.list = list;
langParams.modified = modified.filter((o) => modified.includes(o.id || o)).map((o) => o.name || o).join('__, __');
langParams.updated = list;
langParams.modified = params.filter((o) => modified.includes(o.id || o)).map((o) => o.name || o).join('__, __');
}
}

View File

@ -87,7 +87,7 @@ class Autorole extends Setting {
},
{
name: 'GENERAL_ROLES',
value: setting.roles.map((role) => `<@&${role}>`).join(' ')
value: setting.roles.map((role) => `<@&${role}>`).join(' ') || '**N/A**'
}
];
}

View File

@ -9,7 +9,7 @@ class FilterSetting extends Setting {
async _action(interaction, method, actions, { _wordWatcher } = {}) {
if (!['add', 'remove', 'edit', 'list', 'reset'].includes(method))
return { error: true, message: interaction.format('ERR_INVALID_METHOD', { method }) };
return { error: true, content: interaction.format('ERR_INVALID_METHOD', { method }) };
this.client.logger.debug(`_action method:${method}`);
let result = null,
@ -17,7 +17,7 @@ class FilterSetting extends Setting {
if (method === 'add') {
if (actions.length >= 5 && _wordWatcher) return {
error: true,
message: interaction.format('SETTING_WORDWATCHER_ACTION_LIMIT')
content: interaction.format('SETTING_WORDWATCHER_ACTION_LIMIT')
};
result = await this._createAction(interaction, actions, { _wordWatcher });
index = 'SETTING_FILTER_ACTION_ADD';
@ -76,7 +76,7 @@ class FilterSetting extends Setting {
|| !validInfractions.includes(infType))
&& !['del', 'delete'].includes(action)) return {
error: true,
message: interaction.format('SETTING_FILTER_INVALID_INFRACTION', { valid: validInfractions.join('`, `') })
content: interaction.format('SETTING_FILTER_INVALID_INFRACTION', { valid: validInfractions.join('`, `') })
};
if (!infType && ['del', 'delete'].includes(action)) infType = 'DELETE';
actionObject.type = infType;
@ -192,7 +192,7 @@ class FilterSetting extends Setting {
async _removeAction(interaction, actions) {
if (!actions.length) return { error: true, message: interaction.format('SETTING_FILTER_ACTION_REMOVE_NO_ACTIONS') };
if (!actions.length) return { error: true, content: interaction.format('SETTING_FILTER_ACTION_REMOVE_NO_ACTIONS') };
const embed = this._createActionEmbed(interaction, actions);
const content = await this._prompt(interaction, { index: 'SETTING_FILTER_ACTION_REMOVE_START', time: 60, embed });
@ -200,12 +200,12 @@ class FilterSetting extends Setting {
if (['cancel', 'abort', 'exit'].includes(content)) return {
error: true,
message: interaction.format('ERR_CANCEL')
content: interaction.format('ERR_CANCEL')
};
const index = parseInt(content);
if (isNaN(index)) return { error: true, message: interaction.format('ERR_NAN') };
if (index < 0 || index > actions.length - 1) return { error: true, message: interaction.format('ERR_INDEX_OUT_OF_BOUNDS') };
if (isNaN(index)) return { error: true, content: interaction.format('ERR_NAN') };
if (index < 0 || index > actions.length - 1) return { error: true, content: interaction.format('ERR_INDEX_OUT_OF_BOUNDS') };
return actions.splice(index, 1)[0];
@ -218,8 +218,8 @@ class FilterSetting extends Setting {
if (content.error) return content;
const index = parseInt(content);
if (isNaN(index)) return { error: true, message: interaction.format('ERR_NAN') };
if (index < 0 || index > actions.length - 1) return { error: true, message: interaction.format('ERR_INDEX_OUT_OF_BOUNDS') };
if (isNaN(index)) return { error: true, content: interaction.format('ERR_NAN') };
if (index < 0 || index > actions.length - 1) return { error: true, content: interaction.format('ERR_INDEX_OUT_OF_BOUNDS') };
const action = actions[index];
@ -234,7 +234,7 @@ class FilterSetting extends Setting {
if (!properties.includes(prop)) return {
error: true,
message: interaction.format('SETTING_FILTER_ACTION_EDIT_BADPROP')
content: interaction.format('SETTING_FILTER_ACTION_EDIT_BADPROP')
};
if (prop === 'trigger') return this._editTrigger(interaction, actions, action);
@ -254,7 +254,7 @@ class FilterSetting extends Setting {
if (!interaction.guild._settings.modpoints?.enabled) return {
error: true,
message: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_DISABLED')
content: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_DISABLED')
};
const content = await this._prompt(interaction, { index: 'SETTING_FILTER_ACTION_EDIT_EXPIRATION', time: 60 });
@ -277,7 +277,7 @@ class FilterSetting extends Setting {
const bool = resolver.resolveBoolean(content);
if (bool === null) return {
error: true,
message: interaction.format('SETTING_FILTER_ACTION_EDIT_BOOL_INVALID')
content: interaction.format('SETTING_FILTER_ACTION_EDIT_BOOL_INVALID')
};
action[prop] = bool;
@ -289,7 +289,7 @@ class FilterSetting extends Setting {
if (!interaction.guild._settings.modpoints?.enabled) return {
error: true,
message: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_DISABLED')
content: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_DISABLED')
};
const content = await this._prompt(interaction, { index: 'SETTING_FILTER_ACTION_EDIT_POINTS', time: 60 });
@ -298,7 +298,7 @@ class FilterSetting extends Setting {
const reg = /(\d{1,3})\s?(points?|pts?|p)?/iu;
if (!reg.test(content)) return {
error: true,
message: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_FAIL')
content: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_FAIL')
};
const match = content.match(reg);
@ -324,7 +324,7 @@ class FilterSetting extends Setting {
if (!validInfractions.includes(content.toUpperCase())) return {
error: true,
message: interaction.format('SETTING_FILTER_ACTION_EDIT_INVALID_TYPE')
content: interaction.format('SETTING_FILTER_ACTION_EDIT_INVALID_TYPE')
};
action.type = content.toUpperCase();
@ -339,7 +339,7 @@ class FilterSetting extends Setting {
if (!['MUTE', 'BAN'].includes(action.type)) return {
error: true,
message: interaction.format('SETTING_FILTER_ACTION_EDIT_DURATION_ERR', { action: action.type })
content: interaction.format('SETTING_FILTER_ACTION_EDIT_DURATION_ERR', { action: action.type })
};
const content = await this._prompt(interaction, { index: 'SETTING_FILTER_ACTION_EDIT_DURATION', time: 120 });
@ -351,7 +351,7 @@ class FilterSetting extends Setting {
const time = resolver.resolveTime(content);
if (!time) return {
error: true,
message: interaction.format('SETTING_FILTER_ACTION_EDIT_DURATION_ERR2')
content: interaction.format('SETTING_FILTER_ACTION_EDIT_DURATION_ERR2')
};
action.duration = time;
}

View File

@ -442,7 +442,7 @@ class Infraction {
async unresolve(staff, reason) {
this.changes.push({
type: 'RESOLVE',
type: 'UNRESOLVE',
staff: staff.id,
timestamp: Date.now(),
reason

View File

@ -171,15 +171,16 @@ class SettingsCommand extends SlashCommand {
const embed = setting.usageEmbed(guild, null, this.subcommand(subcommand.name));
const dataFields = await setting.fields(guild);
// eslint-disable-next-line no-return-assign
dataFields.forEach((field) => {
dataFields.forEach((field, index) => {
if (!field.name.length) this.client.logger.warn(`${setting.name} is missing name for a field, index: ${index}`, { broadcast: true });
if (!field.value.length) this.client.logger.warn(`${setting.name} is missing value for a field, index: ${index}`, { broadcast: true });
if(field.name.length > 1) field.name = guild.format(field.name);
});
embed.addFields(dataFields);
try {
embed.addFields(...dataFields);
}catch(err) { /* */ }
await invoker.reply({ embeds: [embed] });
// .catch((error) => {
// this.client.logger.error(`${error.stack || error}\nError context: ${JSON.stringify(embed)}`);
// });
}