diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-07-31 13:58:38 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-07-31 13:58:38 -0400 |
commit | 534aed7f7cd700cc83a9d61f928bba6628e05c86 (patch) | |
tree | 66e8d883e78540151a1e2092f474c53b692af55e /src/lib | |
parent | edcc0dd0a9228192ff6c4f6d6797dd6238e98f92 (diff) | |
download | tanzanite-534aed7f7cd700cc83a9d61f928bba6628e05c86.tar.gz tanzanite-534aed7f7cd700cc83a9d61f928bba6628e05c86.tar.bz2 tanzanite-534aed7f7cd700cc83a9d61f928bba6628e05c86.zip |
throw error objects instead of strings
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClientUtil.ts | 10 | ||||
-rw-r--r-- | src/lib/models/ActivePunishment.ts | 42 | ||||
-rw-r--r-- | src/lib/models/BaseModel.ts | 4 | ||||
-rw-r--r-- | src/lib/models/Global.ts | 36 | ||||
-rw-r--r-- | src/lib/models/Guild.ts | 66 | ||||
-rw-r--r-- | src/lib/models/Level.ts | 18 | ||||
-rw-r--r-- | src/lib/models/ModLog.ts | 42 | ||||
-rw-r--r-- | src/lib/models/StickyRole.ts | 18 |
8 files changed, 155 insertions, 81 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index ac39611..cf8364e 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -314,7 +314,7 @@ export class BushClientUtil extends ClientUtil { const style = Constants.MessageButtonStyles.PRIMARY; let curPage = 0; - if (typeof embeds !== 'object') throw 'embeds must be an object'; + if (typeof embeds !== 'object') throw new Error('embeds must be an object'); const msg: Message = await message.util.reply({ content: text || null, embeds: [embeds[curPage]], @@ -628,7 +628,7 @@ export class BushClientUtil extends ClientUtil { if (!victim.guild && ['ban', 'unban'].includes(type)) return true; if (moderator.guild.id !== victim.guild.id) { - throw 'moderator and victim not in same guild'; + throw new Error('moderator and victim not in same guild'); } const isOwner = moderator.guild.ownerId === moderator.id; if (moderator.id === victim.id) { @@ -768,16 +768,16 @@ export class BushClientUtil extends ClientUtil { if (raw.statusCode == 200) { profile = JSON.parse(raw.body); } else { - throw 'invalid player'; + throw new Error('invalid player'); } if (raw.statusCode == 200 && profile && profile.uuid) { return profile.uuid.replace(/-/g, ''); } else { - throw `Could not fetch the uuid for ${player}.`; + throw new Error(`Could not fetch the uuid for ${player}.`); } } catch (e) { - throw 'An error has occurred.'; + throw new Error('An error has occurred.'); } } diff --git a/src/lib/models/ActivePunishment.ts b/src/lib/models/ActivePunishment.ts index c204c9a..a757b10 100644 --- a/src/lib/models/ActivePunishment.ts +++ b/src/lib/models/ActivePunishment.ts @@ -37,57 +37,71 @@ export class ActivePunishment * The ID of this punishment (no real use just for a primary key) */ public get id(): string { - return null; + throw new Error('This should never be executed'); + } + public set id(_: string) { + throw new Error('This should never be executed'); } - public set id(value: string) {} /** * The type of punishment. */ public get type(): ActivePunishmentType { - return null; + throw new Error('This should never be executed'); + } + public set type(_: ActivePunishmentType) { + throw new Error('This should never be executed'); } - public set type(value: ActivePunishmentType) {} /** * The user who is punished. */ public get user(): Snowflake { - return null; + throw new Error('This should never be executed'); + } + public set user(_: Snowflake) { + throw new Error('This should never be executed'); } - public set user(value: Snowflake) {} /** * The guild they are punished in. */ public get guild(): Snowflake { - return null; + throw new Error('This should never be executed'); + } + public set guild(_: Snowflake) { + throw new Error('This should never be executed'); } - public set guild(value: Snowflake) {} /** * Additional info about the punishment if applicable. The channel id for channel blocks and role for punishment roles. */ public get extraInfo(): Snowflake { - return null; + throw new Error('This should never be executed'); + } + public set extraInfo(_: Snowflake) { + throw new Error('This should never be executed'); } - public set extraInfo(value: Snowflake) {} /** * The date when this punishment expires (optional). */ public get expires(): Date | null { - return null; + throw new Error('This should never be executed'); + } + public set expires(_: Date | null) { + throw new Error('This should never be executed'); } - public set expires(value: Date | null) {} /** * The reference to the modlog entry. */ public get modlog(): string { - return null; + throw new Error('This should never be executed'); + } + public set modlog(_: string) { + throw new Error('This should never be executed'); } - public set modlog(value: string) {} static initModel(sequelize: Sequelize): void { ActivePunishment.init( diff --git a/src/lib/models/BaseModel.ts b/src/lib/models/BaseModel.ts index 340e0aa..f1521dd 100644 --- a/src/lib/models/BaseModel.ts +++ b/src/lib/models/BaseModel.ts @@ -5,13 +5,13 @@ export abstract class BaseModel<A, B> extends Model<A, B> { * The date when the row was created. */ public get createdAt(): Date { - return null; + throw new Error('This should never be executed'); } /** * The date when the row was last updated. */ public get updatedAt(): Date { - return null; + throw new Error('This should never be executed'); } } diff --git a/src/lib/models/Global.ts b/src/lib/models/Global.ts index 80f11ca..a685d91 100644 --- a/src/lib/models/Global.ts +++ b/src/lib/models/Global.ts @@ -25,49 +25,61 @@ export class Global extends BaseModel<GlobalModel, GlobalModelCreationAttributes * The bot's environment. */ public get environment(): 'production' | 'development' | 'beta' { - return null; + throw new Error('This should never be executed'); + } + public set environment(_: 'production' | 'development' | 'beta') { + throw new Error('This should never be executed'); } - public set environment(value: 'production' | 'development' | 'beta') {} /** * Trusted users. */ public get superUsers(): Snowflake[] { - return null; + throw new Error('This should never be executed'); + } + public set superUsers(_: Snowflake[]) { + throw new Error('This should never be executed'); } - public set superUsers(value: Snowflake[]) {} /** * Globally disabled commands. */ public get disabledCommands(): string[] { - return null; + throw new Error('This should never be executed'); + } + public set disabledCommands(_: string[]) { + throw new Error('This should never be executed'); } - public set disabledCommands(value: string[]) {} /** * Globally blacklisted users. */ public get blacklistedUsers(): Snowflake[] { - return null; + throw new Error('This should never be executed'); + } + public set blacklistedUsers(_: Snowflake[]) { + throw new Error('This should never be executed'); } - public set blacklistedUsers(value: Snowflake[]) {} /** * Guilds blacklisted from using the bot. */ public get blacklistedGuilds(): Snowflake[] { - return null; + throw new Error('This should never be executed'); + } + public set blacklistedGuilds(_: Snowflake[]) { + throw new Error('This should never be executed'); } - public set blacklistedGuilds(value: Snowflake[]) {} /** * Channels where the bot is prevented from running. */ public get blacklistedChannels(): Snowflake[] { - return null; + throw new Error('This should never be executed'); + } + public set blacklistedChannels(_: Snowflake[]) { + throw new Error('This should never be executed'); } - public set blacklistedChannels(value: Snowflake[]) {} static initModel(sequelize: Sequelize): void { Global.init( diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts index aac4267..c28fe64 100644 --- a/src/lib/models/Guild.ts +++ b/src/lib/models/Guild.ts @@ -36,89 +36,111 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i * The ID of the guild */ public get id(): Snowflake { - return null; + throw new Error('This should never be executed'); + } + public set id(_: Snowflake) { + throw new Error('This should never be executed'); } - public set id(value: Snowflake) {} /** * The bot's prefix for the guild */ public get prefix(): string { - return null; + throw new Error('This should never be executed'); + } + public set prefix(_: string) { + throw new Error('This should never be executed'); } - public set prefix(value: string) {} /** * Channels that will have their messages automatically published */ public get autoPublishChannels(): Snowflake[] { - return null; + throw new Error('This should never be executed'); + } + public set autoPublishChannels(_: Snowflake[]) { + throw new Error('This should never be executed'); } - public set autoPublishChannels(value: Snowflake[]) {} /** * Channels where the bot won't respond in. */ public get blacklistedChannels(): Snowflake[] { - return null; + throw new Error('This should never be executed'); + } + public set blacklistedChannels(_: Snowflake[]) { + throw new Error('This should never be executed'); } - public set blacklistedChannels(value: Snowflake[]) {} /** * Users that the bot ignores in this guild */ public get blacklistedUsers(): Snowflake[] { - return null; + throw new Error('This should never be executed'); + } + public set blacklistedUsers(_: Snowflake[]) { + throw new Error('This should never be executed'); } - public set blacklistedUsers(value: Snowflake[]) {} /** * The channels where the welcome messages are sent */ public get welcomeChannel(): Snowflake { - return null; + throw new Error('This should never be executed'); + } + public set welcomeChannel(_: Snowflake) { + throw new Error('This should never be executed'); } - public set welcomeChannel(value: Snowflake) {} /** * The role given out when muting someone */ public get muteRole(): Snowflake { - return null; + throw new Error('This should never be executed'); + } + public set muteRole(_: Snowflake) { + throw new Error('This should never be executed'); } - public set muteRole(value: Snowflake) {} /** * The message that gets sent after someone gets a punishment dm */ public get punishmentEnding(): string { - return null; + throw new Error('This should never be executed'); + } + public set punishmentEnding(_: string) { + throw new Error('This should never be executed'); } - public set punishmentEnding(value: string) {} /** * Guild specific disabled commands */ public get disabledCommands(): string[] { - return null; + throw new Error('This should never be executed'); + } + public set disabledCommands(_: string[]) { + throw new Error('This should never be executed'); } - public set disabledCommands(value: string[]) {} /** * Channels that should get locked down when the lockdown command gets used. */ public get lockdownChannels(): Snowflake[] { - return null; + throw new Error('This should never be executed'); + } + public set lockdownChannels(_: Snowflake[]) { + throw new Error('This should never be executed'); } - public set lockdownChannels(value: Snowflake[]) {} /** * Custom automod phases */ public get autoModPhases(): string[] { - return null; + throw new Error('This should never be executed'); + } + public set autoModPhases(_: string[]) { + throw new Error('This should never be executed'); } - public set autoModPhases(value: string[]) {} static initModel(sequelize: Sequelize, client: BushClient): void { Guild.init( diff --git a/src/lib/models/Level.ts b/src/lib/models/Level.ts index d8b98bf..309e6e6 100644 --- a/src/lib/models/Level.ts +++ b/src/lib/models/Level.ts @@ -19,25 +19,31 @@ export class Level extends BaseModel<LevelModel, LevelModelCreationAttributes> { * The user's id. */ public get user(): Snowflake { - return null; + throw new Error('This should never be executed'); + } + public set user(_: Snowflake) { + throw new Error('This should never be executed'); } - public set user(value: Snowflake) {} /** * The guild where the user is gaining xp. */ public get guild(): Snowflake { - return null; + throw new Error('This should never be executed'); + } + public set guild(_: Snowflake) { + throw new Error('This should never be executed'); } - public set guild(value: Snowflake) {} /** * The user's xp. */ public get xp(): number { - return null; + throw new Error('This should never be executed'); + } + public set xp(_: number) { + throw new Error('This should never be executed'); } - public set xp(value: number) {} public get level(): number { return Level.convertXpToLevel(this.xp); diff --git a/src/lib/models/ModLog.ts b/src/lib/models/ModLog.ts index 6933432..33c758f 100644 --- a/src/lib/models/ModLog.ts +++ b/src/lib/models/ModLog.ts @@ -45,57 +45,71 @@ export class ModLog extends BaseModel<ModLogModel, ModLogModelCreationAttributes * The primary key of the modlog entry. */ public get id(): string { - return null; + throw new Error('This should never be executed'); + } + public set id(_: string) { + throw new Error('This should never be executed'); } - public set id(value: string) {} /** * The type of punishment. */ public get type(): ModLogType { - return null; + throw new Error('This should never be executed'); + } + public set type(_: ModLogType) { + throw new Error('This should never be executed'); } - public set type(value: ModLogType) {} /** * The user being punished. */ public get user(): Snowflake { - return null; + throw new Error('This should never be executed'); + } + public set user(_: Snowflake) { + throw new Error('This should never be executed'); } - public set user(value: Snowflake) {} /** * The user carrying out the punishment. */ public get moderator(): Snowflake { - return null; + throw new Error('This should never be executed'); + } + public set moderator(_: Snowflake) { + throw new Error('This should never be executed'); } - public set moderator(value: Snowflake) {} /** * The reason the user is getting punished */ public get reason(): string | null { - return null; + throw new Error('This should never be executed'); + } + public set reason(_: string | null) { + throw new Error('This should never be executed'); } - public set reason(value: string | null) {} /** * The amount of time the user is getting punished for. */ public get duration(): number | null { - return null; + throw new Error('This should never be executed'); + } + public set duration(_: number | null) { + throw new Error('This should never be executed'); } - public set duration(value: number | null) {} /** * The guild the user is getting punished in. */ public get guild(): Snowflake { - return null; + throw new Error('This should never be executed'); + } + public set guild(_: Snowflake) { + throw new Error('This should never be executed'); } - public set guild(value: Snowflake) {} static initModel(sequelize: Sequelize): void { ModLog.init( diff --git a/src/lib/models/StickyRole.ts b/src/lib/models/StickyRole.ts index c71ecb7..46650a4 100644 --- a/src/lib/models/StickyRole.ts +++ b/src/lib/models/StickyRole.ts @@ -19,25 +19,31 @@ export class StickyRole extends BaseModel<StickyRoleModel, StickyRoleModelCreati */ public get user(): Snowflake { - return null; + throw new Error('This should never be executed'); + } + public set user(_: Snowflake) { + throw new Error('This should never be executed'); } - public set user(value: Snowflake) {} /** * The guild where this should happen */ public get guild(): Snowflake { - return null; + throw new Error('This should never be executed'); + } + public set guild(_: Snowflake) { + throw new Error('This should never be executed'); } - public set guild(value: Snowflake) {} /** * The roles that the user should have returned */ public get roles(): Snowflake[] { - return null; + throw new Error('This should never be executed'); + } + public set roles(_: Snowflake[]) { + throw new Error('This should never be executed'); } - public set roles(value: Snowflake[]) {} static initModel(sequelize: Sequelize): void { StickyRole.init( |