diff options
-rw-r--r-- | src/commands/config/features.ts | 29 | ||||
-rw-r--r-- | src/commands/config/settings.ts | 25 | ||||
-rw-r--r-- | src/commands/utilities/steal.ts | 32 | ||||
-rw-r--r-- | src/lib/models/Guild.ts | 34 |
4 files changed, 97 insertions, 23 deletions
diff --git a/src/commands/config/features.ts b/src/commands/config/features.ts new file mode 100644 index 0000000..0547bd0 --- /dev/null +++ b/src/commands/config/features.ts @@ -0,0 +1,29 @@ +// import { BushCommand, BushMessage, BushSlashMessage, guildFeatures } from '@lib'; +// import { MessageEmbed } from 'discord.js'; + +// export default class FeaturesCommand extends BushCommand { +// public constructor() { +// super('features', { +// aliases: ['features'], +// category: 'config', +// description: { +// content: 'Toggle features the server.', +// usage: 'features', +// examples: ['features'] +// }, +// slash: true, +// channel: 'guild', +// clientPermissions: ['SEND_MESSAGES', 'EMBED_LINKS'], +// userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'] +// }); +// } +// public override async exec(message: BushMessage | BushSlashMessage): Promise<unknown> { +// if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be used in servers.`); +// const featureEmbed = new MessageEmbed().setTitle(`${message.guild.name}'s Features`).setColor(util.colors.default); +// const featureList: string[] = []; +// const enabledFeatures = message.guild.getSetting('enabledFeatures'); +// guildFeatures.forEach(feature => { +// featureList.push(`${}`) +// }) +// } +// } diff --git a/src/commands/config/settings.ts b/src/commands/config/settings.ts index f474804..0b71629 100644 --- a/src/commands/config/settings.ts +++ b/src/commands/config/settings.ts @@ -1,28 +1,28 @@ -// import { BushCommand, BushMessage, BushSlashMessage } from '@lib'; +// import { BushCommand, BushMessage, BushSlashMessage, guildSettings } from '@lib'; // export default class SettingsCommand extends BushCommand { // public constructor() { // super('settings', { -// aliases: ['settings'], +// aliases: ['settings', 'settings', 'configure', 'config'], // category: 'config', // description: { -// content: 'Configure options for ', -// usage: 'template <requiredArg> [optionalArg]', +// content: 'Configure server options. Hint this is easier to use with the slash command.', +// usage: 'config <\'add\'|\'remove\'|\'toggle\'> <setting>', // examples: ['template 1 2'] // }, // args: [ // { -// id: 'required_argument', -// type: 'string', +// id: 'action', +// customType: ['add', 'remove', 'toggle'], // prompt: { -// start: 'What would you like to set your first argument to be?', -// retry: '{error} Pick a valid argument.', +// start: 'What action would you like to perform, it can be `add`, `remove`, or `toggle`.', +// retry: '{error} Choose a either `add`, `remove`, or `toggle`.', // optional: false // } // }, // { -// id: 'optional_argument', -// type: 'string', +// id: 'setting', +// customType: Object.keys(guildSettings), // prompt: { // start: 'What would you like to set your second argument to be?', // retry: '{error} Pick a valid argument.', @@ -30,7 +30,7 @@ // } // } // ], -// slash: false, //set this to true +// slash: true, // slashOptions: [ // { // name: 'required_argument', @@ -45,10 +45,7 @@ // required: false // } // ], -// superUserOnly: true, -// ownerOnly: true, // channel: 'guild', -// hidden: true, // clientPermissions: ['SEND_MESSAGES'], // userPermissions: ['SEND_MESSAGES'] // }); diff --git a/src/commands/utilities/steal.ts b/src/commands/utilities/steal.ts index 92abcb2..6298271 100644 --- a/src/commands/utilities/steal.ts +++ b/src/commands/utilities/steal.ts @@ -1,5 +1,5 @@ import { BushCommand, BushMessage } from '@lib'; -import { Emoji } from 'discord.js'; +import { Argument } from 'discord-akairo'; export default class StealCommand extends BushCommand { public constructor() { @@ -14,7 +14,11 @@ export default class StealCommand extends BushCommand { args: [ { id: 'emoji', - customType: util.arg.union('emoji', 'url'), + customType: Argument.union( + /<a?:(?<emojiName>[a-zA-Z0-9_]+):(?<emojiID>\d{15,21})>/gim, //emoji + 'url', + /^(\d{15,21})$/gim //snowflake + ), prompt: { start: 'What emoji would you like to steal?', retry: '{error} Pick a valid emoji.', @@ -29,14 +33,20 @@ export default class StealCommand extends BushCommand { userPermissions: ['SEND_MESSAGES', 'MANAGE_EMOJIS_AND_STICKERS'] }); } - public override async exec(message: BushMessage, args: { emoji?: URL | Emoji; name: string }): Promise<unknown> { + public override async exec( + message: BushMessage, + args: { emoji?: URL | string | { emojiName?: string; emojiID: string }; name: string } + ): Promise<unknown> { if ((!args || !args.emoji) && !message.attachments.size) return await message.util.reply(`${util.emojis.error} You must provide an emoji to steal.`); + client.console.debug(args, 5); const image = - message.attachments.size && message.attachments.first()!.contentType?.includes('image/') + (args?.emoji as any)?.matches && (args?.emoji as any)?.emojiID + ? `https://cdn.discordapp.com/emojis/${(args.emoji as any).emojiID}` + : typeof args.emoji === 'string' + ? `https://cdn.discordapp.com/emojis/${args.emoji}` + : typeof message.attachments.size && message.attachments.first()?.contentType?.includes('image/') ? message.attachments.first()!.url - : args?.emoji instanceof Emoji - ? `https://cdn.discordapp.com/emojis/${args.emoji.id}` : args?.emoji instanceof URL ? args.emoji.href : undefined; @@ -44,9 +54,13 @@ export default class StealCommand extends BushCommand { if (!image) return await message.util.reply(`${util.emojis.error} You must provide an emoji to steal.`); const creationSuccess = await message - .guild!.emojis.create(image, args.name, { - reason: `Stolen by ${message.author.tag} (${message.author.id})` - }) + .guild!.emojis.create( + image, + args.name === 'stolen emoji' && (args?.emoji as any)?.emojiName ? (args?.emoji as any)?.emojiName : args.name, + { + reason: `Stolen by ${message.author.tag} (${message.author.id})` + } + ) .catch((e: Error) => e); if (!(creationSuccess instanceof Error)) diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts index 3473ea4..dfba90c 100644 --- a/src/lib/models/Guild.ts +++ b/src/lib/models/Guild.ts @@ -15,6 +15,7 @@ export interface GuildModel { disabledCommands: string[]; lockdownChannels: Snowflake[]; autoModPhases: string[]; + enabledFeatures: string[]; } export interface GuildModelCreationAttributes { @@ -29,8 +30,20 @@ export interface GuildModelCreationAttributes { disabledCommands?: string[]; lockdownChannels?: Snowflake[]; autoModPhases?: string[]; + enabledFeatures?: string[]; } +export const guildSettings = { + prefix: { type: 'string' }, + autoPublishChannels: { type: 'channel-array' }, + welcomeChannel: { type: 'channel-array' }, + muteRole: { type: 'role' }, + punishmentEnding: { type: 'string' }, + lockdownChannels: { type: 'channel-array' } +}; + +export const guildFeatures = ['automodEnabled', 'supportThreads', 'stickyRoles']; + const NEVER_USED = 'This should never be executed'; export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> implements GuildModel { @@ -144,6 +157,16 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i throw new Error(NEVER_USED); } + /** + * The features enabled in a guild + */ + public get enabledFeatures(): string[] { + throw new Error(NEVER_USED); + } + public set enabledFeatures(_: string[]) { + throw new Error(NEVER_USED); + } + public static initModel(sequelize: Sequelize, client: BushClient): void { Guild.init( { @@ -233,6 +256,17 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i }, allowNull: false, defaultValue: '[]' + }, + enabledFeatures: { + type: DataTypes.TEXT, + get: function () { + return JSON.parse(this.getDataValue('enabledFeatures') as unknown as string); + }, + set: function (val: string[]) { + return this.setDataValue('enabledFeatures', JSON.stringify(val) as unknown as string[]); + }, + allowNull: false, + defaultValue: '[]' } }, { sequelize: sequelize } |