Skip to content

Commit da1a45c

Browse files
authored
Merge pull request #219 from Garlic-Team/dev
7.1.1
2 parents 6056d36 + c38fe28 commit da1a45c

File tree

6 files changed

+31
-21
lines changed

6 files changed

+31
-21
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gcommands",
3-
"version": "7.1.0",
3+
"version": "7.1.1",
44
"description": "Powerful and flexible command handler that can do everything!",
55
"main": "src/index.js",
66
"types": "./typings/index.d.ts",

src/commands/argument.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const MentionableArgumentType = require('./types/mentionable');
1111
const MessageActionRow = require('../structures/MessageActionRow');
1212
const MessageButton = require('../structures/MessageButton');
1313
const ButtonInteraction = require('../structures/ButtonInteraction');
14-
const { ArgumentChannelTypes } = require('../util/Constants');
1514
const ifDjsV13 = require('../util/util').checkDjsVersion(13);
1615

1716
/**
@@ -71,7 +70,7 @@ class Argument {
7170
* Channel Types
7271
* @type {ArgumentChannelTypes}
7372
*/
74-
this.channel_types = this.channelTypes;
73+
this.channel_types = argument.channel_types || [];
7574

7675
/**
7776
* SubCommands
@@ -87,17 +86,6 @@ class Argument {
8786
this.isNotDm = isNotDm;
8887
}
8988

90-
get channelTypes() {
91-
const types = this.argument.channel_types ? !Array.isArray(this.argument.channel_types) ? [this.argument.channel_types] : this.argument.channel_types : [];
92-
const final = [];
93-
94-
for (const type of types) {
95-
final.push(ArgumentChannelTypes[type]);
96-
}
97-
98-
return final;
99-
}
100-
10189
/**
10290
* Method to obtain
10391
* @param {Message|Object}

src/structures/CommandArgsOptionBuilder.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ class CommandArgsOptionBuilder {
4949
*/
5050
this.required = 'required' in data ? Boolean(data.required) : null;
5151

52+
/**
53+
* Channel types
54+
* @type {boolean}
55+
*/
56+
this.channel_types = 'channel_types' in data ? data.channel_types : null;
57+
5258
/**
5359
* Choices
5460
* @type {Array<CommandArgsChoice>}
@@ -109,6 +115,15 @@ class CommandArgsOptionBuilder {
109115
return this;
110116
}
111117

118+
/**
119+
* Method to setChannelTypes
120+
* @param {ArgumentChannelTypes} types
121+
*/
122+
setChannelTypes(types) {
123+
this.channel_types = types;
124+
return this;
125+
}
126+
112127
/**
113128
* Method to addChoice
114129
* @param {CommandArgsChoice} choice

src/structures/MessageButton.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class MessageButton extends BaseMessageComponent {
8484
* @param {string} style
8585
*/
8686
setStyle(style) {
87-
this.style = this.resolveStyle(resolveString(style.toLowerCase()));
87+
this.style = this.resolveStyle(style);
8888
return this;
8989
}
9090

@@ -121,6 +121,7 @@ class MessageButton extends BaseMessageComponent {
121121
*/
122122
setURL(url) {
123123
this.url = resolveString(url);
124+
this.style = 5;
124125
return this;
125126
}
126127

@@ -150,7 +151,7 @@ class MessageButton extends BaseMessageComponent {
150151
toJSON() {
151152
return {
152153
type: MessageComponentTypes.BUTTON,
153-
style: this.url ? 5 : this.style,
154+
style: this.style,
154155
label: this.label || '',
155156
disabled: this.disabled,
156157
url: this.url,
@@ -160,12 +161,14 @@ class MessageButton extends BaseMessageComponent {
160161
}
161162

162163
resolveStyle(style) {
163-
if (!style) throw new GError('[INVALID STYLE]','An invalid button styles was provided');
164+
if (!style) throw new GError('[INVALID STYLE]','An invalid button style was provided');
165+
166+
if (typeof style === 'number' && style >= 1 && style <= 5) return style;
167+
else if (typeof style === 'number') throw new GError('[INVALID STYLE]','An invalid button style was provided');
164168

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

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

170173
return styles[style] || style;
171174
}

src/util/Constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ function createEnum(keys) {
351351
* * GUILD_PUBLIC_THREAD
352352
* * GUILD_PRIVATE_THREAD
353353
* * GUILD_STAGE_VOICE
354-
* @typedef {(String)} ArgumentChannelTypes
354+
* @typedef {(string)} ArgumentChannelTypes
355355
*/
356356
module.exports.ArgumentChannelTypes = {
357357
DM: 1,

typings/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ declare module 'gcommands' {
258258
public description: String;
259259
public type: String;
260260
public prompt: String;
261+
public channelTypes: Array<ArgumentChannelTypes>;
261262
public required: Boolean;
262263
public choices: Array;
263264
public options: Array<CommandArgsOption>;
@@ -267,6 +268,7 @@ declare module 'gcommands' {
267268
public setType(type: String): CommandArgsOptionBuilder;
268269
public setPrompt(prompt: String): CommandArgsOptionBuilder;
269270
public setRequired(required: Boolean): CommandArgsOptionBuilder;
271+
public setChannelTypes(channelTypes: Array<ArgumentChannelTypes>): CommandArgsOptionBuilder;
270272
public addChoice(choice: CommandArgsChoice): CommandArgsOptionBuilder;
271273
public addChoices(choices: Array<CommandArgsChoice>): CommandArgsOptionBuilder;
272274
public addOption(option: CommandArgsOption): CommandArgsOptionBuilder;
@@ -527,6 +529,7 @@ declare module 'gcommands' {
527529
required?: boolean;
528530
choices?: CommandArgsChoice[];
529531
options?: CommandArgsOptions;
532+
channel_types?: ArgumentChannelTypes[];
530533
}
531534

532535
interface CommandArgsChoice {
@@ -535,7 +538,7 @@ declare module 'gcommands' {
535538
}
536539

537540
interface GPayloadOptions {
538-
content: [string | MessageEmbed];
541+
content: [string | object | MessageEmbed | MessageAttachment];
539542
embeds?: [MessageEmbed];
540543
components?: [MessageActionRow];
541544
attachments?: [MessageAttachment | MessageAttachment[]];
@@ -583,6 +586,7 @@ declare module 'gcommands' {
583586

584587
type GCommandsOptionsCommandsSlash = 'both' | 'slash' | 'message' | 'false';
585588
type GCommandsOptionsCommandsContext = 'both' | 'user' | 'message' | 'false';
589+
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';
586590

587591
interface EventOptions {
588592
name: string;

0 commit comments

Comments
 (0)