aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-08-30 13:12:16 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-08-30 13:12:16 -0400
commit22009ec8da37fc2cd235d0b0c987a0fe45a69e27 (patch)
tree69a47217fb1f28cdcbec9622ac8c8252848eb595 /src
parent8d819519b4376441ca156b6146600382a319a0ba (diff)
downloadtanzanite-22009ec8da37fc2cd235d0b0c987a0fe45a69e27.tar.gz
tanzanite-22009ec8da37fc2cd235d0b0c987a0fe45a69e27.tar.bz2
tanzanite-22009ec8da37fc2cd235d0b0c987a0fe45a69e27.zip
need to make commit early
Diffstat (limited to 'src')
-rw-r--r--src/arguments/roleWithDuation.ts5
-rw-r--r--src/commands/moderation/role.ts6
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts6
-rw-r--r--src/lib/extensions/discord.js/BushGuildMember.ts43
4 files changed, 34 insertions, 26 deletions
diff --git a/src/arguments/roleWithDuation.ts b/src/arguments/roleWithDuation.ts
index 423e7df..de83ccf 100644
--- a/src/arguments/roleWithDuation.ts
+++ b/src/arguments/roleWithDuation.ts
@@ -4,10 +4,11 @@ export const roleWithDurationTypeCaster: BushArgumentTypeCaster = async (
message,
phrase
): Promise<{ duration: number; role: string | null } | null> => {
- const { duration, contentWithoutTime } = client.util.parseDuration(phrase);
+ // eslint-disable-next-line prefer-const
+ let { duration, contentWithoutTime } = client.util.parseDuration(phrase);
if (contentWithoutTime === null || contentWithoutTime === undefined) return null;
+ if (contentWithoutTime[0] === ' ') contentWithoutTime = contentWithoutTime.replace(' ', '');
const role = await util.arg.cast('role', client.commandHandler.resolver, message, contentWithoutTime);
- console.debug(['role'], [role], [contentWithoutTime]);
if (!role) return null;
return { duration, role };
};
diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts
index ddaefaa..ff0e049 100644
--- a/src/commands/moderation/role.ts
+++ b/src/commands/moderation/role.ts
@@ -71,7 +71,7 @@ export default class RoleCommand extends BushCommand {
}
}
};
- console.debug(action);
+
const user = yield {
id: 'user',
type: 'member',
@@ -83,7 +83,7 @@ export default class RoleCommand extends BushCommand {
}
}
};
- console.debug(user);
+
const _role = yield {
id: 'role',
type: `${action === 'add' ? 'roleWithDuration' : 'role'}`,
@@ -98,7 +98,7 @@ export default class RoleCommand extends BushCommand {
}
}
};
- console.debug(_role);
+
return { action, user, role: (_role as any).role ?? _role, duration: (_role as any).duration };
}
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index 9a5a07f..ddc03d0 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -1126,7 +1126,7 @@ export class BushClientUtil extends ClientUtil {
user: BushGuildMemberResolvable;
duration: number | undefined;
guild: BushGuildResolvable;
- modlog: string;
+ modlog?: string;
extraInfo?: Snowflake;
}): Promise<ActivePunishment | null> {
const expires = options.duration ? new Date(new Date().getTime() + options.duration) : undefined;
@@ -1134,8 +1134,10 @@ export class BushClientUtil extends ClientUtil {
const guild = client.guilds.resolveId(options.guild)!;
const type = this.#findTypeEnum(options.type)!;
+
+
const entry = options.extraInfo
- ? ActivePunishment.build({ user, type, guild, expires, modlog: options.modlog, extraInfo: options.extraInfo })
+ ? ActivePunishment.build({ user, type, guild, expires, modlog: options.modlog??, extraInfo: options.extraInfo })
: ActivePunishment.build({ user, type, guild, expires, modlog: options.modlog });
return await entry.save().catch((e) => {
void client.console.error('createPunishmentEntry', e?.stack || e);
diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts
index 6ce473a..e738b5e 100644
--- a/src/lib/extensions/discord.js/BushGuildMember.ts
+++ b/src/lib/extensions/discord.js/BushGuildMember.ts
@@ -115,41 +115,46 @@ export class BushGuildMember extends GuildMember {
}
public async addRole(options: AddRoleOptions): Promise<AddRoleResponse> {
+ client.console.debug(`addRole: ${options.role.name}`);
const ifShouldAddRole = this.#checkIfShouldAddRole(options.role);
if (ifShouldAddRole !== true) return ifShouldAddRole;
const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!;
- if (options.addToModlog) {
- const { log: modlog } = await util.createModLogEntry({
- type: options.duration ? ModLogType.TEMP_PUNISHMENT_ROLE : ModLogType.PERM_PUNISHMENT_ROLE,
- guild: this.guild,
- moderator: moderator.id,
- user: this,
- reason: 'N/A'
- });
+ if (options.addToModlog || options.duration) {
+ const { log: modlog } = options.addToModlog
+ ? await util.createModLogEntry({
+ type: options.duration ? ModLogType.TEMP_PUNISHMENT_ROLE : ModLogType.PERM_PUNISHMENT_ROLE,
+ guild: this.guild,
+ moderator: moderator.id,
+ user: this,
+ reason: 'N/A'
+ })
+ : { log: null };
if (!modlog) return 'error creating modlog entry';
- const punishmentEntrySuccess = await util.createPunishmentEntry({
- type: 'role',
- user: this,
- guild: this.guild,
- duration: options.duration,
- modlog: modlog.id,
- extraInfo: options.role.id
- });
-
- if (!punishmentEntrySuccess) return 'error creating role entry';
+ if (options.addToModlog) {
+ const punishmentEntrySuccess = await util.createPunishmentEntry({
+ type: 'role',
+ user: this,
+ guild: this.guild,
+ modlog: modlog?.id ?? undefined,
+ duration: options.duration,
+ extraInfo: options.role.id
+ });
+ if (!punishmentEntrySuccess) return 'error creating role entry';
+ }
}
- const removeRoleSuccess = await this.roles.remove(options.role, `${moderator.tag}`);
+ const removeRoleSuccess = await this.roles.add(options.role, `${moderator.tag}`);
if (!removeRoleSuccess) return 'error adding role';
return 'success';
}
public async removeRole(options: RemoveRoleOptions): Promise<RemoveRoleResponse> {
+ client.console.debug(`removeRole: ${options.role.name}`);
const ifShouldAddRole = this.#checkIfShouldAddRole(options.role);
if (ifShouldAddRole !== true) return ifShouldAddRole;