aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commands/admin/roleAll.ts11
-rw-r--r--src/commands/dev/eval.ts9
-rw-r--r--src/commands/utilities/whoHasRole.ts27
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts21
-rw-r--r--src/listeners/message/automodCreate.ts6
-rw-r--r--src/tasks/removeExpiredPunishements.ts13
6 files changed, 56 insertions, 31 deletions
diff --git a/src/commands/admin/roleAll.ts b/src/commands/admin/roleAll.ts
index ec18060..2382a4b 100644
--- a/src/commands/admin/roleAll.ts
+++ b/src/commands/admin/roleAll.ts
@@ -45,7 +45,11 @@ export default class RoleAllCommand extends BushCommand {
);
}
+ console.time('roleAll1');
let members = await message.guild.members.fetch();
+ console.timeEnd('roleAll1');
+
+ console.time('roleAll2');
members = members.filter((member: GuildMember) => {
try {
if (member.user.bot && !args.bot) return false;
@@ -55,14 +59,21 @@ export default class RoleAllCommand extends BushCommand {
}
return true;
});
+ console.timeEnd('roleAll2');
+ console.time('roleAll3');
await message.util.reply(`${this.client.util.emojis.loading} adding roles to ${members.size} members`);
+ console.timeEnd('roleAll3');
+ console.time('roleAll4');
const promises = members.map((member: GuildMember) => {
return member.roles.add(args.role, `RoleAll Command - triggered by ${message.author.tag} (${message.author.id})`);
});
+ console.timeEnd('roleAll4');
+ console.time('roleAll5');
const failed = (await Promise.allSettled(promises)).filter((val) => val.status === 'rejected');
+ console.timeEnd('roleAll5');
if (!failed.length) {
await message.util.reply({
diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts
index 294c61b..3bc2eed 100644
--- a/src/commands/dev/eval.ts
+++ b/src/commands/dev/eval.ts
@@ -68,12 +68,13 @@ export default class EvalCommand extends BushCommand {
if (message.util.isSlash) {
await (message as BushSlashMessage).interaction.deferReply({ ephemeral: args.silent });
}
- args.code = args.code.replace(/[“”]/g, '"').replace(/```*(?:js|ts)?/g, '');
+ const _isTypescript = args.typescript || args.code.includes('```ts');
+ const _code = args.code.replace(/[“”]/g, '"').replace(/```*(?:js|ts)?/g, '');
const code: { ts: string | null; js: string; lang: 'ts' | 'js' } = {
- ts: args.typescript ? args.code : null,
- js: args.typescript ? transpile(args.code) : args.code,
- lang: args.typescript ? 'ts' : 'js'
+ ts: _isTypescript ? _code : null,
+ js: _isTypescript ? transpile(_code) : _code,
+ lang: _isTypescript ? 'ts' : 'js'
};
const embed = new _MessageEmbed();
diff --git a/src/commands/utilities/whoHasRole.ts b/src/commands/utilities/whoHasRole.ts
index e507036..73a9920 100644
--- a/src/commands/utilities/whoHasRole.ts
+++ b/src/commands/utilities/whoHasRole.ts
@@ -1,10 +1,10 @@
import { BushCommand, BushMessage, BushSlashMessage } from '@lib';
-import { MessageEmbed, Role, Util } from 'discord.js';
+import { Role, Util } from 'discord.js';
export default class WhoHasRoleCommand extends BushCommand {
public constructor() {
super('whohasrole', {
- aliases: ['whohasrole'],
+ aliases: ['whohasrole', 'whr', 'dump'],
category: 'utilities',
description: {
content: 'Allows you to view what users have a certain role.',
@@ -38,17 +38,24 @@ export default class WhoHasRoleCommand extends BushCommand {
});
}
public override async exec(message: BushMessage | BushSlashMessage, args: { role: Role }): Promise<unknown> {
+ // console.time('whohasrole1');
const roleMembers = args.role.members.map((member) => `${member.user} (${Util.escapeMarkdown(member.user.tag)})`);
+ // console.timeEnd('whohasrole1');
+ // console.time('whohasrole2');
const chunkedRoleMembers = util.chunk(roleMembers, 30);
- const embedPages = chunkedRoleMembers.map(
- (chunk) =>
- new MessageEmbed({
- title: `${args.role.name}'s Members [\`${args.role.members.size.toLocaleString()}\`]`,
- description: chunk.join('\n'),
- color: util.colors.default
- })
- );
+ // console.timeEnd('whohasrole2');
+
+ // console.time('whohasrole3');
+ const title = `${args.role.name}'s Members [\`${args.role.members.size.toLocaleString()}\`]`;
+ const color = util.colors.default;
+ const embedPages = chunkedRoleMembers.map((chunk) => ({
+ title,
+ description: chunk.join('\n'),
+ color
+ }));
+ // console.timeEnd('whohasrole3');
+
return await util.buttonPaginate(message, embedPages, null, true);
}
}
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index 55f525b..fa5e3b0 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -39,6 +39,7 @@ import {
MessageComponentInteraction,
MessageEditOptions,
MessageEmbed,
+ MessageEmbedOptions,
MessageOptions,
Snowflake,
TextChannel,
@@ -677,7 +678,7 @@ export class BushClientUtil extends ClientUtil {
*/
public async buttonPaginate(
message: BushMessage | BushSlashMessage,
- embeds: MessageEmbed[],
+ embeds: MessageEmbed[] | MessageEmbedOptions[],
text: string | null = null,
deleteOnExit?: boolean,
startOn?: number
@@ -690,7 +691,11 @@ export class BushClientUtil extends ClientUtil {
}
embeds.forEach((_e, i) => {
- embeds[i] = embeds[i].setFooter(`Page ${i + 1}/${embeds.length}`);
+ embeds[i] instanceof MessageEmbed
+ ? (embeds[i] as MessageEmbed).setFooter(`Page ${(i + 1).toLocaleString()}/${embeds.length.toLocaleString()}`)
+ : ((embeds[i] as MessageEmbedOptions).footer = {
+ text: `Page ${(i + 1).toLocaleString()}/${embeds.length.toLocaleString()}`
+ });
});
const style = Constants.MessageButtonStyles.PRIMARY;
@@ -772,13 +777,13 @@ export class BushClientUtil extends ClientUtil {
style,
customId: 'paginate_beginning',
emoji: paginateEmojis.beginning,
- disabled: disableAll || curPage == 0
+ disabled: disableAll || curPage === 0
}),
new MessageButton({
style,
customId: 'paginate_back',
emoji: paginateEmojis.back,
- disabled: disableAll || curPage == 0
+ disabled: disableAll || curPage === 0
}),
new MessageButton({
style,
@@ -790,13 +795,13 @@ export class BushClientUtil extends ClientUtil {
style,
customId: 'paginate_next',
emoji: paginateEmojis.forward,
- disabled: disableAll || curPage == embeds.length - 1
+ disabled: disableAll || curPage === embeds.length - 1
}),
new MessageButton({
style,
customId: 'paginate_end',
emoji: paginateEmojis.end,
- disabled: disableAll || curPage == embeds.length - 1
+ disabled: disableAll || curPage === embeds.length - 1
})
);
}
@@ -1176,11 +1181,13 @@ export class BushClientUtil extends ClientUtil {
const guild = client.guilds.resolveId(options.guild);
const type = this.#findTypeEnum(options.type);
+ if (!user || !guild) return false;
+
let success = true;
const entries = await ActivePunishment.findAll({
// finding all cases of a certain type incase there were duplicates or something
- where: { user, guild, type }
+ where: { user: user.id, guild: guild, type }
}).catch(async (e) => {
await util.handleError('removePunishmentEntry', e);
success = false;
diff --git a/src/listeners/message/automodCreate.ts b/src/listeners/message/automodCreate.ts
index ac05bf9..638e8d5 100644
--- a/src/listeners/message/automodCreate.ts
+++ b/src/listeners/message/automodCreate.ts
@@ -59,7 +59,7 @@ export default class AutomodMessageCreateListener extends BushListener {
void message.delete().catch(() => {});
void message.member?.warn({
moderator: message.guild.me!,
- reason: 'Saying a blacklisted word'
+ reason: '[AutoMod] blacklisted word'
});
break;
@@ -68,7 +68,7 @@ export default class AutomodMessageCreateListener extends BushListener {
void message.delete().catch(() => {});
void message.member?.mute({
moderator: message.guild.me!,
- reason: 'Saying a blacklisted word',
+ reason: '[AutoMod] blacklisted word',
duration: 900_000 // 15 minutes
});
break;
@@ -77,7 +77,7 @@ export default class AutomodMessageCreateListener extends BushListener {
void message.delete().catch(() => {});
void message.member?.mute({
moderator: message.guild.me!,
- reason: 'Saying a blacklisted word',
+ reason: '[AutoMod] blacklisted word',
duration: 0 // perm
});
break;
diff --git a/src/tasks/removeExpiredPunishements.ts b/src/tasks/removeExpiredPunishements.ts
index d787063..69130ee 100644
--- a/src/tasks/removeExpiredPunishements.ts
+++ b/src/tasks/removeExpiredPunishements.ts
@@ -1,4 +1,4 @@
-import { BushGuild, BushTask } from '@lib';
+import { BushGuild, BushTask, BushUser } from '@lib';
import { Op } from 'sequelize';
import { ActivePunishment, ActivePunishmentType } from '../lib/models/ActivePunishment';
@@ -30,22 +30,21 @@ export default class RemoveExpiredPunishmentsTask extends BushTask {
for (const entry of expiredEntries) {
const guild = client.guilds.cache.get(entry.guild) as BushGuild;
const member = guild.members.cache.get(entry.user);
+ const user = (await util.resolveNonCachedUser(entry.user)) as BushUser;
- if (!guild) {
- await entry.destroy();
- continue;
- }
+ if (!guild) continue;
switch (entry.type) {
case ActivePunishmentType.BAN: {
- const result = await guild.unban({ user: entry.user, reason: 'Punishment expired.' });
+ if (!user) throw new Error(`user is undefined`);
+ const result = await guild.unban({ user: user, reason: 'Punishment expired.' });
if (['success', 'user not banned'].includes(result)) await entry.destroy();
else throw new Error(result);
void client.logger.verbose(`removeExpiredPunishments`, `Unbanned ${entry.user}.`);
break;
}
case ActivePunishmentType.BLOCK: {
- //todo
+ //todo once blocks are added
break;
}
case ActivePunishmentType.MUTE: {