aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/discord.js
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-08-17 12:31:09 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-08-17 12:31:09 -0400
commitd40527d0a2d9f209905750258f71bedff1cdf089 (patch)
treee017fd844c2135bfc85228d00ef2617d24ce0a3f /src/lib/extensions/discord.js
parentd431ad00754f3f250103deedea495b9bcee73fc0 (diff)
downloadtanzanite-d40527d0a2d9f209905750258f71bedff1cdf089.tar.gz
tanzanite-d40527d0a2d9f209905750258f71bedff1cdf089.tar.bz2
tanzanite-d40527d0a2d9f209905750258f71bedff1cdf089.zip
turned on ts strict option
Diffstat (limited to 'src/lib/extensions/discord.js')
-rw-r--r--src/lib/extensions/discord.js/BushGuild.ts6
-rw-r--r--src/lib/extensions/discord.js/BushGuildMember.ts47
-rw-r--r--src/lib/extensions/discord.js/BushMessage.ts2
3 files changed, 33 insertions, 22 deletions
diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts
index dafa1a4..81c0108 100644
--- a/src/lib/extensions/discord.js/BushGuild.ts
+++ b/src/lib/extensions/discord.js/BushGuild.ts
@@ -41,8 +41,8 @@ export class BushGuild extends Guild {
| 'error creating modlog entry'
| 'error removing ban entry'
> {
- const user = client.users.resolveId(options.user);
- const moderator = client.users.cache.get(client.users.resolveId(options.moderator));
+ const user = client.users.resolveId(options.user)!;
+ const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!)!;
const bans = await this.bans.fetch();
@@ -50,6 +50,7 @@ export class BushGuild extends Guild {
if (!bans.has(user)) notBanned = true;
const unbanSuccess = await this.bans
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
.remove(user, `${moderator.tag} | ${options.reason || 'No reason provided.'}`)
.catch((e) => {
if (e?.code === 'UNKNOWN_BAN') {
@@ -84,6 +85,7 @@ export class BushGuild extends Guild {
const userObject = client.users.cache.get(user);
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
userObject?.send(`You have been unbanned from **${this}** for **${options.reason || 'No reason provided'}**.`);
if (notBanned) return 'user not banned';
diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts
index 7db31c5..641cc74 100644
--- a/src/lib/extensions/discord.js/BushGuildMember.ts
+++ b/src/lib/extensions/discord.js/BushGuildMember.ts
@@ -80,8 +80,8 @@ export class BushGuildMember extends GuildMember {
super(client, data, guild);
}
- public async warn(options: BushPunishmentOptions): Promise<{ result: WarnResponse; caseNum: number }> {
- const moderator = client.users.cache.get(client.users.resolveId(options.moderator)) ?? client.user;
+ public async warn(options: BushPunishmentOptions): Promise<{ result: WarnResponse | null; caseNum: number | null }> {
+ const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!;
// add modlog entry
const result = await util.createModLogEntry(
{
@@ -98,6 +98,7 @@ export class BushGuildMember extends GuildMember {
// dm user
const ending = await this.guild.getSetting('punishmentEnding');
const dmSuccess = await this.send({
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
content: `You have been warned in **${this.guild}** for **${options.reason || 'No reason provided'}**.${
ending ? `\n\n${ending}` : ''
}`
@@ -112,7 +113,7 @@ export class BushGuildMember extends GuildMember {
const ifShouldAddRole = this.#checkIfShouldAddRole(options.role);
if (ifShouldAddRole !== true) return ifShouldAddRole;
- const moderator = client.users.cache.get(client.users.resolveId(options.moderator)) ?? client.user;
+ const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!;
if (options.addToModlog) {
const { log: modlog } = await util.createModLogEntry({
@@ -147,7 +148,7 @@ export class BushGuildMember extends GuildMember {
const ifShouldAddRole = this.#checkIfShouldAddRole(options.role);
if (ifShouldAddRole !== true) return ifShouldAddRole;
- const moderator = client.users.cache.get(client.users.resolveId(options.moderator)) ?? client.user;
+ const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!;
if (options.addToModlog) {
const { log: modlog } = await util.createModLogEntry({
@@ -180,7 +181,7 @@ export class BushGuildMember extends GuildMember {
return 'user hierarchy';
} else if (role.managed) {
return 'role managed';
- } else if (this.guild.me.roles.highest.position <= role.position) {
+ } else if (this.guild.me!.roles.highest.position <= role.position) {
return 'client hierarchy';
}
return true;
@@ -188,17 +189,18 @@ export class BushGuildMember extends GuildMember {
public async mute(options: BushTimedPunishmentOptions): Promise<MuteResponse> {
// checks
- if (!this.guild.me.permissions.has('MANAGE_ROLES')) return 'missing permissions';
+ if (!this.guild.me!.permissions.has('MANAGE_ROLES')) return 'missing permissions';
const muteRoleID = await this.guild.getSetting('muteRole');
if (!muteRoleID) return 'no mute role';
const muteRole = this.guild.roles.cache.get(muteRoleID);
if (!muteRole) return 'invalid mute role';
- if (muteRole.position >= this.guild.me.roles.highest.position || muteRole.managed) return 'mute role not manageable';
+ if (muteRole.position >= this.guild.me!.roles.highest.position || muteRole.managed) return 'mute role not manageable';
- const moderator = client.users.cache.get(client.users.resolveId(options.moderator)) ?? client.user;
+ const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!;
// add role
const muteSuccess = await this.roles
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
.add(muteRole, `[Mute] ${moderator.tag} | ${options.reason || 'No reason provided.'}`)
.catch(async (e) => {
await client.console.warn('muteRoleAddError', e?.stack || e);
@@ -234,6 +236,7 @@ export class BushGuildMember extends GuildMember {
const dmSuccess = await this.send({
content: `You have been muted ${
options.duration ? 'for ' + util.humanizeDuration(options.duration) : 'permanently'
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
} in **${this.guild}** for **${options.reason || 'No reason provided'}**.${ending ? `\n\n${ending}` : ''}`
}).catch(() => false);
@@ -244,17 +247,18 @@ export class BushGuildMember extends GuildMember {
public async unmute(options: BushPunishmentOptions): Promise<UnmuteResponse> {
//checks
- if (!this.guild.me.permissions.has('MANAGE_ROLES')) return 'missing permissions';
+ if (!this.guild.me!.permissions.has('MANAGE_ROLES')) return 'missing permissions';
const muteRoleID = await this.guild.getSetting('muteRole');
if (!muteRoleID) return 'no mute role';
const muteRole = this.guild.roles.cache.get(muteRoleID);
if (!muteRole) return 'invalid mute role';
- if (muteRole.position >= this.guild.me.roles.highest.position || muteRole.managed) return 'mute role not manageable';
+ if (muteRole.position >= this.guild.me!.roles.highest.position || muteRole.managed) return 'mute role not manageable';
- const moderator = client.users.cache.get(client.users.resolveId(options.moderator)) ?? client.user;
+ const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!;
//remove role
const muteSuccess = await this.roles
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
.remove(muteRole, `[Unmute] ${moderator.tag} | ${options.reason || 'No reason provided.'}`)
.catch(async (e) => {
await client.console.warn('muteRoleAddError', e?.stack || e);
@@ -284,6 +288,7 @@ export class BushGuildMember extends GuildMember {
//dm user
const dmSuccess = await this.send({
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
content: `You have been unmuted in **${this.guild}** because **${options.reason || 'No reason provided'}**.`
}).catch(() => false);
@@ -294,20 +299,22 @@ export class BushGuildMember extends GuildMember {
public async bushKick(options: BushPunishmentOptions): Promise<KickResponse> {
// checks
- if (!this.guild.me.permissions.has('KICK_MEMBERS') || !this.kickable) return 'missing permissions';
+ if (!this.guild.me?.permissions.has('KICK_MEMBERS') || !this.kickable) return 'missing permissions';
- const moderator = client.users.cache.get(client.users.resolveId(options.moderator)) ?? client.user;
+ const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!;
// dm user
const ending = await this.guild.getSetting('punishmentEnding');
const dmSuccess = await this.send({
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
content: `You have been kicked from **${this.guild}** for **${options.reason || 'No reason provided'}**.${
ending ? `\n\n${ending}` : ''
}`
}).catch(() => false);
// kick
- const kickSuccess = await this.kick(`${moderator.tag} | ${options.reason || 'No reason provided.'}`).catch(() => false);
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
+ const kickSuccess = await this.kick(`${moderator?.tag} | ${options.reason || 'No reason provided.'}`).catch(() => false);
if (!kickSuccess) return 'error kicking';
// add modlog entry
@@ -319,28 +326,30 @@ export class BushGuildMember extends GuildMember {
reason: options.reason,
guild: this.guild
})
- .catch(() => null);
+ .catch(() => ({ log: null }));
if (!modlog) return 'error creating modlog entry';
if (!dmSuccess) return 'failed to dm';
return 'success';
}
- public async bushBan(options?: BushBanOptions): Promise<BanResponse> {
+ public async bushBan(options: BushBanOptions): Promise<BanResponse> {
// checks
- if (!this.guild.me.permissions.has('BAN_MEMBERS') || !this.bannable) return 'missing permissions';
+ if (!this.guild.me!.permissions.has('BAN_MEMBERS') || !this.bannable) return 'missing permissions';
- const moderator = client.users.cache.get(client.users.resolveId(options.moderator)) ?? client.user;
+ const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!;
// dm user
const ending = await this.guild.getSetting('punishmentEnding');
const dmSuccess = await this.send({
content: `You have been banned ${
- options.duration ? 'for ' + util.humanizeDuration(options.duration) : 'permanently'
+ options?.duration ? 'for ' + util.humanizeDuration(options.duration) : 'permanently'
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
} from **${this.guild}** for **${options.reason || 'No reason provided'}**.${ending ? `\n\n${ending}` : ''}`
}).catch(() => false);
// ban
const banSuccess = await this.ban({
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
reason: `${moderator.tag} | ${options.reason || 'No reason provided.'}`,
days: options.deleteDays
}).catch(() => false);
diff --git a/src/lib/extensions/discord.js/BushMessage.ts b/src/lib/extensions/discord.js/BushMessage.ts
index 921d03e..6d9a332 100644
--- a/src/lib/extensions/discord.js/BushMessage.ts
+++ b/src/lib/extensions/discord.js/BushMessage.ts
@@ -11,7 +11,7 @@ export interface BushPartialMessage
extends Partialize<BushMessage, 'type' | 'system' | 'pinned' | 'tts', 'content' | 'cleanContent' | 'author'> {}
export class BushMessage extends Message {
public declare readonly client: BushClient;
- public override util: BushCommandUtil;
+ public override util!: BushCommandUtil;
public declare readonly guild: BushGuild | null;
public declare readonly member: BushGuildMember | null;
public declare author: BushUser;