aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commands/config/joinRoles.ts11
-rw-r--r--src/commands/moderation/ban.ts3
-rw-r--r--src/commands/moderation/kick.ts4
-rw-r--r--src/commands/moderation/mute.ts7
-rw-r--r--src/commands/moderation/unmute.ts3
-rw-r--r--src/commands/moderation/warn.ts3
-rw-r--r--src/commands/utilities/price.ts3
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts3
-rw-r--r--src/lib/extensions/discord.js/BushGuild.ts2
-rw-r--r--src/lib/models/Guild.ts4
10 files changed, 27 insertions, 16 deletions
diff --git a/src/commands/config/joinRoles.ts b/src/commands/config/joinRoles.ts
index 89a2421..9507d4b 100644
--- a/src/commands/config/joinRoles.ts
+++ b/src/commands/config/joinRoles.ts
@@ -39,12 +39,15 @@ export default class JoinRolesCommand extends BushCommand {
public override async exec(message: BushMessage | BushSlashMessage, { role }: { role: Role }): Promise<unknown> {
const joinRoles = await message.guild!.getSetting('joinRoles');
- const newValue = util.addOrRemoveFromArray(joinRoles.includes(role.id) ? 'remove' : 'add', joinRoles, role.id);
+ const includes = joinRoles.includes(role.id);
+ client.console.debug(joinRoles);
+ const newValue = util.addOrRemoveFromArray(includes ? 'remove' : 'add', joinRoles, role.id);
await message.guild!.setSetting('joinRoles', newValue);
+ client.console.debug(joinRoles);
return await message.util.reply({
- content: `${util.emojis.success} Successfully ${joinRoles.includes(role.id) ? 'removed' : 'added'} <@&${
- role.id
- }> from being assigned to members when they join the server.`,
+ content: `${util.emojis.success} Successfully ${includes ? 'removed' : 'added'} <@&${role.id}> ${
+ includes ? 'from' : 'to'
+ }from being assigned to members when they join the server.`,
allowedMentions: AllowedMentions.none()
});
}
diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts
index 3a86244..7f1a67c 100644
--- a/src/commands/moderation/ban.ts
+++ b/src/commands/moderation/ban.ts
@@ -93,7 +93,8 @@ export default class BanCommand extends BushCommand {
if (!message.guild) return message.util.reply(`${util.emojis.error} This command cannot be used in dms.`);
const member = message.guild!.members.cache.get(user.id) as BushGuildMember;
const useForce = force && message.author.isOwner();
- const canModerateResponse = util.moderationPermissionCheck(message.member!, member, 'ban', true, useForce);
+ if (!message.member) throw new Error(`message.member is null`);
+ const canModerateResponse = util.moderationPermissionCheck(message.member, member, 'ban', true, useForce);
if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts
index 8864320..2315712 100644
--- a/src/commands/moderation/kick.ts
+++ b/src/commands/moderation/kick.ts
@@ -62,9 +62,9 @@ export default class KickCommand extends BushCommand {
const member = message.guild!.members.cache.get(user.id) as BushGuildMember;
if (!member) return await message.util.reply(`${util.emojis.error} You cannot kick members that are not in the server.`);
-
+ if (!message.member) throw new Error(`message.member is null`);
const useForce = force && message.author.isOwner();
- const canModerateResponse = util.moderationPermissionCheck(message.member!, member, 'kick', true, useForce);
+ const canModerateResponse = util.moderationPermissionCheck(message.member, member, 'kick', true, useForce);
if (canModerateResponse !== true) {
return message.util.reply(canModerateResponse);
diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts
index e6c9065..7b8689a 100644
--- a/src/commands/moderation/mute.ts
+++ b/src/commands/moderation/mute.ts
@@ -1,4 +1,4 @@
-import { AllowedMentions, BushCommand, BushGuildMember, BushMessage, BushSlashMessage, BushUser } from '@lib';
+import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage, BushUser } from '@lib';
import { Argument } from 'discord-akairo';
export default class MuteCommand extends BushCommand {
@@ -61,11 +61,12 @@ export default class MuteCommand extends BushCommand {
message: BushMessage | BushSlashMessage,
{ user, reason, force }: { user: BushUser; reason?: { duration: number; contentWithoutTime: string }; force: boolean }
): Promise<unknown> {
- const member = message.guild!.members.cache.get(user.id) as BushGuildMember;
+ const member = message.guild!.members.cache.get(user.id);
if (!member) return await message.util.reply(`${util.emojis.error} You cannot kick members that are not in the server.`);
+ if (!message.member) throw new Error(`message.member is null`);
const useForce = force && message.author.isOwner();
- const canModerateResponse = util.moderationPermissionCheck(message.member!, member, 'mute', true, useForce);
+ const canModerateResponse = util.moderationPermissionCheck(message.member, member, 'mute', true, useForce);
const victimBoldTag = `**${member.user.tag}**`;
if (canModerateResponse !== true) {
diff --git a/src/commands/moderation/unmute.ts b/src/commands/moderation/unmute.ts
index 7e93d31..acbda3e 100644
--- a/src/commands/moderation/unmute.ts
+++ b/src/commands/moderation/unmute.ts
@@ -57,7 +57,8 @@ export default class UnmuteCommand extends BushCommand {
): Promise<unknown> {
const error = util.emojis.error;
const member = message.guild!.members.cache.get(user.id) as BushGuildMember;
- const canModerateResponse = util.moderationPermissionCheck(message.member!, member, 'unmute');
+ if (!message.member) throw new Error(`message.member is null`);
+ const canModerateResponse = util.moderationPermissionCheck(message.member, member, 'unmute');
const victimBoldTag = `**${member.user.tag}**`;
if (canModerateResponse !== true) {
diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts
index 33ac2a3..a9469cf 100644
--- a/src/commands/moderation/warn.ts
+++ b/src/commands/moderation/warn.ts
@@ -61,7 +61,8 @@ export default class WarnCommand extends BushCommand {
): Promise<unknown> {
const member = message.guild!.members.cache.get(user.id) as BushGuildMember;
const useForce = force && message.author.isOwner();
- const canModerateResponse = util.moderationPermissionCheck(message.member!, member, 'warn', true, useForce);
+ if (!message.member) throw new Error(`message.member is null`);
+ const canModerateResponse = util.moderationPermissionCheck(message.member, member, 'warn', true, useForce);
const victimBoldTag = `**${member.user.tag}**`;
if (canModerateResponse !== true) {
diff --git a/src/commands/utilities/price.ts b/src/commands/utilities/price.ts
index 921784f..0bdad27 100644
--- a/src/commands/utilities/price.ts
+++ b/src/commands/utilities/price.ts
@@ -1,4 +1,4 @@
-import { MessageEmbed } from 'discord.js';
+import { CommandInteraction, MessageEmbed } from 'discord.js';
import Fuse from 'fuse.js';
import fetch from 'node-fetch';
import { BushCommand, BushMessage } from '../../lib';
@@ -98,6 +98,7 @@ export default class PriceCommand extends BushCommand {
}
public override async exec(message: BushMessage, { item, strict }: { item: string; strict: boolean }): Promise<unknown> {
+ if (message.util.isSlash) await (message.interaction as CommandInteraction).deferReply();
const errors = new Array<string>();
const [bazaar, currentLowestBIN, averageLowestBIN, auctionAverages] = (
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index 29be84c..3c3a9c4 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -996,7 +996,8 @@ export class BushClientUtil extends ClientUtil {
return await row.save().catch((e) => client.logger.error('insertOrRemoveFromGlobal', e?.stack || e));
}
- public addOrRemoveFromArray(action: 'add' | 'remove', array: any[], value: any): any[] {
+ public addOrRemoveFromArray(action: 'add' | 'remove', _array: any[], value: any): any[] {
+ const array = new Array(..._array); // prevent modifying the original array
let newValue: any[];
if (!array) throw new Error('array is either null or undefined');
if (action === 'add') {
diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts
index efc780d..908fcec 100644
--- a/src/lib/extensions/discord.js/BushGuild.ts
+++ b/src/lib/extensions/discord.js/BushGuild.ts
@@ -21,6 +21,7 @@ export class BushGuild extends Guild {
}
public async getSetting<K extends keyof GuildModel>(setting: K): Promise<GuildModel[K]> {
+ // client.console.debug(`getSetting: ${setting}`);
return (
client.cache.guilds.get(this.id)?.[setting] ??
((await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id }))[setting]
@@ -28,6 +29,7 @@ export class BushGuild extends Guild {
}
public async setSetting<K extends keyof GuildModel>(setting: K, value: GuildDB[K]): Promise<GuildDB> {
+ // client.console.debug(`setSetting: ${setting}`);
const row = (await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id });
row[setting] = value;
client.cache.guilds.set(this.id, row.toJSON() as GuildDB);
diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts
index 4640d70..41ded9d 100644
--- a/src/lib/models/Guild.ts
+++ b/src/lib/models/Guild.ts
@@ -285,10 +285,10 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i
joinRoles: {
type: DataTypes.TEXT,
get: function () {
- return JSON.parse(this.getDataValue('enabledFeatures') as unknown as string);
+ return JSON.parse(this.getDataValue('joinRoles') as unknown as string);
},
set: function (val: string[]) {
- return this.setDataValue('enabledFeatures', JSON.stringify(val) as unknown as string[]);
+ return this.setDataValue('joinRoles', JSON.stringify(val) as unknown as string[]);
},
allowNull: false,
defaultValue: '[]'