Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: AllowedMentions #66

Merged
merged 23 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/Core/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { TYPE_ERRORS } from '../Utility/Constants/AxonEnums';
* @typedef {import('../Utility/Discord/Embed').default} Embed
* @typedef {{ content?: String, embed?: Embed|EmbedBase }} MessageObject
* @typedef {{ guild: Guild|String, cmd: String, user: User|String}} Ctx
* @typedef {import('eris').AllowedMentions} ErisAllowedMentions
* @typedef {import('discord.js').AllowedMentions} DjsAllowedMentions
Khaaz marked this conversation as resolved.
Show resolved Hide resolved
* @typedef {ErisAllowedMentions | DjsAllowedMentions} AllowedMentions
*/

/**
Expand Down Expand Up @@ -169,7 +172,7 @@ class Base {
* @param {User} user - User object to get the DM channel
* @param {String|MessageObject} content - String or object (embed)
* @param {Object} [options={}] - Options { disableEveryone: Boolean, delete: Boolean, delay: Number }
* @param {Boolean} [options.disableEveryone=true] - Whether to allow mentioning everyone or not
* @param {AllowedMentions} [options.allowedMentions] - Custom allowed mentions object
* @param {Boolean} [options.delete=false] - Whether to delete the message or not
* @param {Number} [options.delay=null] - Delay after which the message will be deleted
* @returns {Promise<Message?>} Message Object
Expand All @@ -187,7 +190,7 @@ class Base {
* @param {Channel} channel - The channel Object
* @param {String|MessageObject} content - Message content, String or Embed Object
* @param {Object} [options={}] - Options { disableEveryone: Boolean, delete: Boolean, delay: Number }
* @param {Boolean} [options.disableEveryone=true] - Whether to allow mentioning everyone or not
* @param {AllowedMentions} [options.allowedMentions] - Custom allowed mentions object
* @param {Boolean} [options.delete=false] - Whether to delete the message or not
* @param {Number} [options.delay=null] - Delay after which the message will be deleted
* @returns {Promise<Message?>} Message Object
Expand Down Expand Up @@ -218,7 +221,7 @@ class Base {
* @param {Channel} channel - The channel Object
* @param {String|MessageObject} content - Success message content
* @param {Object} [options={}] - Additional options
* @param {Boolean} [options.disableEveryone=true] - Whether to allow mentioning everyone or not
* @param {AllowedMentions} [options.allowedMentions] - Custom allowed mentions object
* @param {Boolean} [options.delete=false] - Whether to delete the message or not
* @param {Number} [options.delay=null] - Delay after which the message will be deleted
* @param {Boolean} [options.triggerCooldown=true] - Whether the command should trigger cooldown or not
Expand All @@ -243,7 +246,7 @@ class Base {
* @param {Channel} channel - The channel Object
* @param {String|MessageObject} content - Success message content
* @param {Object} [options={}] - Additional options
* @param {Boolean} [options.disableEveryone=true] - Whether to allow mentioning everyone or not
* @param {AllowedMentions} [options.allowedMentions] - Custom allowed mentions object
* @param {Boolean} [options.delete=false] - Whether to delete the message or not
* @param {Number} [options.delay=null] - Delay after which the message will be deleted
* @param {Boolean} [options.triggerCooldown=false] - Whether the command should trigger cooldown or not
Expand Down
5 changes: 3 additions & 2 deletions src/Libraries/discordjs/lib/DjsChannel.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import Channel from '../../definitions/Channel';

/**
* @typedef {import('discord.js').AllowedMentions} AllowedMentions
Khaaz marked this conversation as resolved.
Show resolved Hide resolved
* @typedef {import('discord.js').Channel} channel
* @typedef {import('discord.js').User} user
* @typedef {{
* content?: String, tts?: Boolean, nonce?: String, embed?: Embed|import('discord.js').MessageEmbed|import('discord.js').MessageEmbedOptions, disableEveryone?: Boolean,
* content?: String, tts?: Boolean, nonce?: String, embed?: Embed|import('discord.js').MessageEmbed|import('discord.js').MessageEmbedOptions,
* files?: Array<import('discord.js').FileOptions|import('discord.js').BufferResolvable|import('discord.js').MessageAttachment>, code?: String|Boolean,
* split?: Boolean|import('discord.js').SplitOptions, reply?: import('discord.js').UserResolvable
* split?: Boolean|import('discord.js').SplitOptions, reply?: import('discord.js').UserResolvable, allowedMentions: AllowedMentions
* }} DjsContent
* @typedef {import('../../../Utility/Discord/Embed').default} Embed
* @typedef {import('discord.js').Message} message
Expand Down
3 changes: 2 additions & 1 deletion src/Libraries/eris/lib/ErisChannel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Channel from '../../definitions/Channel';

/**
* @typedef {import('eris').AllowedMentions} AllowedMentions
* @typedef {import('eris').GuildChannel} gchannel
* @typedef {import('eris').User} User
* @typedef {
Expand All @@ -12,7 +13,7 @@ import Channel from '../../definitions/Channel';
* @typedef {import('eris').TextableChannel} channel
* @typedef {import('eris').Message} Message
* @typedef {{
* content?: String, tts?: Boolean, disableEveryone?: Boolean, embed?: Embed|EmbedOptions, file: MessageFile|Array<MessageFile>
* content?: String, tts?: Boolean, allowedMentions?: AllowedMentions, embed?: Embed|EmbedOptions, file: MessageFile|Array<MessageFile>
* }} ErisContent
* @typedef {import('../../../Utility/Discord/Embed').default} Embed
* @typedef {import('eris').EmbedOptions} EmbedOptions
Expand Down
12 changes: 9 additions & 3 deletions src/Utility/AxonUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import Validator from '../Core/Validator';
* @typedef {import('../Libraries/definitions/LibraryInterface').default} LibraryInterface
* @typedef {import('../Core/Models/GuildConfig').default} GuildConfig
* @typedef {import('../Loggers/ALogger').default} ALogger
* @typedef {import('eris').AllowedMentions} ErisAllowedMentions
* @typedef {import('discord.js').AllowedMentions} DjsAllowedMentions
Khaaz marked this conversation as resolved.
Show resolved Hide resolved
* @typedef {ErisAllowedMentions | DjsAllowedMentions} AllowedMentions
*/

