diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/extensions/discord-akairo/BushCommand.ts | 29 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushCommandHandler.ts | 19 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushClientEvents.d.ts | 7 | ||||
-rw-r--r-- | src/lib/models/Guild.ts | 64 |
4 files changed, 100 insertions, 19 deletions
diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts index 1c8ea5b..073221d 100644 --- a/src/lib/extensions/discord-akairo/BushCommand.ts +++ b/src/lib/extensions/discord-akairo/BushCommand.ts @@ -1,5 +1,5 @@ import { ArgumentOptions, ArgumentPromptOptions, ArgumentTypeCaster, Command, CommandOptions } from 'discord-akairo'; -import { Snowflake } from 'discord.js'; +import { PermissionResolvable, Snowflake } from 'discord.js'; import { BushMessage } from '../discord.js/BushMessage'; import { BushClient } from './BushClient'; import { BushCommandHandler } from './BushCommandHandler'; @@ -136,7 +136,9 @@ export interface CustomBushArgumentOptions extends BaseBushArgumentOptions { customType?: ArgumentTypeCaster | (string | string[])[] | RegExp | string | null; } -export interface BushCommandOptions extends CommandOptions { +export type BushMissingPermissionSupplier = (message: BushMessage | BushSlashMessage) => Promise<any> | any; + +export interface BushCommandOptions extends Omit<CommandOptions, 'userPermissions' | 'clientPermissions'> { hidden?: boolean; restrictedChannels?: Snowflake[]; restrictedGuilds?: Snowflake[]; @@ -148,6 +150,9 @@ export interface BushCommandOptions extends CommandOptions { args?: BushArgumentOptions[] & CustomBushArgumentOptions[]; category: string; pseudo?: boolean; + bypassChannelBlacklist?: boolean; + clientPermissions?: PermissionResolvable | PermissionResolvable[] | BushMissingPermissionSupplier; + userPermissions?: PermissionResolvable | PermissionResolvable[] | BushMissingPermissionSupplier; } export class BushCommand extends Command { @@ -155,13 +160,14 @@ export class BushCommand extends Command { public declare handler: BushCommandHandler; + /** The command's options */ public options: BushCommandOptions; /** The channels the command is limited to run in. */ - public restrictedChannels: Snowflake[]; + public restrictedChannels: Snowflake[] | undefined; /** The guilds the command is limited to run in. */ - public restrictedGuilds: Snowflake[]; + public restrictedGuilds: Snowflake[] | undefined; /** Whether the command is hidden from the help command. */ public hidden: boolean; @@ -169,6 +175,9 @@ export class BushCommand extends Command { /** A fake command, completely hidden from the help command. */ public pseudo: boolean; + /** Allow this command to be run in channels that are blacklisted. */ + public bypassChannelBlacklist: boolean; + public constructor(id: string, options: BushCommandOptions) { if (options.args && typeof options.args !== 'function') { options.args.forEach((_, index: number) => { @@ -179,12 +188,14 @@ export class BushCommand extends Command { } }); } - super(id, options); + // incompatible options + super(id, options as any); this.options = options; - this.hidden = options.hidden ?? false; - this.restrictedChannels = options.restrictedChannels!; - this.restrictedGuilds = options.restrictedGuilds!; - this.pseudo = options.pseudo!; + this.hidden = Boolean(options.hidden); + this.restrictedChannels = options.restrictedChannels; + this.restrictedGuilds = options.restrictedGuilds; + this.pseudo = Boolean(options.pseudo); + this.bypassChannelBlacklist = Boolean(options.bypassChannelBlacklist); } public override exec(message: BushMessage, args: any): any; diff --git a/src/lib/extensions/discord-akairo/BushCommandHandler.ts b/src/lib/extensions/discord-akairo/BushCommandHandler.ts index f8dcd93..8ab47d8 100644 --- a/src/lib/extensions/discord-akairo/BushCommandHandler.ts +++ b/src/lib/extensions/discord-akairo/BushCommandHandler.ts @@ -9,17 +9,30 @@ export type BushCommandHandlerOptions = CommandHandlerOptions; export interface BushCommandHandlerEvents extends CommandHandlerEvents { commandBlocked: [message: BushMessage, command: BushCommand, reason: string]; - + commandBreakout: [message: BushMessage, command: BushCommand, breakMessage: BushMessage]; + commandCancelled: [message: BushMessage, command: BushCommand, retryMessage?: BushMessage]; + commandFinished: [message: BushMessage, command: BushCommand, args: any, returnValue: any]; + commandInvalid: [message: BushMessage, command: BushCommand]; + commandLocked: [message: BushMessage, command: BushCommand]; + commandStarted: [message: BushMessage, command: BushCommand, args: any]; + cooldown: [message: BushMessage | BushSlashMessage, command: BushCommand, remaining: number]; + error: [error: Error, message: BushMessage, command?: BushCommand]; + inPrompt: [message: BushMessage]; + load: [command: BushCommand, isReload: boolean]; + messageBlocked: [message: BushMessage | BushSlashMessage, reason: string]; + messageInvalid: [message: BushMessage]; missingPermissions: [message: BushMessage, command: BushCommand, type: 'client' | 'user', missing: Array<PermissionString>]; - + remove: [command: BushCommand]; slashBlocked: [message: BushSlashMessage, command: BushCommand, reason: string]; - + slashError: [error: Error, message: BushSlashMessage, command: BushCommand]; + slashFinished: [message: BushSlashMessage, command: BushCommand, args: any, returnValue: any]; slashMissingPermissions: [ message: BushSlashMessage, command: BushCommand, type: 'client' | 'user', missing: Array<PermissionString> ]; + slashStarted: [message: BushSlashMessage, command: BushCommand, args: any]; } export class BushCommandHandler extends CommandHandler { diff --git a/src/lib/extensions/discord.js/BushClientEvents.d.ts b/src/lib/extensions/discord.js/BushClientEvents.d.ts index eb36153..2c9de89 100644 --- a/src/lib/extensions/discord.js/BushClientEvents.d.ts +++ b/src/lib/extensions/discord.js/BushClientEvents.d.ts @@ -233,7 +233,12 @@ export interface BushClientEvents extends ClientEvents { caseID: string, dmSuccess: boolean ]; - bushLevelUp: []; + bushLevelUpdate: [ + member: BushGuildMember, + oldLevel: number, + newLevel: number, + currentXp: number + ]; } type Setting = diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts index f59bed1..1897068 100644 --- a/src/lib/models/Guild.ts +++ b/src/lib/models/Guild.ts @@ -64,6 +64,18 @@ export const guildSettingsObj = { description: 'Custom phrases to be detected by automod.', type: 'custom', configurable: false + }, + noXpChannels: { + name: 'No Xp Channels', + description: 'Channels where users will not earn xp for leveling.', + type: 'channel-array', + configurable: true + }, + levelRoles: { + name: 'Level Roles', + description: 'What roles get given at certain levels.', + type: 'custom', + configurable: false } }; export type GuildSettings = keyof typeof guildSettingsObj; @@ -144,11 +156,13 @@ export interface GuildModel { punishmentEnding: string; disabledCommands: string[]; lockdownChannels: Snowflake[]; - autoModPhases: string[]; + autoModPhases: { [word: string]: 0 | 1 | 2 | 3 }; enabledFeatures: GuildFeatures[]; joinRoles: Snowflake[]; logChannels: LogChannelDB; bypassChannelBlacklist: Snowflake[]; + noXpChannels: Snowflake[]; + levelRoles: { [level: number]: Snowflake }; } export interface GuildModelCreationAttributes { @@ -162,11 +176,13 @@ export interface GuildModelCreationAttributes { punishmentEnding?: string; disabledCommands?: string[]; lockdownChannels?: Snowflake[]; - autoModPhases?: string[]; + autoModPhases?: { [word: string]: 0 | 1 | 2 | 3 }; enabledFeatures?: GuildFeatures[]; joinRoles?: Snowflake[]; logChannels?: LogChannelDB; bypassChannelBlacklist?: Snowflake[]; + noXpChannels?: Snowflake[]; + levelRoles?: { [level: number]: Snowflake }; } export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> implements GuildModel { @@ -273,10 +289,10 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i /** * Custom automod phases */ - public get autoModPhases(): string[] { + public get autoModPhases(): { [word: string]: 0 | 1 | 2 | 3 } { throw new Error(NEVER_USED); } - public set autoModPhases(_: string[]) { + public set autoModPhases(_: { [word: string]: 0 | 1 | 2 | 3 }) { throw new Error(NEVER_USED); } @@ -320,6 +336,20 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i throw new Error(NEVER_USED); } + public get noXpChannels(): Snowflake[] { + throw new Error(NEVER_USED); + } + public set noXpChannels(_: Snowflake[]) { + throw new Error(NEVER_USED); + } + + public get levelRoles(): { [level: number]: Snowflake } { + throw new Error(NEVER_USED); + } + public set levelRoles(_: { [level: number]: Snowflake }) { + throw new Error(NEVER_USED); + } + public static initModel(sequelize: Sequelize, client: BushClient): void { Guild.init( { @@ -349,7 +379,17 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i }, disabledCommands: jsonArrayInit('disabledCommands'), lockdownChannels: jsonArrayInit('lockdownChannels'), - autoModPhases: jsonArrayInit('autoModPhases'), + autoModPhases: { + type: DataTypes.TEXT, + get: function (): { [level: number]: Snowflake } { + return jsonParseGet.call(this, 'autoModPhases'); + }, + set: function (val: { [level: number]: Snowflake }) { + return jsonParseSet.call(this, 'autoModPhases', val); + }, + allowNull: false, + defaultValue: '{}' + }, enabledFeatures: jsonArrayInit('enabledFeatures'), joinRoles: jsonArrayInit('joinRoles'), logChannels: { @@ -363,7 +403,19 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i allowNull: false, defaultValue: '{}' }, - bypassChannelBlacklist: jsonArrayInit('bypassChannelBlacklist') + bypassChannelBlacklist: jsonArrayInit('bypassChannelBlacklist'), + noXpChannels: jsonArrayInit('noXpChannels'), + levelRoles: { + type: DataTypes.TEXT, + get: function (): { [level: number]: Snowflake } { + return jsonParseGet.call(this, 'levelRoles'); + }, + set: function (val: { [level: number]: Snowflake }) { + return jsonParseSet.call(this, 'levelRoles', val); + }, + allowNull: false, + defaultValue: '{}' + } }, { sequelize: sequelize } ); |