Skip to content

Commit

Permalink
Merge pull request #219 from Garlic-Team/dev
Browse files Browse the repository at this point in the history
7.1.1
  • Loading branch information
xhyrom authored Oct 9, 2021
2 parents 6056d36 + c38fe28 commit da1a45c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gcommands",
"version": "7.1.0",
"version": "7.1.1",
"description": "Powerful and flexible command handler that can do everything!",
"main": "src/index.js",
"types": "./typings/index.d.ts",
Expand Down
14 changes: 1 addition & 13 deletions src/commands/argument.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const MentionableArgumentType = require('./types/mentionable');
const MessageActionRow = require('../structures/MessageActionRow');
const MessageButton = require('../structures/MessageButton');
const ButtonInteraction = require('../structures/ButtonInteraction');
const { ArgumentChannelTypes } = require('../util/Constants');
const ifDjsV13 = require('../util/util').checkDjsVersion(13);

/**
Expand Down Expand Up @@ -71,7 +70,7 @@ class Argument {
* Channel Types
* @type {ArgumentChannelTypes}
*/
this.channel_types = this.channelTypes;
this.channel_types = argument.channel_types || [];

/**
* SubCommands
Expand All @@ -87,17 +86,6 @@ class Argument {
this.isNotDm = isNotDm;
}

get channelTypes() {
const types = this.argument.channel_types ? !Array.isArray(this.argument.channel_types) ? [this.argument.channel_types] : this.argument.channel_types : [];
const final = [];

for (const type of types) {
final.push(ArgumentChannelTypes[type]);
}

return final;
}

/**
* Method to obtain
* @param {Message|Object}
Expand Down
15 changes: 15 additions & 0 deletions src/structures/CommandArgsOptionBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class CommandArgsOptionBuilder {
*/
this.required = 'required' in data ? Boolean(data.required) : null;

/**
* Channel types
* @type {boolean}
*/
this.channel_types = 'channel_types' in data ? data.channel_types : null;

/**
* Choices
* @type {Array<CommandArgsChoice>}
Expand Down Expand Up @@ -109,6 +115,15 @@ class CommandArgsOptionBuilder {
return this;
}

/**
* Method to setChannelTypes
* @param {ArgumentChannelTypes} types
*/
setChannelTypes(types) {
this.channel_types = types;
return this;
}

/**
* Method to addChoice
* @param {CommandArgsChoice} choice
Expand Down
13 changes: 8 additions & 5 deletions src/structures/MessageButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class MessageButton extends BaseMessageComponent {
* @param {string} style
*/
setStyle(style) {
this.style = this.resolveStyle(resolveString(style.toLowerCase()));
this.style = this.resolveStyle(style);
return this;
}

Expand Down Expand Up @@ -121,6 +121,7 @@ class MessageButton extends BaseMessageComponent {
*/
setURL(url) {
this.url = resolveString(url);
this.style = 5;
return this;
}

Expand Down Expand Up @@ -150,7 +151,7 @@ class MessageButton extends BaseMessageComponent {
toJSON() {
return {
type: MessageComponentTypes.BUTTON,
style: this.url ? 5 : this.style,
style: this.style,
label: this.label || '',
disabled: this.disabled,
url: this.url,
Expand All @@ -160,12 +161,14 @@ class MessageButton extends BaseMessageComponent {
}

resolveStyle(style) {
if (!style) throw new GError('[INVALID STYLE]','An invalid button styles was provided');
if (!style) throw new GError('[INVALID STYLE]','An invalid button style was provided');

if (typeof style === 'number' && style >= 1 && style <= 5) return style;
else if (typeof style === 'number') throw new GError('[INVALID STYLE]','An invalid button style was provided');

if (typeof style === 'string') style = style.toLowerCase();
if (typeof style === 'number') style = Object.keys(styles)[style];

if (!styles[style]) throw new GError('[INVALID STYLE]','An invalid button styles was provided');
if (!styles[style]) throw new GError('[INVALID STYLE]','An invalid button style was provided');

return styles[style] || style;
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function createEnum(keys) {
* * GUILD_PUBLIC_THREAD
* * GUILD_PRIVATE_THREAD
* * GUILD_STAGE_VOICE
* @typedef {(String)} ArgumentChannelTypes
* @typedef {(string)} ArgumentChannelTypes
*/
module.exports.ArgumentChannelTypes = {
DM: 1,
Expand Down
6 changes: 5 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ declare module 'gcommands' {
public description: String;
public type: String;
public prompt: String;
public channelTypes: Array<ArgumentChannelTypes>;
public required: Boolean;
public choices: Array;
public options: Array<CommandArgsOption>;
Expand All @@ -267,6 +268,7 @@ declare module 'gcommands' {
public setType(type: String): CommandArgsOptionBuilder;
public setPrompt(prompt: String): CommandArgsOptionBuilder;
public setRequired(required: Boolean): CommandArgsOptionBuilder;
public setChannelTypes(channelTypes: Array<ArgumentChannelTypes>): CommandArgsOptionBuilder;
public addChoice(choice: CommandArgsChoice): CommandArgsOptionBuilder;
public addChoices(choices: Array<CommandArgsChoice>): CommandArgsOptionBuilder;
public addOption(option: CommandArgsOption): CommandArgsOptionBuilder;
Expand Down Expand Up @@ -527,6 +529,7 @@ declare module 'gcommands' {
required?: boolean;
choices?: CommandArgsChoice[];
options?: CommandArgsOptions;
channel_types?: ArgumentChannelTypes[];
}

interface CommandArgsChoice {
Expand All @@ -535,7 +538,7 @@ declare module 'gcommands' {
}

interface GPayloadOptions {
content: [string | MessageEmbed];
content: [string | object | MessageEmbed | MessageAttachment];
embeds?: [MessageEmbed];
components?: [MessageActionRow];
attachments?: [MessageAttachment | MessageAttachment[]];
Expand Down Expand Up @@ -583,6 +586,7 @@ declare module 'gcommands' {

type GCommandsOptionsCommandsSlash = 'both' | 'slash' | 'message' | 'false';
type GCommandsOptionsCommandsContext = 'both' | 'user' | 'message' | 'false';
type ArgumentChannelTypes = 'DM' | 'GUILD_TEXT' | 'GUILD_VOICE' | 'GUILD_CATEGORY' | 'GUILD_NEWS' | 'GUILD_STORE' | 'GUILD_NEWS_THREAD' | 'GUILD_PUBLIC_THREAD' | 'GUILD_PRIVATE_THREAD' | 'GUILD_STAGE_VOICE';

interface EventOptions {
name: string;
Expand Down

0 comments on commit da1a45c

Please sign in to comment.