/**
Expand Down Expand Up @@ -247,7 +250,7 @@ class AxonUtils {
* @param {User} user - User object to get the DM channel
* @param {String|MessageObject} content - String or object (embed)
* @param {Object} [options={}] - Options { disableEveryone: Boolean, delete: Boolean, delay: Number }
* @param {Boolean} [options.disableEveryone=true] - Whether to allow mentioning everyone or not
* @param {AllowedMentions} [options.allowedMentions] - Custom allowed mentions object
* @param {Boolean} [options.delete=false] - Whether to delete the message or not
* @param {Number} [options.delay=null] - Delay after which the message will be deleted
* @returns {Promise<Message?>} Message Object
Expand All @@ -270,7 +273,7 @@ class AxonUtils {
* @param {Channel} channel - The channel Object
* @param {String|MessageObject} content - Message content: String or Embed Object
* @param {Object} [options={}] - Options { disableEveryone: Boolean, delete: Boolean, delay: Number }
* @param {Boolean} [options.disableEveryone=true] - Whether to allow mentioning everyone or not
* @param {AllowedMentions} [options.allowedMentions] - Custom allowed mentions object
* @param {Boolean} [options.delete=false] - Whether to delete the message or not
* @param {Number} [options.delay=null] - Delay after which the message will be deleted
* @returns {Promise<Message?>} Message Object
Expand All @@ -296,8 +299,11 @@ class AxonUtils {
if (typeof content !== 'object' || content === null) {
content = { content: `${content}` };
}
content.disableEveryone = !!options.disableEveryone;

if (options.allowedMentions) {
content.allowedMentions = options.allowedMentions;
}

return this.library.channel.sendMessage(channel, content)
.then(message => {
/* Delete the message automatically */
Expand Down