Skip to content

Commit

Permalink
Added option allowed mentions | allowed_mentions FIX
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Apr 23, 2021
1 parent 8b88a73 commit 10f9fa7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 122 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": "1.0.26",
"version": "1.0.27",
"description": "Open-source slah command handler",
"main": "src/index.js",
"dependencies": {
Expand Down
124 changes: 3 additions & 121 deletions src/main/GCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ class Message extends Structures.get("Message") {
options.buttons = [];
}

if(!options.allowed_mentions) {
options.allowed_mentions = { parse: ["users", "roles", "everyone"] };
if(!options.allowedMentions) {
options.allowedMentions = { parse: ["users", "roles", "everyone"] };
}

if (!Array.isArray(options.buttons)) {
Expand Down Expand Up @@ -375,7 +375,7 @@ class Message extends Structures.get("Message") {
"Content-Type": 'applications/json'
},
data: {
allowed_mentions: options.allowed_mentions,
allowed_mentions: options.allowedMentions,
content: content,
components: [
{
Expand All @@ -389,124 +389,6 @@ class Message extends Structures.get("Message") {
});
}

async buttonsWithReply(content, options) {
if (!options.buttons) {
options.buttons = [];
}

if(!options.allowed_mentions) {
options.allowed_mentions = { parse: ["users", "roles", "everyone"] };
}

if (!Array.isArray(options.buttons)) {
return console.log(new Color("&d[GCommands] &cThe buttons must be array.",{json:false}).getText());
}

let buttons = [];
let styles = ['blupurple', 'grey', 'green', 'red', 'url'];

options.buttons.forEach((x, i) => {
if (!x.style) x.style = 'blupurple';

if (!styles.includes(x.style)) {
return console.log(new Color(`&d[GCommands] &c#${i} button has invalid style, recived ${x.style}`,{json:false}).getText());
}

if (!x.label) {
return console.log(new Color(`&d[GCommands] &c#${i} don't has label!`,{json:false}).getText());
}

if (typeof (x.label) !== 'string') x.label = String(x.label);

if (x.style === 'url') {
if (!x.url) {
return console.log(new Color(`&d[GCommands] &cIf the button style is "url", you must provide url`,{json:false}).getText());
}
} else {
if (!x.id) {
return console.log(new Color(`&d[GCommands] &cIf the button style is not "url", you must provide custom id`,{json:false}).getText());
}
}

var style;

if (x.style === 'blupurple') {
style = 1;
} else if (x.style === 'grey') {
style = 2;
} else if (x.style === 'green') {
style = 3;
} else if (x.style === 'red') {
style = 4;
} else if (x.style === 'url') {
style = 5;
}

let data = {
type: 2,
style: style,
label: x.label,
custom_id: x.id || null,
url: x.url || null
}

buttons.push(data);
})

options.buttons === null;

this.client.ws.on('INTERACTION_CREATE', async (data) => {
let typeStyles = {
1: 'blupurple',
2: 'grey',
3: 'green',
4: 'red',
5: 'url'
};

await this.client.channels.cache.get(data.channel_id).messages.fetch();

var message;
try {
message = await this.client.channels.cache.get(data.channel_id).messages.cache.get(data.message.id);
} catch(e) {
message = await this.client.channels.cache.get(data.channel_id)
}

var clicker = await this.client.guilds.cache.get(data.guild_id).members.cache.get(data.member.user.id);

this.client.emit('clickButton', {
version: data.version,
type: data.type,
style: typeStyles[data.type],
token: data.token,
id: data.data.custom_id,
discordId: data.id,
applicationId: data.application_id,
clicker: clicker,
message
})
});

this.client.api.channels[this.channel.id].messages.post({
headers: {
"Content-Type": 'applications/json'
},
data: {
allowed_mentions: options.allowed_mentions,
content: content,
components: [
{
type: 1,
components: buttons
}
],
options,
embed: options.embed || null
}
}).then(d => this.client.actions.MessageCreate.handle(d).message);
}

async inlineReply(content, options) {
const mentionRepliedUser = typeof ((options || content || {}).allowedMentions || {}).repliedUser === "undefined" ? true : ((options || content).allowedMentions).repliedUser;
delete ((options || content || {}).allowedMentions || {}).repliedUser;
Expand Down

0 comments on commit 10f9fa7

Please sign in to comment.