From 8fab712f39f5e16ed8faffe3fb26a9ea2c4d92c5 Mon Sep 17 00:00:00 2001 From: Khaazz Date: Sun, 22 Mar 2020 15:12:20 +0100 Subject: [PATCH 01/13] feat: detritus support [WIP] --- src/Libraries/detritusjs/DetritusInterface.js | 81 +++++ .../handlers/ChannelCreateHandler.js | 9 + .../handlers/ChannelDeleteHandler.js | 9 + .../handlers/ChannelPinsUpdateHandler.js | 9 + .../handlers/ChannelUpdateHandler.js | 9 + .../detritusjs/handlers/GuildBanAddHandler.js | 9 + .../handlers/GuildBanRemoveHandler.js | 9 + .../detritusjs/handlers/GuildCreateHandler.js | 9 + .../detritusjs/handlers/GuildDeleteHandler.js | 9 + .../handlers/GuildEmojisUpdateHandler.js | 9 + .../handlers/GuildMemberAddHandler.js | 9 + .../handlers/GuildMemberRemoveHandler.js | 9 + .../handlers/GuildMemberUpdateHandler.js | 9 + .../handlers/GuildMembersChunkHandler.js | 9 + .../detritusjs/handlers/GuildReadyHandler.js | 9 + .../handlers/GuildRoleCreateHandler.js | 9 + .../handlers/GuildRoleDeleteHandler.js | 9 + .../handlers/GuildRoleUpdateHandler.js | 9 + .../detritusjs/handlers/GuildUpdateHandler.js | 9 + .../handlers/InviteCreateHandler.js | 9 + .../handlers/InviteDeleteHandler.js | 9 + .../handlers/MessageCreateHandler.js | 11 + .../handlers/MessageDeleteBulkHandler.js | 12 + .../handlers/MessageDeleteHandler.js | 11 + .../handlers/MessageReactionAddHandler.js | 9 + .../MessageReactionRemoveAllHandler.js | 9 + .../MessageReactionRemoveEmojiHandler.js | 9 + .../handlers/MessageReactionRemoveHandler.js | 9 + .../handlers/MessageUpdateHandler.js | 11 + .../handlers/PresenceUpdateHandler.js | 9 + .../handlers/ShardGatewayDisconnectHandler.js | 11 + .../handlers/ShardGatewayReadyHandler.js | 9 + .../detritusjs/handlers/TypingStartHandler.js | 9 + .../detritusjs/handlers/UnknownHandler.js | 9 + .../detritusjs/handlers/UserUpdateHandler.js | 9 + .../handlers/VoiceServerUpdateHandler.js | 9 + .../handlers/VoiceStateUpdateHandler.js | 9 + .../handlers/WebhooksUpdateHandler.js | 9 + src/Libraries/detritusjs/handlers/index.js | 47 +++ .../detritusjs/lib/DetritusChannel.js | 14 + .../detritusjs/lib/DetritusClient.js | 33 ++ src/Libraries/detritusjs/lib/DetritusEnums.js | 301 ++++++++++++++++++ src/Libraries/detritusjs/lib/DetritusGuild.js | 20 ++ .../detritusjs/lib/DetritusMember.js | 46 +++ .../detritusjs/lib/DetritusMessage.js | 35 ++ .../detritusjs/lib/DetritusResolver.js | 203 ++++++++++++ src/Libraries/detritusjs/lib/DetritusUser.js | 19 ++ 47 files changed, 1143 insertions(+) create mode 100644 src/Libraries/detritusjs/DetritusInterface.js create mode 100644 src/Libraries/detritusjs/handlers/ChannelCreateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/ChannelDeleteHandler.js create mode 100644 src/Libraries/detritusjs/handlers/ChannelPinsUpdateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/ChannelUpdateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/GuildBanAddHandler.js create mode 100644 src/Libraries/detritusjs/handlers/GuildBanRemoveHandler.js create mode 100644 src/Libraries/detritusjs/handlers/GuildCreateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/GuildDeleteHandler.js create mode 100644 src/Libraries/detritusjs/handlers/GuildEmojisUpdateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/GuildMemberAddHandler.js create mode 100644 src/Libraries/detritusjs/handlers/GuildMemberRemoveHandler.js create mode 100644 src/Libraries/detritusjs/handlers/GuildMemberUpdateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/GuildMembersChunkHandler.js create mode 100644 src/Libraries/detritusjs/handlers/GuildReadyHandler.js create mode 100644 src/Libraries/detritusjs/handlers/GuildRoleCreateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/GuildRoleDeleteHandler.js create mode 100644 src/Libraries/detritusjs/handlers/GuildRoleUpdateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/GuildUpdateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/InviteCreateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/InviteDeleteHandler.js create mode 100644 src/Libraries/detritusjs/handlers/MessageCreateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/MessageDeleteBulkHandler.js create mode 100644 src/Libraries/detritusjs/handlers/MessageDeleteHandler.js create mode 100644 src/Libraries/detritusjs/handlers/MessageReactionAddHandler.js create mode 100644 src/Libraries/detritusjs/handlers/MessageReactionRemoveAllHandler.js create mode 100644 src/Libraries/detritusjs/handlers/MessageReactionRemoveEmojiHandler.js create mode 100644 src/Libraries/detritusjs/handlers/MessageReactionRemoveHandler.js create mode 100644 src/Libraries/detritusjs/handlers/MessageUpdateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/PresenceUpdateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/ShardGatewayDisconnectHandler.js create mode 100644 src/Libraries/detritusjs/handlers/ShardGatewayReadyHandler.js create mode 100644 src/Libraries/detritusjs/handlers/TypingStartHandler.js create mode 100644 src/Libraries/detritusjs/handlers/UnknownHandler.js create mode 100644 src/Libraries/detritusjs/handlers/UserUpdateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/VoiceServerUpdateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/VoiceStateUpdateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/WebhooksUpdateHandler.js create mode 100644 src/Libraries/detritusjs/handlers/index.js create mode 100644 src/Libraries/detritusjs/lib/DetritusChannel.js create mode 100644 src/Libraries/detritusjs/lib/DetritusClient.js create mode 100644 src/Libraries/detritusjs/lib/DetritusEnums.js create mode 100644 src/Libraries/detritusjs/lib/DetritusGuild.js create mode 100644 src/Libraries/detritusjs/lib/DetritusMember.js create mode 100644 src/Libraries/detritusjs/lib/DetritusMessage.js create mode 100644 src/Libraries/detritusjs/lib/DetritusResolver.js create mode 100644 src/Libraries/detritusjs/lib/DetritusUser.js diff --git a/src/Libraries/detritusjs/DetritusInterface.js b/src/Libraries/detritusjs/DetritusInterface.js new file mode 100644 index 00000000..12f12848 --- /dev/null +++ b/src/Libraries/detritusjs/DetritusInterface.js @@ -0,0 +1,81 @@ +import LibraryInterface from '../definitions/LibraryInterface'; + +import * as HANDLERS from './handlers/index'; + +import DetritusEnums from './lib/DetritusEnums'; + +import DetritusClient from './lib/DetritusClient'; +import DetritusUser from './lib/DetritusUser'; +import DetritusMember from './lib/DetritusMember'; +import DetritusMessage from './lib/DetritusMessage'; +import DetritusChannel from './lib/DetritusChannel'; +import DetritusGuild from './lib/DetritusGuild'; +import DetritusResolver from './lib/DetritusResolver'; + +class DetritusInterface extends LibraryInterface { + /** + * @param {Client} botClient + */ + constructor(botClient) { + super(botClient, { + User: DetritusUser, + Member: DetritusMember, + Message: DetritusMessage, + Channel: DetritusChannel, + Guild: DetritusGuild, + Resolver: DetritusResolver, + } ); + + this.client = new DetritusClient(this); + this.type = 0; + } + + get enums() { + return DetritusEnums; + } + + get HANDLERS() { + return HANDLERS; + } + + onMessageCreate(func) { + this.botClient.on(this.enums.EVENTS.MESSAGE_CREATE, ( { message } ) => { + func(message); + } ); + } + + onceReady(func) { + this.botClient.once('gatewayReady', () => { + func(); + } ); + } + + /** + * @param {(msg: Message) => void} + * @returns {({ message: Message }) => void} + * @memberof DetritusInterface + */ + getMessageCreate(func) { + return ( { message } ) => func(message); + } + + /** + * @param {(msg: Message) => void} + * @returns {({ differences, message: Message) => void} + * @memberof DetritusInterface + */ + getMessageUpdate(func) { + return ( { differences, message } ) => func(differences, message); + } + + /** + * @param {(msg: Message) => void} + * @returns {({ message: Message}) => void} + * @memberof DetritusInterface + */ + getMessageDelete(func) { + return ( { message } ) => func(message); + } +} + +export default DetritusInterface; diff --git a/src/Libraries/detritusjs/handlers/ChannelCreateHandler.js b/src/Libraries/detritusjs/handlers/ChannelCreateHandler.js new file mode 100644 index 00000000..e53feb5c --- /dev/null +++ b/src/Libraries/detritusjs/handlers/ChannelCreateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class ChannelCreateHandler extends AHandler { + handle( { channel } ) { + return channel.guild ? channel.guild.id : null; + } +} + +export default ChannelCreateHandler; diff --git a/src/Libraries/detritusjs/handlers/ChannelDeleteHandler.js b/src/Libraries/detritusjs/handlers/ChannelDeleteHandler.js new file mode 100644 index 00000000..24398a9a --- /dev/null +++ b/src/Libraries/detritusjs/handlers/ChannelDeleteHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class ChannelDeleteHandler extends AHandler { + handle( { channel } ) { + return channel.guild ? channel.guild.id : null; + } +} + +export default ChannelDeleteHandler; diff --git a/src/Libraries/detritusjs/handlers/ChannelPinsUpdateHandler.js b/src/Libraries/detritusjs/handlers/ChannelPinsUpdateHandler.js new file mode 100644 index 00000000..eeff3e74 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/ChannelPinsUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class ChannelPinsUpdateHandler extends AHandler { + handle( { channel } ) { + return channel.guild ? channel.guild.id : null; + } +} + +export default ChannelPinsUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/ChannelUpdateHandler.js b/src/Libraries/detritusjs/handlers/ChannelUpdateHandler.js new file mode 100644 index 00000000..7a7895ee --- /dev/null +++ b/src/Libraries/detritusjs/handlers/ChannelUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class ChannelUpdateHandler extends AHandler { + handle( { channel } ) { + return channel.guild ? channel.guild.id : null; + } +} + +export default ChannelUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildBanAddHandler.js b/src/Libraries/detritusjs/handlers/GuildBanAddHandler.js new file mode 100644 index 00000000..86b4cbeb --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildBanAddHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class GuildBanAddHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildBanAddHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildBanRemoveHandler.js b/src/Libraries/detritusjs/handlers/GuildBanRemoveHandler.js new file mode 100644 index 00000000..6ae6c767 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildBanRemoveHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class GuildBanRemoveHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildBanRemoveHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildCreateHandler.js b/src/Libraries/detritusjs/handlers/GuildCreateHandler.js new file mode 100644 index 00000000..f606a2a2 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildCreateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class GuildCreateHandler extends AHandler { + handle( { guild } ) { + return guild.id; + } +} + +export default GuildCreateHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildDeleteHandler.js b/src/Libraries/detritusjs/handlers/GuildDeleteHandler.js new file mode 100644 index 00000000..8424efe6 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildDeleteHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class GuildDeleteHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildDeleteHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildEmojisUpdateHandler.js b/src/Libraries/detritusjs/handlers/GuildEmojisUpdateHandler.js new file mode 100644 index 00000000..34df385b --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildEmojisUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class GuildEmojisUpdateHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildEmojisUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildMemberAddHandler.js b/src/Libraries/detritusjs/handlers/GuildMemberAddHandler.js new file mode 100644 index 00000000..96e064c1 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildMemberAddHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class GuildMemberAddHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildMemberAddHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildMemberRemoveHandler.js b/src/Libraries/detritusjs/handlers/GuildMemberRemoveHandler.js new file mode 100644 index 00000000..98d86e30 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildMemberRemoveHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class GuildMemberRemoveHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildMemberRemoveHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildMemberUpdateHandler.js b/src/Libraries/detritusjs/handlers/GuildMemberUpdateHandler.js new file mode 100644 index 00000000..cfc87708 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildMemberUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class GuildMemberUpdateHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildMemberUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildMembersChunkHandler.js b/src/Libraries/detritusjs/handlers/GuildMembersChunkHandler.js new file mode 100644 index 00000000..2eef4c63 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildMembersChunkHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class GuildMembersChunkHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildMembersChunkHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildReadyHandler.js b/src/Libraries/detritusjs/handlers/GuildReadyHandler.js new file mode 100644 index 00000000..19f94a50 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildReadyHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class GuildReadyHandler extends AHandler { + handle( { guild } ) { + return guild.id; + } +} + +export default GuildReadyHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildRoleCreateHandler.js b/src/Libraries/detritusjs/handlers/GuildRoleCreateHandler.js new file mode 100644 index 00000000..0dcd3def --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildRoleCreateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class GuildRoleCreateHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildRoleCreateHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildRoleDeleteHandler.js b/src/Libraries/detritusjs/handlers/GuildRoleDeleteHandler.js new file mode 100644 index 00000000..f44300ed --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildRoleDeleteHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class GuildRoleDeleteHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildRoleDeleteHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildRoleUpdateHandler.js b/src/Libraries/detritusjs/handlers/GuildRoleUpdateHandler.js new file mode 100644 index 00000000..e10a6bd4 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildRoleUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class GuildRoleUpdateHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default GuildRoleUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/GuildUpdateHandler.js b/src/Libraries/detritusjs/handlers/GuildUpdateHandler.js new file mode 100644 index 00000000..2b594f96 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/GuildUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class GuildUpdateHandler extends AHandler { + handle( { guild } ) { + return guild.id; + } +} + +export default GuildUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/InviteCreateHandler.js b/src/Libraries/detritusjs/handlers/InviteCreateHandler.js new file mode 100644 index 00000000..c9b43802 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/InviteCreateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class InviteCreateHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default InviteCreateHandler; diff --git a/src/Libraries/detritusjs/handlers/InviteDeleteHandler.js b/src/Libraries/detritusjs/handlers/InviteDeleteHandler.js new file mode 100644 index 00000000..996ed388 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/InviteDeleteHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class InviteDeleteHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default InviteDeleteHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageCreateHandler.js b/src/Libraries/detritusjs/handlers/MessageCreateHandler.js new file mode 100644 index 00000000..79b95533 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageCreateHandler.js @@ -0,0 +1,11 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class MessageCreateHandler extends AHandler { + handle( { message } ) { + return (message.channel && message.channel.guild) + ? message.channel.guild.id + : null; + } +} + +export default MessageCreateHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageDeleteBulkHandler.js b/src/Libraries/detritusjs/handlers/MessageDeleteBulkHandler.js new file mode 100644 index 00000000..c2c2238a --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageDeleteBulkHandler.js @@ -0,0 +1,12 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class MessageDeleteBulkHandler extends AHandler { + handle( { messages } ) { + const firstMessage = messages.first(); + return (messages.size > 0 && firstMessage && firstMessage.channel && firstMessage.channel.guild) + ? messages.channel.guild.id + : null; + } +} + +export default MessageDeleteBulkHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageDeleteHandler.js b/src/Libraries/detritusjs/handlers/MessageDeleteHandler.js new file mode 100644 index 00000000..9ce00f0a --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageDeleteHandler.js @@ -0,0 +1,11 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class MessageDeleteHandler extends AHandler { + handle( { message } ) { + return (message && message.channel && message.channel.guild) + ? message.channel.guild.id + : null; + } +} + +export default MessageDeleteHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageReactionAddHandler.js b/src/Libraries/detritusjs/handlers/MessageReactionAddHandler.js new file mode 100644 index 00000000..d6c78055 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageReactionAddHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class MessageReactionAddHandler extends AHandler { + handle( { guildId } ) { + return guildId || null; + } +} + +export default MessageReactionAddHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageReactionRemoveAllHandler.js b/src/Libraries/detritusjs/handlers/MessageReactionRemoveAllHandler.js new file mode 100644 index 00000000..d792e2bf --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageReactionRemoveAllHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class MessageReactionRemoveAllHandler extends AHandler { + handle( { guildId } ) { + return guildId || null; + } +} + +export default MessageReactionRemoveAllHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageReactionRemoveEmojiHandler.js b/src/Libraries/detritusjs/handlers/MessageReactionRemoveEmojiHandler.js new file mode 100644 index 00000000..362713e2 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageReactionRemoveEmojiHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class MessageReactionRemoveEmojiHandler extends AHandler { + handle( { guildId } ) { + return guildId || null; + } +} + +export default MessageReactionRemoveEmojiHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageReactionRemoveHandler.js b/src/Libraries/detritusjs/handlers/MessageReactionRemoveHandler.js new file mode 100644 index 00000000..88569467 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageReactionRemoveHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class MessageReactionRemoveHandler extends AHandler { + handle( { guildId } ) { + return guildId | null; + } +} + +export default MessageReactionRemoveHandler; diff --git a/src/Libraries/detritusjs/handlers/MessageUpdateHandler.js b/src/Libraries/detritusjs/handlers/MessageUpdateHandler.js new file mode 100644 index 00000000..24632838 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/MessageUpdateHandler.js @@ -0,0 +1,11 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class MessageUpdateHandler extends AHandler { + handle( { message } ) { + return (message && message.channel && message.channel.guild) + ? message.channel.guild.id + : null; + } +} + +export default MessageUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/PresenceUpdateHandler.js b/src/Libraries/detritusjs/handlers/PresenceUpdateHandler.js new file mode 100644 index 00000000..16bc7521 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/PresenceUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class PresenceUpdateHandler extends AHandler { + handle( { guildId } ) { + return guildId || null; + } +} + +export default PresenceUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/ShardGatewayDisconnectHandler.js b/src/Libraries/detritusjs/handlers/ShardGatewayDisconnectHandler.js new file mode 100644 index 00000000..22a318e3 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/ShardGatewayDisconnectHandler.js @@ -0,0 +1,11 @@ +/* import AHandler from '../../../Structures/Event/AHandler'; + +class ShardGatewayDisconnectHandler extends AHandler { + handle() { + return null; + } +} + +export default ShardGatewayDisconnectHandler; */ + +// this event is not yet added diff --git a/src/Libraries/detritusjs/handlers/ShardGatewayReadyHandler.js b/src/Libraries/detritusjs/handlers/ShardGatewayReadyHandler.js new file mode 100644 index 00000000..7e435647 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/ShardGatewayReadyHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class ShardGatewayReadyHandler extends AHandler { + handle() { + return null; + } +} + +export default ShardGatewayReadyHandler; diff --git a/src/Libraries/detritusjs/handlers/TypingStartHandler.js b/src/Libraries/detritusjs/handlers/TypingStartHandler.js new file mode 100644 index 00000000..0347d634 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/TypingStartHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class TypingStartHandler extends AHandler { + handle( { guildId } ) { + return guildId || null; + } +} + +export default TypingStartHandler; diff --git a/src/Libraries/detritusjs/handlers/UnknownHandler.js b/src/Libraries/detritusjs/handlers/UnknownHandler.js new file mode 100644 index 00000000..d204e0c0 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/UnknownHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class UnknownHandler extends AHandler { + handle() { + return null; + } +} + +export default UnknownHandler; diff --git a/src/Libraries/detritusjs/handlers/UserUpdateHandler.js b/src/Libraries/detritusjs/handlers/UserUpdateHandler.js new file mode 100644 index 00000000..9aef86ca --- /dev/null +++ b/src/Libraries/detritusjs/handlers/UserUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class UserUpdateHandler extends AHandler { + handle() { + return null; + } +} + +export default UserUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/VoiceServerUpdateHandler.js b/src/Libraries/detritusjs/handlers/VoiceServerUpdateHandler.js new file mode 100644 index 00000000..3eeb720f --- /dev/null +++ b/src/Libraries/detritusjs/handlers/VoiceServerUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class VoiceServerUpdateHandler extends AHandler { + handle( { guildId } ) { + return guildId || null; + } +} + +export default VoiceServerUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/VoiceStateUpdateHandler.js b/src/Libraries/detritusjs/handlers/VoiceStateUpdateHandler.js new file mode 100644 index 00000000..06521bbb --- /dev/null +++ b/src/Libraries/detritusjs/handlers/VoiceStateUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class VoiceStateUpdateHandler extends AHandler { + handle( { voiceState } ) { + return voiceState.guild.id || null; + } +} + +export default VoiceStateUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/WebhooksUpdateHandler.js b/src/Libraries/detritusjs/handlers/WebhooksUpdateHandler.js new file mode 100644 index 00000000..c7268e40 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/WebhooksUpdateHandler.js @@ -0,0 +1,9 @@ +import AHandler from '../../../Structures/Event/AHandler'; + +class WebhooksUpdateHandler extends AHandler { + handle( { guildId } ) { + return guildId; + } +} + +export default WebhooksUpdateHandler; diff --git a/src/Libraries/detritusjs/handlers/index.js b/src/Libraries/detritusjs/handlers/index.js new file mode 100644 index 00000000..d65d2a27 --- /dev/null +++ b/src/Libraries/detritusjs/handlers/index.js @@ -0,0 +1,47 @@ +export { default as channelCreate } from './ChannelCreateHandler'; +export { default as channelDelete } from './ChannelDeleteHandler'; +export { default as channelPinsUpdate } from './ChannelPinsUpdateHandler'; +export { default as channelUpdate } from './ChannelUpdateHandler'; + +export { default as guildBanAdd } from './GuildBanAddHandler'; +export { default as guildBanRemove } from './GuildBanRemoveHandler'; +export { default as guildCreate } from './GuildCreateHandler'; +export { default as guildDelete } from './GuildDeleteHandler'; +export { default as guildEmojisUpdate } from './GuildEmojisUpdateHandler'; +export { default as guildMemberAdd } from './GuildMemberAddHandler'; +export { default as guildMembersChunk } from './GuildMembersChunkHandler'; +export { default as guildMemberRemove } from './GuildMemberRemoveHandler'; +export { default as guildMemberUpdate } from './GuildMemberUpdateHandler'; +export { default as guildReady } from './GuildReadyHandler'; +export { default as guildRoleCreate } from './GuildRoleCreateHandler'; +export { default as guildRoleDelete } from './GuildRoleDeleteHandler'; +export { default as guildRoleUpdate } from './GuildRoleUpdateHandler'; +export { default as guildUpdate } from './GuildUpdateHandler'; + +export { default as inviteCreate } from './InviteCreateHandler'; +export { default as inviteDelete } from './InviteDeleteHandler'; + +export { default as messageCreate } from './MessageCreateHandler'; +export { default as messageDeleteBulk } from './MessageDeleteBulkHandler'; +export { default as messageDelete } from './MessageDeleteHandler'; +export { default as messageReactionAdd } from './MessageReactionAddHandler'; +export { default as messageReactionRemoveAll } from './MessageReactionRemoveAllHandler'; +export { default as messageReactionRemoveEmoji } from './MessageReactionRemoveEmojiHandler'; +export { default as messageReactionRemove } from './MessageReactionRemoveHandler'; +export { default as messageUpdate } from './MessageUpdateHandler'; + +export { default as presenceUpdate } from './PresenceUpdateHandler'; + +// export { default as shardGatewayDisconnect } from './ShardGatewayDisconnectHandler'; not implemented yet, see file +export { default as shardGatewayReady } from './ShardReadyHandler'; + +export { default as typingStart } from './TypingStartHandler'; + +export { default as unknown } from './UnknownHandler'; + +export { default as userUpdate } from './UserUpdateHandler'; + +export { default as voiceServerUpdate } from './VoiceServerUpdateHandler'; +export { default as voiceStateUpdate } from './VoiceStateUpdateHandler'; + +export { default as webhooksUpdate } from './WebhooksUpdateHandler'; diff --git a/src/Libraries/detritusjs/lib/DetritusChannel.js b/src/Libraries/detritusjs/lib/DetritusChannel.js new file mode 100644 index 00000000..b3be170e --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusChannel.js @@ -0,0 +1,14 @@ +import Channel from '../../definitions/Channel'; + +class DetritusChannel extends Channel { + hasPermission(channel, user, perm) { + return channel.can(perm, user); + } + + + sendMessage(channel, content) { + return channel.createMessage(content); + } +} + +export default DetritusChannel; diff --git a/src/Libraries/detritusjs/lib/DetritusClient.js b/src/Libraries/detritusjs/lib/DetritusClient.js new file mode 100644 index 00000000..be1769eb --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusClient.js @@ -0,0 +1,33 @@ +import Client from '../../definitions/Client'; + +class DetritusClient extends Client { + get client() { + return this.lib.botClient; + } + + getAvatar() { + return this.getUser() ? this.getUser().avatarUrl : null; + } + + getMember(guild) { + return guild.members.get(this.client.user.id); + } + + // **** METHODS **** // + + connect() { + return this.client.run(); + } + + setPresence(status, game) { + return this.client.gateway.setPresence( { status, game } ); + } + + triggerWebhook(id, token, data) { + return this.client + ? this.client.executeWebhook(id, token, data) + : super.triggerWebhook(id, token, data); + } +} + +export default DetritusClient; diff --git a/src/Libraries/detritusjs/lib/DetritusEnums.js b/src/Libraries/detritusjs/lib/DetritusEnums.js new file mode 100644 index 00000000..9f629c2a --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusEnums.js @@ -0,0 +1,301 @@ +/** + * @type {{ + * HELLO: '', + * READY: 'gatewayReady', + * RESUMED: 'gatewayResumed', + * RECONNECT: '', + * INVALID_SESSION: '', + * CHANNEL_CREATE: 'channelCreate', + * CHANNEL_UPDATE: 'channelUpdate', + * CHANNEL_DELETE: 'channelDelete', + * CHANNEL_PINS_UPDATE: 'channelPinsUpdate', + * GUILD_CREATE: 'guildCreate', + * GUILD_UPDATE: 'guildUpdate', + * GUILD_DELETE: 'guildDelete', + * GUILD_BAN_ADD: 'guildBanAdd', + * GUILD_BAN_REMOVE: 'guildBanRemove', + * GUILD_EMOJIS_UPDATE: 'guildEmojisUpdate', + * GUILD_INTEGRATIONS_UPDATE: '', + * GUILD_MEMBER_ADD: 'guildMemberAdd', + * GUILD_MEMBER_REMOVE: 'guildMemberRemove', + * GUILD_MEMBER_UPDATE: 'guildMemberUpdate', + * GUILD_MEMBERS_CHUNK: 'guildMembersChunk', + * GUILD_ROLE_CREATE: 'roleCreate', + * GUILD_ROLE_UPDATE: 'roleUpdate', + * GUILD_ROLE_DELETE: 'roleDelete', + * INVITE_CREATE: 'inviteCreate', + * INVITE_DELETE: 'inviteDelete', + * MESSAGE_CREATE: 'message', + * MESSAGE_UPDATE: 'messageUpdate', + * MESSAGE_DELETE: 'messageDelete', + * MESSAGE_DELETE_BULK: 'messageDeleteBulk', + * MESSAGE_REACTION_ADD: 'messageReactionAdd', + * MESSAGE_REACTION_REMOVE: 'messageReactionRemove', + * MESSAGE_REACTION_REMOVE_ALL: 'messageReactionRemoveAll', + * MESSAGE_REACTION_REMOVE_EMOJI: 'messageReactionRemoveEmoji', + * PRESENCE_UPDATE: 'presenceUpdate', + * TYPING_START: 'typingStart', + * USER_UPDATE: 'userUpdate', + * VOICE_STATE_UPDATE: 'voiceStateUpdate', + * VOICE_SERVER_UPDATE: 'voiceServerUpdate', + * WEBHOOKS_UPDATE: 'webhooksUpdate', + * }} + * @enum {String} + */ +export const EVENTS = { + HELLO: '', + READY: 'gatewayReady', + RESUMED: 'gatewayResumed', + RECONNECT: '', + INVALID_SESSION: '', + CHANNEL_CREATE: 'channelCreate', + CHANNEL_UPDATE: 'channelUpdate', + CHANNEL_DELETE: 'channelDelete', + CHANNEL_PINS_UPDATE: 'channelPinsUpdate', + GUILD_CREATE: 'guildCreate', + GUILD_UPDATE: 'guildUpdate', + GUILD_DELETE: 'guildDelete', + GUILD_BAN_ADD: 'guildBanAdd', + GUILD_BAN_REMOVE: 'guildBanRemove', + GUILD_EMOJIS_UPDATE: 'guildEmojisUpdate', + GUILD_INTEGRATIONS_UPDATE: '', + GUILD_MEMBER_ADD: 'guildMemberAdd', + GUILD_MEMBER_REMOVE: 'guildMemberRemove', + GUILD_MEMBER_UPDATE: 'guildMemberUpdate', + GUILD_MEMBERS_CHUNK: 'guildMembersChunk', + GUILD_ROLE_CREATE: 'roleCreate', + GUILD_ROLE_UPDATE: 'roleUpdate', + GUILD_ROLE_DELETE: 'roleDelete', + INVITE_CREATE: 'inviteCreate', + INVITE_DELETE: 'inviteDelete', + MESSAGE_CREATE: 'message', + MESSAGE_UPDATE: 'messageUpdate', + MESSAGE_DELETE: 'messageDelete', + MESSAGE_DELETE_BULK: 'messageDeleteBulk', + MESSAGE_REACTION_ADD: 'messageReactionAdd', + MESSAGE_REACTION_REMOVE: 'messageReactionRemove', + MESSAGE_REACTION_REMOVE_ALL: 'messageReactionRemoveAll', + MESSAGE_REACTION_REMOVE_EMOJI: 'messageReactionRemoveEmoji', + PRESENCE_UPDATE: 'presenceUpdate', + TYPING_START: 'typingStart', + USER_UPDATE: 'userUpdate', + VOICE_STATE_UPDATE: 'voiceStateUpdate', + VOICE_SERVER_UPDATE: 'voiceServerUpdate', + WEBHOOKS_UPDATE: 'webhooksUpdate', +}; + +/** + * @type {{ + * CREATE_INSTANT_INVITE: 'CREATE_INSTANT_INVITE', + * KICK_MEMBERS: 'KICK_MEMBERS', + * BAN_MEMBERS: 'BAN_MEMBERS', + * ADMINISTRATOR: 'ADMINISTRATOR', + * MANAGE_CHANNELS: 'MANAGE_CHANNELS', + * MANAGE_GUILD: 'MANAGE_GUILD', + * ADD_REACTIONS: 'ADD_REACTIONS', + * VIEW_AUDIT_LOG: 'VIEW_AUDIT_LOG', + * PRIORITY_SPEAKER: 'PRIORITY_SPEAKER', + * STREAM: 'STREAM', + * VIEW_CHANNEL: 'VIEW_CHANNEL', + * SEND_MESSAGES: 'SEND_MESSAGES', + * SEND_TTS_MESSAGES: 'SEND_TTS_MESSAGES', + * MANAGE_MESSAGES: 'MANAGE_MESSAGES', + * EMBED_LINKS: 'EMBED_LINKS', + * ATTACH_FILES: 'ATTACH_FILES', + * READ_MESSAGE_HISTORY: 'READ_MESSAGE_HISTORY', + * MENTION_EVERYONE: 'MENTION_EVERYONE', + * USE_EXTERNAL_EMOJIS: 'USE_EXTERNAL_EMOJIS', + * VIEW_GUILD_INSIGHTS: 'VIEW_GUILD_INSIGHTS', + * CONNECT: 'CONNECT', + * SPEAK: 'SPEAK', + * MUTE_MEMBERS: 'MUTE_MEMBERS', + * DEAFEN_MEMBERS: 'DEAFEN_MEMBERS', + * MOVE_MEMBERS: 'MOVE_MEMBERS', + * USE_VAD: 'USE_VAD', + * CHANGE_NICKNAME: 'CHANGE_NICKNAME', + * MANAGE_NICKNAMES: 'MANAGE_NICKNAMES', + * MANAGE_ROLES: 'MANAGE_ROLES', + * MANAGE_WEBHOOKS: 'MANAGE_WEBHOOKS', + * MANAGE_EMOJIS: 'MANAGE_EMOJIS', + * }} + * @enum {String} + */ +export const DISCORD_LIB_PERMISSIONS = { + CREATE_INSTANT_INVITE: 'CREATE_INSTANT_INVITE', + KICK_MEMBERS: 'KICK_MEMBERS', + BAN_MEMBERS: 'BAN_MEMBERS', + ADMINISTRATOR: 'ADMINISTRATOR', + MANAGE_CHANNELS: 'MANAGE_CHANNELS', + MANAGE_GUILD: 'MANAGE_GUILD', + ADD_REACTIONS: 'ADD_REACTIONS', + VIEW_AUDIT_LOG: 'VIEW_AUDIT_LOG', + PRIORITY_SPEAKER: 'PRIORITY_SPEAKER', + STREAM: 'STREAM', + VIEW_CHANNEL: 'VIEW_CHANNEL', + SEND_MESSAGES: 'SEND_MESSAGES', + SEND_TTS_MESSAGES: 'SEND_TTS_MESSAGES', + MANAGE_MESSAGES: 'MANAGE_MESSAGES', + EMBED_LINKS: 'EMBED_LINKS', + ATTACH_FILES: 'ATTACH_FILES', + READ_MESSAGE_HISTORY: 'READ_MESSAGE_HISTORY', + MENTION_EVERYONE: 'MENTION_EVERYONE', + USE_EXTERNAL_EMOJIS: 'USE_EXTERNAL_EMOJIS', + VIEW_GUILD_INSIGHTS: 'VIEW_GUILD_INSIGHTS', + CONNECT: 'CONNECT', + SPEAK: 'SPEAK', + MUTE_MEMBERS: 'MUTE_MEMBERS', + DEAFEN_MEMBERS: 'DEAFEN_MEMBERS', + MOVE_MEMBERS: 'MOVE_MEMBERS', + USE_VAD: 'USE_VAD', + CHANGE_NICKNAME: 'CHANGE_NICKNAME', + MANAGE_NICKNAMES: 'MANAGE_NICKNAMES', + MANAGE_ROLES: 'MANAGE_ROLES', + MANAGE_WEBHOOKS: 'MANAGE_WEBHOOKS', + MANAGE_EMOJIS: 'MANAGE_EMOJIS', +}; + +/** +* @type {[ + 'CREATE_INSTANT_INVITE', + 'KICK_MEMBERS', + 'BAN_MEMBERS', + 'ADMINISTRATOR', + 'MANAGE_CHANNELS', + 'MANAGE_GUILD', + 'ADD_REACTIONS', + 'VIEW_AUDIT_LOG', + 'PRIORITY_SPEAKER', + 'STREAM', + 'VIEW_CHANNEL', + 'SEND_MESSAGES', + 'SEND_TTS_MESSAGES', + 'MANAGE_MESSAGES', + 'EMBED_LINKS', + 'ATTACH_FILES', + 'READ_MESSAGE_HISTORY', + 'MENTION_EVERYONE', + 'USE_EXTERNAL_EMOJIS', + 'VIEW_GUILD_INSIGHTS', + 'CONNECT', + 'SPEAK', + 'MUTE_MEMBERS', + 'DEAFEN_MEMBERS', + 'MOVE_MEMBERS', + 'USE_VAD', + 'CHANGE_NICKNAME', + 'MANAGE_NICKNAMES', + 'MANAGE_ROLES', + 'MANAGE_WEBHOOKS', + 'MANAGE_EMOJIS', + * ]} + */ +export const PERMISSIONS = [ + 'CREATE_INSTANT_INVITE', + 'KICK_MEMBERS', + 'BAN_MEMBERS', + 'ADMINISTRATOR', + 'MANAGE_CHANNELS', + 'MANAGE_GUILD', + 'ADD_REACTIONS', + 'VIEW_AUDIT_LOG', + 'PRIORITY_SPEAKER', + 'STREAM', + 'VIEW_CHANNEL', + 'SEND_MESSAGES', + 'SEND_TTS_MESSAGES', + 'MANAGE_MESSAGES', + 'EMBED_LINKS', + 'ATTACH_FILES', + 'READ_MESSAGE_HISTORY', + 'MENTION_EVERYONE', + 'USE_EXTERNAL_EMOJIS', + 'VIEW_GUILD_INSIGHTS', + 'CONNECT', + 'SPEAK', + 'MUTE_MEMBERS', + 'DEAFEN_MEMBERS', + 'MOVE_MEMBERS', + 'USE_VAD', + 'CHANGE_NICKNAME', + 'MANAGE_NICKNAMES', + 'MANAGE_ROLES', + 'MANAGE_WEBHOOKS', + 'MANAGE_EMOJIS', +]; + +/** + * @type {{ + * CREATE_INSTANT_INVITE: 'Create Instant Invite', + * KICK_MEMBERS: 'Kick Members', + * BAN_MEMBERS: 'Ban Members', + * ADMINISTRATOR: 'Administrator', + * MANAGE_CHANNELS: 'Manage Channels', + * MANAGE_GUILD: 'Manage Guild', + * ADD_REACTIONS: 'Add Reactions', + * VIEW_AUDIT_LOG: 'View Audit Log', + * PRIORITY_SPEAKER: 'Priority Speaker', + * STREAM: 'Stream', + * VIEW_CHANNEL: 'Read Messages', + * SEND_MESSAGES: 'Send Messages', + * SEND_TTS_MESSAGES: 'Send TTS Messages', + * MANAGE_MESSAGES: 'Manage Messages', + * EMBED_LINKS: 'Embed Links', + * ATTACH_FILES: 'Attach Files', + * READ_MESSAGE_HISTORY: 'Read Message History', + * MENTION_EVERYONE: 'Mention Everyone', + * USE_EXTERNAL_EMOJIS: 'External Emojis', + * VIEW_GUILD_INSIGHTS: 'View Guild Insights', + * CONNECT: 'Voice Connect', + * SPEAK: 'Voice Speak', + * MUTE_MEMBERS: 'Voice Mute Members', + * DEAFEN_MEMBERS: 'Voice Deafen Members', + * MOVE_MEMBERS: 'Voice Move Members', + * USE_VAD: 'Voice Use VAD', + * CHANGE_NICKNAME: 'Change Nickname', + * MANAGE_NICKNAMES: 'Manage Nicknames', + * MANAGE_ROLES: 'Manage Roles', + * MANAGE_WEBHOOKS: 'Manage Webhooks', + * MANAGE_EMOJIS: 'Manage Emojis', + * }} + */ +export const PERMISSIONS_NAMES = { + CREATE_INSTANT_INVITE: 'Create Instant Invite', + KICK_MEMBERS: 'Kick Members', + BAN_MEMBERS: 'Ban Members', + ADMINISTRATOR: 'Administrator', + MANAGE_CHANNELS: 'Manage Channels', + MANAGE_GUILD: 'Manage Guild', + ADD_REACTIONS: 'Add Reactions', + VIEW_AUDIT_LOG: 'View Audit Log', + PRIORITY_SPEAKER: 'Priority Speaker', + STREAM: 'Stream', + VIEW_CHANNEL: 'Read Messages', + SEND_MESSAGES: 'Send Messages', + SEND_TTS_MESSAGES: 'Send TTS Messages', + MANAGE_MESSAGES: 'Manage Messages', + EMBED_LINKS: 'Embed Links', + ATTACH_FILES: 'Attach Files', + READ_MESSAGE_HISTORY: 'Read Message History', + MENTION_EVERYONE: 'Mention Everyone', + USE_EXTERNAL_EMOJIS: 'External Emojis', + VIEW_GUILD_INSIGHTS: 'View Guild Insights', + CONNECT: 'Voice Connect', + SPEAK: 'Voice Speak', + MUTE_MEMBERS: 'Voice Mute Members', + DEAFEN_MEMBERS: 'Voice Deafen Members', + MOVE_MEMBERS: 'Voice Move Members', + USE_VAD: 'Voice Use VAD', + CHANGE_NICKNAME: 'Change Nickname', + MANAGE_NICKNAMES: 'Manage Nicknames', + MANAGE_ROLES: 'Manage Roles', + MANAGE_WEBHOOKS: 'Manage Webhooks', + MANAGE_EMOJIS: 'Manage Emojis', +}; + +export default { + EVENTS, + DISCORD_LIB_PERMISSIONS, + PERMISSIONS, + PERMISSIONS_NAMES, +}; + diff --git a/src/Libraries/detritusjs/lib/DetritusGuild.js b/src/Libraries/detritusjs/lib/DetritusGuild.js new file mode 100644 index 00000000..ac1073b8 --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusGuild.js @@ -0,0 +1,20 @@ +import Guild from '../../definitions/Guild'; + +/** + * @typedef {import('eris').Guild} guild + * @typedef {import('eris').Member} Member + */ + +class DetritusGuild extends Guild { + /** + * @param {guild} guild + * @param {String} userID + * @returns {Member} + * @memberof ErisGuild + */ + getMember(guild, userID) { + return guild.members.get(userID); + } +} + +export default DetritusGuild; diff --git a/src/Libraries/detritusjs/lib/DetritusMember.js b/src/Libraries/detritusjs/lib/DetritusMember.js new file mode 100644 index 00000000..0bd21588 --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusMember.js @@ -0,0 +1,46 @@ +import Member from '../../definitions/Member'; + +/** + * @typedef {import('eris').Member} member + * @typedef { + * 'createInstantInvite' | 'kickMembers' | 'banMembers' | 'administrator' | 'manageChannels' | 'manageGuild' | + * 'addReactions' | 'viewAuditLog' | 'voicePrioritySpeaker' | 'stream' | 'readMessages' | 'sendMessages' | 'sendTTSMessages' | 'manageMessages' | + * 'embedLinks' | 'attachFiles' | 'readMessageHistory' | 'mentionEveryone' | 'externalEmojis' | 'voiceConnect' | 'voiceSpeak' | 'voiceMuteMembers' | + * 'voiceDeafenMembers' | 'voiceMoveMembers' | 'voiceUseVAD' | 'changeNickname' | 'manageNicknames' | 'manageRoles' | 'manageWebhooks' | 'manageEmojis' + * } ErisPermissions + * @typedef {import('eris').Role} Role + */ +class DetritusMember extends Member { + // **** GETTERS / SETTERS **** // + + /** + * @param {member} member + * @returns {Array} + * @memberof ErisMember + */ + getRoles(member) { + return member.roles; + } + + /** + * @param {member} member + * @returns {Array} + * @memberof ErisMember + */ + getRolesObject(member) { + const { guild } = member; + return member.roles.map(r => guild.roles.get(r) ); + } + + /** + * @param {member} member + * @param {ErisPermissions} permission + * @returns {Boolean} + * @memberof ErisMember + */ + hasPermission(member, permission) { + return member.permission.has(permission); + } +} + +export default DetritusMember; diff --git a/src/Libraries/detritusjs/lib/DetritusMessage.js b/src/Libraries/detritusjs/lib/DetritusMessage.js new file mode 100644 index 00000000..d84e752a --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusMessage.js @@ -0,0 +1,35 @@ +import Message from '../../definitions/Message'; + +/** + * @typedef {import('eris').Message} message + * @typedef {{ + * content?: String, tts?: Boolean, disableEveryone?: Boolean, embed?: Embed|EmbedOptions, file?: MessageFile|Array + * }} ErisContent + * @typedef {import('eris').EmbedOptions} EmbedOptions + * @typedef {import('eris').MessageFile} MessageFile + */ + +class DetritusMessage extends Message { + // **** METHODS **** // + + /** + * @param {message} message + * @returns {Promise} + * @memberof ErisMessage + */ + delete(message) { + return message.delete(); + } + + /** + * @param {message} message + * @param {ErisContent} content + * @returns {Promise} + * @memberof ErisMessage + */ + edit(message, content) { + return message.edit(content); + } +} + +export default DetritusMessage; diff --git a/src/Libraries/detritusjs/lib/DetritusResolver.js b/src/Libraries/detritusjs/lib/DetritusResolver.js new file mode 100644 index 00000000..0325b373 --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusResolver.js @@ -0,0 +1,203 @@ +import Resolver from '../../definitions/Resolver'; + +import Utils from '../../../Utility/Utils'; + +import AxonError from '../../../Errors/AxonError'; + +/** + * @typedef {import('eris').Client} Client + * @typedef {import('eris').User} User + * @typedef {import('eris').Member} Member + * @typedef {import('eris').Role} Role + * @typedef {import('eris').GuildChannel} Channel + * @typedef {import('eris').Guild} Guild + */ + +/** + * Static Resolver class for Eris.AxonCore + * + * @author KhaaZ + * + * @static + * @class ErisResolver + */ +class DetritusResolver extends Resolver { + /** + * Resolve a user within all the users the bot has. + * + * @param {Client} client - The bot client + * @param {Array|String} args - Array of arguments resolved by the command. + * @returns {User|null} The user object / Null if not found / Error + * @memberof ErisResolver + */ + static user(client, args) { + // Checking if all the arguments are supplied. + if (!args.length) { + throw new AxonError('All the arguments are either not given or false.', 'Resolver', 'User'); + } + // Checking if args is an array, if it is not, converting it to an array. + if (!Array.isArray(args) ) { + args = `${args}`.split(' '); + } + + args.all = args.join(' '); + args.lower = args.all.toLowerCase(); + const { users } = client; + + const mention = Utils.userMention.exec(args[0] ); + + const user = ( (mention && mention[1] ) && users.get(mention[1] ) ) // User mention + || (Utils.id.test(args[0] ) && users.get(args[0] ) ) // User ID + || (args.all.indexOf('#') > -1 && users.find(u => `${u.username}#${u.discriminator}` === args.all) ) // Username + discrim + || users.find(u => u.username === args.all) // Username + || users.find(u => u.username.toLowerCase() === args.lower) // Username lowercase + || users.find(u => u.username.includes(args.all) ) // Username includes + || users.find(u => u.username.toLowerCase().includes(args.lower) ) // Username lowercase includes + || null;// No users found + + return user; // Return the user object. + } + + /** + * Resolve a member within a guild. + * + * @param {Guild} guild - Object Guild resolved by the command. + * @param {Array|String} args - Array of arguments resolved by the command. + * @returns {Member|null} The member object / Null if not found / Error + * @memberof ErisResolver + */ + static member(guild, args) { + // Checking if all the arguments are supplied. + if (!guild || !args.length) { + throw new AxonError('All the arguments are either not given or false.', 'Resolver', 'Member'); + } + // Checking if args is an array, if it is not, converting it to an array. + if (!Array.isArray(args) ) { + args = `${args}`.split(' '); + } + + args.all = args.join(' '); + args.lower = args.all.toLowerCase(); + const { members } = guild; + + const mention = Utils.userMention.exec(args[0] ); + + const member = ( (mention && mention[1] ) && members.get(mention[1] ) ) // User mention + || (Utils.id.test(args[0] ) && members.get(args[0] ) ) // User ID + || (args.all.indexOf('#') > -1 && members.find(m => `${m.username}#${m.discriminator}` === args.all) ) // Username + discrim + || members.find(m => m.username === args.all) // Username + || members.find(m => m.nick === args.all) // nickname + || members.find(m => m.username.toLowerCase() === args.lower) // Username lowercase + || members.find(m => m.nick && m.nick.toLowerCase() === args.lower) // nickname lowercase + // members.find(m => m.username.includes(args.all) ) || // Username includes + // members.find(m => m.nick && m.nick.includes(args.all) ) || // nickname includes + || members.find(m => m.username.toLowerCase().includes(args.lower) ) // username lowercase includes + || members.find(m => m.nick && m.nick.toLowerCase().includes(args.lower) ) // nickname lowercase includes + || null; // No member found + + return member; // Return the member object. + } + + /** + * Resolve a role within a guild. + * + * @param {Guild} guild - Object Guild resolved by the command. + * @param {Array|String} args - Array of arguments resolved by the command. + * @returns {Role|null} The role object / Null if not found / Error + * @memberof ErisResolver + */ + static role(guild, args) { + // Checking if all the arguments are supplied. + if (!guild || !args.length) { + throw new AxonError('All the arguments are either not given or false.', 'Resolver', 'Role'); + } + + // Checking if args is an array, if it is not, converting it to an array. + if (!Array.isArray(args) ) { + args = `${args}`.split(' '); + } + + args.all = args.join(' '); + args.lower = args.all.toLowerCase(); + const { roles } = guild; + + const mention = Utils.roleMention.exec(args[0] ); + + const role = ( (mention && mention[1] ) && roles.get(mention[1] ) ) // mention + || (Utils.id.test(args[0] ) && roles.get(args[0] ) ) // id + || roles.find(m => m.name === args.all) // name + || roles.find(m => m.name.toLowerCase() === args.lower) // name lower + || roles.find(m => m.name.includes(args.all) ) // name includes + || roles.find(m => m.name.toLowerCase().includes(args.lower) ) // name loxer includes + || null; // no role found + + return role; + } + + /** + * Resolve a channel within a guild. + * + * @param {Guild} guild - Object Guild resolved by the command. + * @param {Array|String} args - Array of arguments resolved by the command. + * @returns {Channel|null} The channel object / Null if not found / Error + * @memberof ErisResolver + */ + static channel(guild, args) { + // Checking if all the arguments are supplied. + if (!guild || !args.length) { + throw new AxonError('All the arguments are either not given or false.', 'Resolver', 'Channel'); + } + + // Checking if args is an array, if it is not, converting it to an array. + if (!Array.isArray(args) ) { + args = `${args}`.split(' '); + } + + args.all = args.join(' '); + args.lower = args.all.toLowerCase(); + const { channels } = guild; + + const mention = Utils.channelMention.exec(args[0] ); + + const channel = ( (mention && mention[1] ) && channels.get(mention[1] ) ) + || (Utils.id.test(args[0] ) && channels.get(args[0] ) ) + || channels.find(c => c.name === args.all) // name + || channels.find(c => c.name.toLowerCase() === args.lower) // name lower + || channels.find(c => c.name.includes(args.all) ) // name includes + || channels.find(c => c.name.toLowerCase().includes(args.lower) ) // name lower includes + || null; // no channel found + + return channel; + } + + /** + * Resolve a guild within all guilds the bot is in. + * + * @param {Client} client - The bot client + * @param {Array} args - Array with guild name/ID + * @returns {Guild|null} The guild object / Null if not found / Error + * @memberof ErisResolver + */ + static guild(client, args) { + // Checking if all the arguments are supplied. + if (!args.length) { + throw new AxonError('All the arguments are either not given or false.', 'Resolver', 'Guild'); + } + + const { guilds } = client; + args.all = args.join(' '); + args.lower = args.all.toLowerCase(); + + const guild = (Utils.id.test(args[0] ) && guilds.find(g => g.id === args[0] ) ) // ID + || guilds.find(g => g.name === args.all) // Name + || guilds.find(g => g.name.toLowerCase() === args.lower) // Lowercase name + || guilds.find(g => g.name.includes(args.all) ) // Includes name + || guilds.find(g => g.name.toLowerCase().includes(args.lower) ) // Includes lowercase name + || null; + + return guild; + } +} + +export default DetritusResolver; + diff --git a/src/Libraries/detritusjs/lib/DetritusUser.js b/src/Libraries/detritusjs/lib/DetritusUser.js new file mode 100644 index 00000000..b0f9a326 --- /dev/null +++ b/src/Libraries/detritusjs/lib/DetritusUser.js @@ -0,0 +1,19 @@ +import User from '../../definitions/User'; + +/** + * @typedef {import('eris').User} user + * @typedef {import('eris').PrivateChannel} PrivateChannel + */ + +class DetritusUser extends User { + /** + * @param {user} user + * @returns {PrivateChannel} + * @memberof ErisUser + */ + getDM(user) { + return this.lib.botClient.getDMChannel(user.id); + } +} + +export default DetritusUser; From 4c0c2b43a5e6d30c288fe982451f0108b1e6fcfe Mon Sep 17 00:00:00 2001 From: Khaazz Date: Sun, 22 Mar 2020 17:12:07 +0100 Subject: [PATCH 02/13] feat: detritus initialisation --- src/Libraries/index.js | 8 ++++++++ src/Utility/Constants/AxonEnums.js | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Libraries/index.js b/src/Libraries/index.js index 1f82390e..99cbf95b 100644 --- a/src/Libraries/index.js +++ b/src/Libraries/index.js @@ -2,6 +2,8 @@ import ASelector from '../Core/ASelector'; import ErisInterface from './eris/ErisInterface'; import DjsInterface from './discordjs/DjsInterface'; +import DetritusInterface from './detritusjs/DetritusInterface'; + import { LIBRARY_TYPES } from '../Utility/Constants/AxonEnums'; @@ -44,6 +46,12 @@ class LibrarySelector extends ASelector { break; } + case LIBRARY_TYPES.DETRITUS: { + libraryInterface = new DetritusInterface(axon.botClient); + axon.log('INFO', 'Selected Library Interface: DETRITUS.JS.'); + break; + } + default: { axon.log('WARN', 'No Selected Library Interface.'); libraryInterface = new ErisInterface(axon.botClient); diff --git a/src/Utility/Constants/AxonEnums.js b/src/Utility/Constants/AxonEnums.js index 62d5103e..93f7ab11 100644 --- a/src/Utility/Constants/AxonEnums.js +++ b/src/Utility/Constants/AxonEnums.js @@ -202,13 +202,14 @@ export const HTTP_MESSAGES = { // Types - Selector /** - * @type {{ ERIS: 0, DISCORDJS: 1 }} + * @type {{ ERIS: 0, DISCORDJS: 1, DETRITUSJS: 2 }} * @readonly - * @enum {0|1} + * @enum {0|1|2} */ export const LIBRARY_TYPES = { ERIS: 0, DISCORDJS: 1, + DETRITUSJS: 2, }; /** From 28528d967bb102d2a5c052ad2af1a30eee45ee11 Mon Sep 17 00:00:00 2001 From: Khaazz Date: Sun, 22 Mar 2020 17:13:52 +0100 Subject: [PATCH 03/13] chore(deps): detritus to dev deps --- package.json | 1 + yarn.lock | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 544d6667..aa9fd3de 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@typescript-eslint/eslint-plugin": "^2.16.0", "@typescript-eslint/parser": "^2.16.0", "chalk": "^2.4.2", + "detritus-client": "^0.10.1", "discord.js": "discordjs/discord.js", "eris": "abalabahaha/eris#dev", "eslint": "^6.8.0", diff --git a/yarn.lock b/yarn.lock index 8b195e7d..63586b7f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -475,6 +475,41 @@ denque@^1.4.1: resolved "https://registry.yarnpkg.com/denque/-/denque-1.4.1.tgz#6744ff7641c148c3f8a69c307e51235c1f4a37cf" integrity sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ== +detritus-client-rest@^0.6.9: + version "0.6.9" + resolved "https://registry.yarnpkg.com/detritus-client-rest/-/detritus-client-rest-0.6.9.tgz#328ce3f671c8ed5b5825a80f8cfe98c8b63c17e1" + integrity sha512-3gLb2h2L4Le7z0rMUobRDo/UfYqQupp73anqxTucsE4WO5Sbze/M+Q0q+ltaNgXo9qmWMrY4QV2EIq+WpvX6mw== + dependencies: + detritus-rest "^0.3.1" + detritus-utils "^0.2.6" + +detritus-client-socket@^0.4.7: + version "0.4.7" + resolved "https://registry.yarnpkg.com/detritus-client-socket/-/detritus-client-socket-0.4.7.tgz#a2a12075bdb30cf5d3997771db862407e2412d67" + integrity sha512-atnVI0tG3xnC+Ph1G2Xg6cwZ6f+q8BZ0I21iqTc+ShUVBhsO/LTqkncYQq55ssaWXn0DYSP3abAQQDfcTwrrJg== + dependencies: + detritus-utils "^0.2.6" + ws "^7.2.0" + +detritus-client@^0.10.1: + version "0.10.1" + resolved "https://registry.yarnpkg.com/detritus-client/-/detritus-client-0.10.1.tgz#bff65a350d7dd0bc714cc14b22940d6b3be7076b" + integrity sha512-+XBehxwq0Kn9ukAmghsYIUWEj0V2uDevqv+Szi/fVDb7VLHbzGenRGtnceV1Lfk1G7ZIlyf9MowN9JovIlW65w== + dependencies: + detritus-client-rest "^0.6.9" + detritus-client-socket "^0.4.7" + detritus-utils "^0.2.6" + +detritus-rest@^0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/detritus-rest/-/detritus-rest-0.3.1.tgz#75969e95e9e2200134b397c5246df23b26d69726" + integrity sha512-DW7wu/trh/Oq+u/ky3xZMgGoZErC2VnEuZ9ZHrOZd973MVcIm9a8hRqIA/N53ygf5a2qExBzuv7UaPw8nwV7yw== + +detritus-utils@^0.2.6: + version "0.2.6" + resolved "https://registry.yarnpkg.com/detritus-utils/-/detritus-utils-0.2.6.tgz#9249850d769d8572de43690a111899d6c3961f6c" + integrity sha512-cjeZjmIPew0h4ZP+A9aGizGCNrUyYhSx4FkQXGa3bJ5dNunChSqzUR8a5c2Gq6PIerWldTbh9976WxMw3m6Ejw== + diagnostics@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/diagnostics/-/diagnostics-1.1.1.tgz#cab6ac33df70c9d9a727490ae43ac995a769b22a" @@ -1983,7 +2018,7 @@ write@1.0.3: dependencies: mkdirp "^0.5.1" -ws@^7.2.1: +ws@^7.2.0, ws@^7.2.1: version "7.2.3" resolved "https://registry.yarnpkg.com/ws/-/ws-7.2.3.tgz#a5411e1fb04d5ed0efee76d26d5c46d830c39b46" integrity sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ== From 8096f2e66a6b74d6c4942f8bfda34525be858d78 Mon Sep 17 00:00:00 2001 From: Khaazz Date: Sun, 22 Mar 2020 17:17:00 +0100 Subject: [PATCH 04/13] feat(example): add detritus example [WIP] --- .gitignore | 2 + examples/detritus/scripts/start.js | 30 +++++ examples/detritus/src/Bot.js | 56 +++++++++ examples/detritus/src/Client.js | 58 ++++++++++ examples/detritus/src/Database/.gitkeep | 0 examples/detritus/src/MyUtils.js | 32 ++++++ .../detritus/src/configs/customConfig.json | 65 +++++++++++ examples/detritus/src/configs/lang.json | 16 +++ examples/detritus/src/index.js | 24 ++++ .../src/modules/Core/commands/Ping.js | 50 +++++++++ .../src/modules/Core/commands/Ping_Pong.js | 59 ++++++++++ .../modules/Core/commands/Ping_Pong_Pang.js | 54 +++++++++ .../Core/commands/Ping_Pong_Pang_Pung.js | 40 +++++++ .../src/modules/Core/commands/Wave.js | 71 ++++++++++++ .../src/modules/Core/commands/index.js | 2 + examples/detritus/src/modules/Core/index.js | 26 +++++ .../src/modules/Core/listeners/GuildCreate.js | 26 +++++ .../src/modules/Core/listeners/GuildDelete.js | 26 +++++ .../Core/listeners/MessageCreateLog.js | 32 ++++++ .../Core/listeners/MessageCreateMod.js | 32 ++++++ .../src/modules/Core/listeners/index.js | 4 + .../src/modules/Private/commands/Collect.js | 60 ++++++++++ .../src/modules/Private/commands/Eval.js | 106 ++++++++++++++++++ .../src/modules/Private/commands/index.js | 2 + .../detritus/src/modules/Private/index.js | 28 +++++ examples/detritus/src/modules/index.js | 2 + 26 files changed, 903 insertions(+) create mode 100644 examples/detritus/scripts/start.js create mode 100644 examples/detritus/src/Bot.js create mode 100644 examples/detritus/src/Client.js create mode 100644 examples/detritus/src/Database/.gitkeep create mode 100644 examples/detritus/src/MyUtils.js create mode 100644 examples/detritus/src/configs/customConfig.json create mode 100644 examples/detritus/src/configs/lang.json create mode 100644 examples/detritus/src/index.js create mode 100644 examples/detritus/src/modules/Core/commands/Ping.js create mode 100644 examples/detritus/src/modules/Core/commands/Ping_Pong.js create mode 100644 examples/detritus/src/modules/Core/commands/Ping_Pong_Pang.js create mode 100644 examples/detritus/src/modules/Core/commands/Ping_Pong_Pang_Pung.js create mode 100644 examples/detritus/src/modules/Core/commands/Wave.js create mode 100644 examples/detritus/src/modules/Core/commands/index.js create mode 100644 examples/detritus/src/modules/Core/index.js create mode 100644 examples/detritus/src/modules/Core/listeners/GuildCreate.js create mode 100644 examples/detritus/src/modules/Core/listeners/GuildDelete.js create mode 100644 examples/detritus/src/modules/Core/listeners/MessageCreateLog.js create mode 100644 examples/detritus/src/modules/Core/listeners/MessageCreateMod.js create mode 100644 examples/detritus/src/modules/Core/listeners/index.js create mode 100644 examples/detritus/src/modules/Private/commands/Collect.js create mode 100644 examples/detritus/src/modules/Private/commands/Eval.js create mode 100644 examples/detritus/src/modules/Private/commands/index.js create mode 100644 examples/detritus/src/modules/Private/index.js create mode 100644 examples/detritus/src/modules/index.js diff --git a/.gitignore b/.gitignore index 0bb8c8c7..b236ca22 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,14 @@ # configs file examples/eris/src/configs/tokenConfig.json examples/djs/src/configs/tokenConfig.json +examples/detritus/src/configs/tokenConfig.json examples/tokenConfig.json # json db src/Database/JSON/Database/*.json examples/eris/src/Database/*.json examples/djs/src/Database/*.json +examples/detritus/src/Database/*.json # Logs logs diff --git a/examples/detritus/scripts/start.js b/examples/detritus/scripts/start.js new file mode 100644 index 00000000..b70c0ec2 --- /dev/null +++ b/examples/detritus/scripts/start.js @@ -0,0 +1,30 @@ +const pm2 = require('pm2'); + +// Start process +console.log('>> Starting AxonCore'); +pm2.connect( (err) => { + if (err) { + console.error(err); + process.exit(2); + } + pm2.start( { + script: 'index.js', + args: ['--color'], + name: 'AxonCore.eris', + exec_mode: 'fork', + max_memory_restart: '1G', + cwd: 'example/src', + error: '../logs/error.err', + output: '../../logs/output.log', + pid: '../../logs/pid.pid', + node_args: '-r esm', + autorestart: true, + wait_ready: true, + }, (e) => { + pm2.disconnect(); + if (e) { + throw e; + } + } ); +} ); +// diff --git a/examples/detritus/src/Bot.js b/examples/detritus/src/Bot.js new file mode 100644 index 00000000..cdf17868 --- /dev/null +++ b/examples/detritus/src/Bot.js @@ -0,0 +1,56 @@ +import { ShardClient } from 'detritus-client'; + +import { AxonOptions } from 'axoncore'; + +import Client from './Client'; + +import botConfig from './configs/customConfig.json'; +import tokenConfig from '../../tokenConfig.json'; +import lang from './configs/lang.json'; + +import MyUtils from './MyUtils'; + +const axonOptions = new AxonOptions( { + prefixes: botConfig.prefixes, + settings: botConfig.settings, + lang, + logo: null, + + info: botConfig.info, + staff: botConfig.staff, + template: botConfig.template, + custom: { + param: 1, + }, +}, +tokenConfig.webhooks, +{ + utils: MyUtils, // use your own Utils + logger: null, // custom Logger + DBProvider: null, // custom DB Service + DBLocation: `${__dirname}/Database/`, + + axonConfig: null, + guildConfig: null, +} ); + +/** + * new AxonClient(token, erisOptions, AxonOptions, modules) + * + * new Client(token, erisOptions, AxonOptions) => Modules imported in Client + */ +const client = new ShardClient( + tokenConfig.bot.token, + { + gateway: { + loadAllMembers: true, + }, + }, +); + +const Bot = new Client( + client, + axonOptions, +); + +export default Bot; diff --git a/examples/detritus/src/Client.js b/examples/detritus/src/Client.js new file mode 100644 index 00000000..ccddbbe0 --- /dev/null +++ b/examples/detritus/src/Client.js @@ -0,0 +1,58 @@ +import { AxonClient } from 'axoncore'; + +import * as modules from './modules/index'; + +/** + * Example - Client constructor + * + * @author KhaaZ + * + * @class Client + * @extends AxonCore.AxonClient + */ +class Client extends AxonClient { + constructor(client, axonOptions) { + super(client, axonOptions, modules); + + this.param = 1; // personal stuff + this._param = 2; // personal hidden stuff + } + + onInit() { + this.staff.contributors = []; + } + + onStart() { + return Promise.resolve(true); + } + + onReady() { + return Promise.resolve(true); + } + + initStatus() { + // called after ready event + // overrides default editStatus + // used to setup custom status + this.botClient.editStatus(null, { + name: `AxonCore | ${this.settings.prefixes[0]}help`, + type: 0, + } ); + } + + // disabled + // eslint-disable-next-line no-unused-vars + $sendFullHelp(msg, guildConfig) { + // override sendFullHelp method + return this.axonUtils.sendMessage(msg.channel, 'Full Help override'); + } + + // disabled + // eslint-disable-next-line no-unused-vars + $sendHelp(command, env) { + // override sendHelp method + return this.axonUtils.sendMessage(env.msg.channel, `Help override for ${command.label}`); + } +} + +export default Client; diff --git a/examples/detritus/src/Database/.gitkeep b/examples/detritus/src/Database/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/examples/detritus/src/MyUtils.js b/examples/detritus/src/MyUtils.js new file mode 100644 index 00000000..12f3d5d7 --- /dev/null +++ b/examples/detritus/src/MyUtils.js @@ -0,0 +1,32 @@ +import { Utils } from 'axoncore'; + +class MyUtils extends Utils { + constructor(...args) { + super(...args); + this.invite = /^(discord.gg\/|discordapp.com\/invite\/)([a-z0-9]+)$/gi; + } + + /** + * Convert a hex code into a rgb code + * + * @param {Number/String} float - The base10 number to convert OR the base10 number as a String + * @returns {String} rgb color code (xxx, xxx, xxx) + */ + hexTOrgb(hex) { + let num = hex.replace('#', ''); + num = parseInt(num, 16); + return [num >> 16, num >> 8 & 255, num & 255]; // eslint-disable-line + } + + /** + * Convert a rgb code into a hex code + * + * @param {Number/String} float - the rgb color code + * @returns {String} Hex color code (6 char) (without #) + */ + rgbTOhex(red, green, blue) { + return ((blue | green << 8 | red << 16) | 1 << 24).toString(16).slice(1); // eslint-disable-line + } +} + +export default MyUtils; diff --git a/examples/detritus/src/configs/customConfig.json b/examples/detritus/src/configs/customConfig.json new file mode 100644 index 00000000..59ac2f13 --- /dev/null +++ b/examples/detritus/src/configs/customConfig.json @@ -0,0 +1,65 @@ +{ + "info": { + "name": "Axon", + "description": "AxonCore - Bot client, core module (eris lib)", + "version": "1.0.0", + "library": "eris" + }, + + "links": { + "website": "", + "invite": "", + "server": "", + + "github": "https://github.com/khaazz/AxonCore", + "trello": "", + "sentry": "", + "grafana": "" + }, + + "prefixes": { + "general": "a!", + "owner": "!!", + "admin": "a." + }, + + "staff": { + "owners": [ + { + "name": "KhaaZ#0001", + "id": "179908288337412096" + } + ], + "admins": [ + { + "name": "KhaaZ#0001", + "id": "179908288337412096" + } + ] + }, + + "template": { + "embeds": { + "help": "ffffff", + "global": 4315874, + "error": 15844367 + }, + + "emotes": { + "error": "<:error:426906693624922113>", + "success": "<:success:426906630463160330>", + "loading": "", + "update": "<:update:373546418952077323>", + "info": ":information_source:" + } + }, + + "settings": { + "lang": "french", + "debugMode": true, + "library": 0, + "logger": 1, + "db": 1, + "guildConfigCache": 1000 + } +} diff --git a/examples/detritus/src/configs/lang.json b/examples/detritus/src/configs/lang.json new file mode 100644 index 00000000..b11e2590 --- /dev/null +++ b/examples/detritus/src/configs/lang.json @@ -0,0 +1,16 @@ +{ + "english": { + "ERR_BOT_PERM": "I don't have sufficient permissions to do that! I need: {{permissions}}", + "ERR_CALLER_PERM": "You don't have sufficient permissions to do that! You need: {{permissions}}", + "ERR_DESTINATION_PERM": "This user is a mod/admin, I can't do that!", + "ERR_COOLDOWN": "Please, slow down! Remaining time: **{{cooldown}}** sec...", + "ERR_GENERAL": "An unexpected error occured! Contact the bot developers." + }, + "french": { + "ERR_BOT_PERM": "Je n'ai pas les permissions pour faire cela ! J'ai besoin de: {{permissions}}", + "ERR_CALLER_PERM": "Vous n'avez pas les permissions pour faire cela ! Vous avez besoin de: {{permissions}}", + "ERR_DESTINATION_PERM": "Cet utilisateur est un mod/admin, je ne peux pas faire ca !", + "ERR_COOLDOWN": "S'il vous plait, ralentissez ! Temps restant: **{{cooldown}}** sec...", + "ERR_GENERAL": "An unexpected error occured! Contact the bot developers." + } +} diff --git a/examples/detritus/src/index.js b/examples/detritus/src/index.js new file mode 100644 index 00000000..46cab4f9 --- /dev/null +++ b/examples/detritus/src/index.js @@ -0,0 +1,24 @@ +import Bot from './Bot'; +import customConf from './configs/customConfig.json'; + +if (customConf.db === 1) { + try { + const mongoose = require('mongoose'); + mongoose.connect('mongodb://localhost/AxonCoreDB', { + useCreateIndex: true, + autoReconnect: true, + } ) + .then( () => { + Bot.logger.notice('Connected to AxonCore DataBase.'); + } ) + .catch(err => { + Bot.logger.fatal(`Could NOT connect to AxonCore DataBase.\n${err.stack}`); + } ); + } catch (e) { + Bot.logger.fatal(`Could NOT connect to AxonCore DataBase.\n${e.stack}`); + } +} + +Bot.start(); + +Bot.logger.notice('=== ONLINE ==='); diff --git a/examples/detritus/src/modules/Core/commands/Ping.js b/examples/detritus/src/modules/Core/commands/Ping.js new file mode 100644 index 00000000..f83cee4f --- /dev/null +++ b/examples/detritus/src/modules/Core/commands/Ping.js @@ -0,0 +1,50 @@ +import { Command, CommandOptions, CommandResponse } from 'axoncore'; + +import Pong from './Ping_Pong'; + +class Ping extends Command { + constructor(module) { + super(module); + + this.label = 'ping'; + this.aliases = [ + 'ping', + 'pang', + 'pung', + ]; + + this.hasSubcmd = true; + + this.info = { + owners: ['KhaaZ'], + name: 'ping', + description: 'Ping the bot.', + usage: 'ping', + examples: ['ping'], + }; + + this.options = new CommandOptions(this, { + argsMin: 0, + guildOnly: false, + } ); + } + + init() { + return [Pong]; + } + + async execute( { msg } ) { + const start = Date.now(); + const mess = await this.sendMessage(msg.channel, 'Pong! '); + if (!mess) { + return new CommandResponse( { success: false } ); + } + + const diff = (Date.now() - start); + this.editMessage(mess, `Pong! \`${diff}ms\``); + + return new CommandResponse( { success: true } ); + } +} + +export default Ping; diff --git a/examples/detritus/src/modules/Core/commands/Ping_Pong.js b/examples/detritus/src/modules/Core/commands/Ping_Pong.js new file mode 100644 index 00000000..9eae2e34 --- /dev/null +++ b/examples/detritus/src/modules/Core/commands/Ping_Pong.js @@ -0,0 +1,59 @@ +import { Command, CommandOptions, CommandPermissions, CommandResponse } from 'axoncore'; + +import Pang from './Ping_Pong_Pang'; + +class Pong extends Command { + constructor(module) { + super(module); + + this.label = 'pong'; + this.aliases = ['pong']; + + this.hasSubcmd = true; + + this.info = { + owners: ['KhaaZ'], + name: 'ping pong', + description: 'Ping the bot.', + usage: 'ping pong', + examples: ['ping pong'], + }; + + this.options = new CommandOptions(this, { + argsMin: 0, + cooldown: 10000, + guildOnly: false, + hidden: true, + sendPermissionMessage: true, + } ); + + this.permissions = new CommandPermissions(this, { + author: { + needed: ['manageGuild'], + }, + staff: { + bypass: [...this.axon.staff.owners, ...this.axon.staff.admins], + }, + } ); + } + + init() { + return [Pang]; + } + + async execute( { msg } ) { + const start = Date.now(); + + const mess = await this.sendMessage(msg.channel, 'BADABOUM!'); + if (!mess) { + return new CommandResponse( { success: false } ); + } + + const diff = (Date.now() - start); + + this.editMessage(mess, `BADABOUM! \`${diff}ms\``); + return new CommandResponse( { success: true } ); + } +} + +export default Pong; diff --git a/examples/detritus/src/modules/Core/commands/Ping_Pong_Pang.js b/examples/detritus/src/modules/Core/commands/Ping_Pong_Pang.js new file mode 100644 index 00000000..ce77b65a --- /dev/null +++ b/examples/detritus/src/modules/Core/commands/Ping_Pong_Pang.js @@ -0,0 +1,54 @@ +import { Command, CommandOptions, CommandPermissions, CommandResponse } from 'axoncore'; + +import Pung from './Ping_Pong_Pang_Pung'; + +class Pang extends Command { + constructor(module) { + super(module); + + this.label = 'pang'; + this.aliases = ['pang']; + + this.hasSubcmd = true; + + this.info = { + owners: ['KhaaZ'], + name: 'ping pong pang', + description: 'Ping the bot.', + usage: 'ping pong pang', + examples: [ + 'ping pong pang', + 'ping pong pang but different', + 'an other ping pong pang', + ], + }; + + this.options = new CommandOptions(this, { + guildOnly: false, + } ); + + this.permissions = new CommandPermissions(this, { + serverMod: true, + } ); + } + + init() { + return [Pung]; + } + + async execute( { msg } ) { + const start = Date.now(); + + const mess = await this.sendMessage(msg.channel, 'pang pang!'); + if (!mess) { + return new CommandResponse( { success: false } ); + } + + const diff = (Date.now() - start); + + this.editMessage(mess, `pang pang! \`${diff}ms\``); + return new CommandResponse( { success: true } ); + } +} + +export default Pang; diff --git a/examples/detritus/src/modules/Core/commands/Ping_Pong_Pang_Pung.js b/examples/detritus/src/modules/Core/commands/Ping_Pong_Pang_Pung.js new file mode 100644 index 00000000..7841ce35 --- /dev/null +++ b/examples/detritus/src/modules/Core/commands/Ping_Pong_Pang_Pung.js @@ -0,0 +1,40 @@ +import { Command, CommandPermissions, CommandResponse } from 'axoncore'; + +class Pung extends Command { + constructor(module) { + super(module); + + this.label = 'pung'; + this.aliases = ['pung']; + + this.hasSubcmd = false; + + this.info = { + owners: ['KhaaZ'], + name: 'ping pong pang pung', + description: 'Ping the bot.', + usage: 'ping pong pang pung', + examples: [], + }; + + this.permissions = new CommandPermissions(this, { + custom: (msg) => msg.channel.guild.id === '365236789855649814', // Ease guild id + } ); + } + + async execute( { msg } ) { + const start = Date.now(); + + const mess = await this.sendMessage(msg.channel, 'REEEEEEEEE!'); + if (!mess) { + return new CommandResponse( { success: false } ); + } + + const diff = (Date.now() - start); + + this.editMessage(mess, `REEEEEEEEE! \`${diff}ms\``); + return new CommandResponse( { success: true } ); + } +} + +export default Pung; diff --git a/examples/detritus/src/modules/Core/commands/Wave.js b/examples/detritus/src/modules/Core/commands/Wave.js new file mode 100644 index 00000000..a2332e99 --- /dev/null +++ b/examples/detritus/src/modules/Core/commands/Wave.js @@ -0,0 +1,71 @@ +import { Command, Prompt } from 'axoncore'; + +class Wave extends Command { + constructor(module) { + super(module); + this.label = 'wave'; + + this.info = { + owners: ['Null'], + name: 'wave', + description: 'Wave at someone', + usage: 'wave (user)', + examples: ['wave KhaaZ'], + }; + + this.options.argsMin = 0; + this.options.cooldown = 15000; + } + + async execute( { msg, args } ) { + if (!args[0] ) { + const prompt = new Prompt(this.axon, msg.author.id, msg.channel, { + timeoutTime: 10000, + } ); + try { + const returnedMes = await prompt.run('Who would you like to me to wave to?', { + deleteTimeoutMsg: 10000, + timeoutMessage: 'Well, I guess you don\'t want to wave at anyone then.', + } ); + let user = this.Resolver.member(msg.channel.guild, returnedMes.content) || this.Resolver.user(this.axon.botClient, returnedMes.content); + if (!user) { + if (this.utils.id.test(returnedMes.content) ) { + user = await this.axon.botClient.getRESTUser(returnedMes.content); + } else { + return this.sendMessage(msg.channel, 'I can\'t wave to someone who does not exist.'); + } + } + const username = (user.guild && user.nick) || (user.guild && `${user.username}#${user.discriminator}`) || `${user.username}#${user.discriminator}`; + return this.sendMessage(msg.channel, `*Waves to ${username}*`); + } catch (err) { + if (err.message === 'Prompt timed out' || err.message === 'Invalid usage found. Prompt ended.') { + return null; + } + console.log(err); + return this.sendError(msg.channel, err); + } + } else { + try { + let user = this.Resolver.member(msg.channel.guild, args.join(' ') ) || this.Resolver.user(this.axon.botClient, args.join(' ') ); + if (!user) { + if (this.utils.id.test(args[0] ) ) { + user = await this.bot.getRESTUser(args[0] ); + } else { + return this.sendMessage(msg.channel, 'I can\'t wave to someone who does not exist.'); + } + } + const username = (user.guild && user.nick) || (user.guild && `${user.username}#${user.discriminator}`) || `${user.username}#${user.discriminator}`; + return this.sendMessage(msg.channel, `*Waves to ${username}*`); + } catch (err) { + if (err.message) { + if (err.message === 'DiscordRESTError [10013]: Unknown User') { + return this.sendMessage(msg.channel, 'I can\'t wave to someone who does not exist.'); + } + } + return this.sendError(msg.channel, `Error: \`\`\`js\n${err.message}\`\`\``); + } + } + } +} + +export default Wave; diff --git a/examples/detritus/src/modules/Core/commands/index.js b/examples/detritus/src/modules/Core/commands/index.js new file mode 100644 index 00000000..1da64109 --- /dev/null +++ b/examples/detritus/src/modules/Core/commands/index.js @@ -0,0 +1,2 @@ +export { default as Ping } from './Ping'; +// export { default as Wave } from './Wave'; diff --git a/examples/detritus/src/modules/Core/index.js b/examples/detritus/src/modules/Core/index.js new file mode 100644 index 00000000..bb0c9595 --- /dev/null +++ b/examples/detritus/src/modules/Core/index.js @@ -0,0 +1,26 @@ +import { Module } from 'axoncore'; + +import * as commands from './commands/index'; +import * as listeners from './listeners/index'; + +class Core extends Module { + constructor(...args) { + super(...args); + + this.label = 'Core'; + + this.enabled = true; + this.serverBypass = true; + + this.info = { + name: 'Core', + description: 'The main module with most basic commands.', + }; + } + + init() { + return { commands, listeners }; + } +} + +export default Core; diff --git a/examples/detritus/src/modules/Core/listeners/GuildCreate.js b/examples/detritus/src/modules/Core/listeners/GuildCreate.js new file mode 100644 index 00000000..667ce1dc --- /dev/null +++ b/examples/detritus/src/modules/Core/listeners/GuildCreate.js @@ -0,0 +1,26 @@ +import { Listener } from 'axoncore'; + +class GuildCreate extends Listener { + constructor(...args) { + super(...args); + + /** Event Name (Discord name) */ + this.eventName = 'guildCreate'; + /** Event name (Function name) */ + this.label = 'guildCreate'; + + this.enabled = true; + + this.info = { + owners: ['KhaaZ'], + description: 'Guild Create event', + }; + } + + execute(guild, guildConfig) { // eslint-disable-line no-unused-vars + console.log(`Guild Created: ${guild.name} [${guild.id}]`); + return Promise.resolve(); + } +} + +export default GuildCreate; diff --git a/examples/detritus/src/modules/Core/listeners/GuildDelete.js b/examples/detritus/src/modules/Core/listeners/GuildDelete.js new file mode 100644 index 00000000..3c0f8fa0 --- /dev/null +++ b/examples/detritus/src/modules/Core/listeners/GuildDelete.js @@ -0,0 +1,26 @@ +import { Listener } from 'axoncore'; + +class GuildDelete extends Listener { + constructor(...args) { + super(...args); + + /** Event Name (Discord name) */ + this.eventName = 'guildDelete'; + /** Event name (Function name) */ + this.label = 'guildDelete'; + + this.enabled = true; + + this.info = { + owners: ['KhaaZ'], + description: 'Guild Delete event', + }; + } + + execute(guild, guildConfig) { // eslint-disable-line no-unused-vars + console.log(`Guild Deleted: ${guild.name} [${guild.id}]`); + return Promise.resolve(); + } +} + +export default GuildDelete; diff --git a/examples/detritus/src/modules/Core/listeners/MessageCreateLog.js b/examples/detritus/src/modules/Core/listeners/MessageCreateLog.js new file mode 100644 index 00000000..501a477b --- /dev/null +++ b/examples/detritus/src/modules/Core/listeners/MessageCreateLog.js @@ -0,0 +1,32 @@ +import { Listener } from 'axoncore'; + +class MessageCreateLog extends Listener { + constructor(...args) { + super(...args); + + /** Event Name (Discord name) */ + this.eventName = 'messageCreate'; + /** Event name (Function name) */ + this.label = 'messageCreateLog'; + + this.enabled = true; + + this.info = { + owners: ['KhaaZ'], + description: 'Log Message Create events', + }; + } + + execute(message, guildConfig) { // eslint-disable-line no-unused-vars + if (!message.channel.guild) { + return Promise.resolve(); + } + if (message.webhookID !== undefined) { + return Promise.resolve(); + } + console.log(`Msg ${message.channel.guild.id}`); + return Promise.resolve(); + } +} + +export default MessageCreateLog; diff --git a/examples/detritus/src/modules/Core/listeners/MessageCreateMod.js b/examples/detritus/src/modules/Core/listeners/MessageCreateMod.js new file mode 100644 index 00000000..03662dfc --- /dev/null +++ b/examples/detritus/src/modules/Core/listeners/MessageCreateMod.js @@ -0,0 +1,32 @@ +import { Listener } from 'axoncore'; + +class MessageCreateMod extends Listener { + constructor(...args) { + super(...args); + + /** Event Name (Discord name) */ + this.eventName = 'messageCreate'; + /** Event name (Function name) */ + this.label = 'messageCreateMod'; + + this.enabled = true; + + this.info = { + owners: ['KhaaZ'], + description: 'Log Message Create events', + }; + } + + execute(message, guildConfig) { + if (!message.channel.guild) { + return Promise.resolve(); + } + if (message.webhookID !== undefined) { + return Promise.resolve(); + } + console.log(`Prefix: ${guildConfig.prefixes}`); + return Promise.resolve(); + } +} + +export default MessageCreateMod; diff --git a/examples/detritus/src/modules/Core/listeners/index.js b/examples/detritus/src/modules/Core/listeners/index.js new file mode 100644 index 00000000..a0179426 --- /dev/null +++ b/examples/detritus/src/modules/Core/listeners/index.js @@ -0,0 +1,4 @@ +export { default as GuildCreate } from './GuildCreate'; +export { default as GuildDelete } from './GuildDelete'; +export { default as MessageCreateLog } from './MessageCreateLog'; +export { default as MessageCreateMod } from './MessageCreateMod'; diff --git a/examples/detritus/src/modules/Private/commands/Collect.js b/examples/detritus/src/modules/Private/commands/Collect.js new file mode 100644 index 00000000..ab4a848d --- /dev/null +++ b/examples/detritus/src/modules/Private/commands/Collect.js @@ -0,0 +1,60 @@ +import { Command, MessageCollector } from 'axoncore'; + +class Collect extends Command { + constructor(module) { + super(module); + this.label = 'collect'; + this.info = { + owners: ['Null'], + name: 'collect', + description: 'Collect some messages and return', + usage: 'collect', + }; + this.options.cooldown = null; + + this._boundCollectEvent = this._onCollectEvent.bind(this); + } + + async execute( { msg } ) { + this._collector = new MessageCollector(this.axon); + this._message = await this.sendMessage(msg.channel, 'Awaiting messages'); + this._aID = msg.author.id; + + this._collector.on('collect', this._boundCollectEvent); + + try { + const msgs = await this._collector.run(msg.channel, { + count: 10, + ignoreBots: false, + } ); + const finale = msgs.map(m => `ID: ${m.id} (${m.author.username}#${m.author.discriminator}) => Content: ${m.content}`); // Code block\code line mardown breaks this + this._collector.off('collect', this._boundCollectEvent); + return this.sendMessage(msg.channel, `\`\`\`js\n${finale.join(',\n')}\`\`\``); + } catch (err) { + return this.sendMessage(msg.channel, err); + } + } + + async _onCollectEvent(message) { + if (this._message.content === 'Awaiting messages') { + this._message = await this.editMessage(this._message, 'Awaiting messages. \nSay `delete [message id]` to delete a message from the collector\nSay `end` to end the collect. (Ends at 10 messages anyways)'); + } + if (message.content.toLowerCase() === 'end' && message.author.id === this._aID) { + this._collector.delete(message.id); + this._collector.end(); + } else if (message.content.toLowerCase().startsWith('delete') ) { + const strings = message.content.split(' '); + this._collector.delete(message.id); + try { + const msgs = this._collector.delete(strings[1] ); + const finale = msgs.map(m => `ID: ${m.id} (${m.author.username}#${m.author.discriminator}) => Content: ${m.content}`); + return this.sendMessage(message.channel, `\`\`\`js\n${finale.join(',\n')}\`\`\``); + } catch (err) { + return this.sendMessage(message.channel, `Error: \`\`\`${err.message}\`\`\``); + } + } + return null; + } +} + +export default Collect; diff --git a/examples/detritus/src/modules/Private/commands/Eval.js b/examples/detritus/src/modules/Private/commands/Eval.js new file mode 100644 index 00000000..3bea12b1 --- /dev/null +++ b/examples/detritus/src/modules/Private/commands/Eval.js @@ -0,0 +1,106 @@ +/* eslint-disable no-unused-vars */ +import nodeUtil from 'util'; + +import { + Command, + CommandPermissions, + CommandOptions, + CommandResponse, + AxonEnums, + DiscordEnums, + Collection, + Embed, + Prompt, + MessageCollector, + SortedList, + Stack, + Queue, + FunctionQueue, + AutoQueue, + AsyncQueue, +} from 'axoncore'; + +class Eval extends Command { + constructor(module) { + super(module); + + this.label = 'eval'; + this.aliases = ['eval', 'e']; + + this.info = { + owners: [ + 'AS04', + 'Ape', + 'KhaaZ', + ], + name: 'eval', + description: 'Eval js code.', + usage: 'eval [js code]', + examples: ['eval 1 + 1'], + }; + + this.options = new CommandOptions(this, { + argsMin: 1, + cooldown: null, + } ); + + this.permissions = new CommandPermissions(this, { + staff: { + needed: this.axon.staff.owners, + bypass: this.axon.staff.owners, + }, + } ); + } + + async execute(env) { + const { msg, args, guildConfig } = env; + let evalString; + try { + // eslint-disable-next-line no-eval + evalString = await eval(args.join(' ') ); + + if (typeof evalString === 'object') { + evalString = nodeUtil.inspect(evalString, { depth: 0, showHidden: true } ); + } else { + evalString = String(evalString); + } + } catch (err) { + this.logger.debug(err.stack); + return this.sendError(msg.channel, err.message ? err.message : err); + } + + evalString = this.cleanUpToken(evalString); + + if (evalString.length === 0) { + return this.sendError(msg.channel, 'Nothing to evaluate.'); + } + + const splitEvaled = evalString.match(/[\s\S]{1,1900}[\n\r]/g) || [evalString]; + + if (splitEvaled.length > 3) { + this.sendMessage(msg.channel, `Cut the response! [3/${splitEvaled.length} | ${evalString.length} chars]`); + } + + for (let i = 0; i < 3; i++) { + if (!splitEvaled[i] ) { + break; + } + this.sendCode(msg.channel, splitEvaled[i] ); + } + return new CommandResponse( { + success: true, + } ); + } + + cleanUpToken(evalString) { + return evalString + .split(this.bot._token ? this.bot._token : this.bot.token) + .join('Khaaz Baguette'); + } + + sendCode(channel, content, lang = 'js') { + return this.sendMessage(channel, `\`\`\`${lang}\n${content}\`\`\``); + } +} + +export default Eval; diff --git a/examples/detritus/src/modules/Private/commands/index.js b/examples/detritus/src/modules/Private/commands/index.js new file mode 100644 index 00000000..26276b91 --- /dev/null +++ b/examples/detritus/src/modules/Private/commands/index.js @@ -0,0 +1,2 @@ +export { default as Eval } from './Eval'; +// export { default as Collect } from './Collect'; diff --git a/examples/detritus/src/modules/Private/index.js b/examples/detritus/src/modules/Private/index.js new file mode 100644 index 00000000..39ab5719 --- /dev/null +++ b/examples/detritus/src/modules/Private/index.js @@ -0,0 +1,28 @@ +import { Module, CommandPermissions } from 'axoncore'; + +import * as commands from './commands/index'; +// import * as events from './commands/index'; + +class Private extends Module { + constructor(...args) { + super(...args); + + this.label = 'Private'; + + this.enabled = true; + this.serverBypass = true; + + this.info = { + name: 'Private', + description: 'Very Private. Much Dev. Wow.', + }; + + this.permissions = new CommandPermissions(this, {}, true); + } + + init() { + return { commands }; + } +} + +export default Private; diff --git a/examples/detritus/src/modules/index.js b/examples/detritus/src/modules/index.js new file mode 100644 index 00000000..484f1132 --- /dev/null +++ b/examples/detritus/src/modules/index.js @@ -0,0 +1,2 @@ +export { default as Core } from './Core/index'; +export { default as Private } from './Private/index'; From 0f6817046546e38f083e56471004b0a7afdde537 Mon Sep 17 00:00:00 2001 From: Khaazz Date: Sun, 22 Mar 2020 17:18:19 +0100 Subject: [PATCH 05/13] feat: add detritus start script --- examples/detritus/scripts/start.js | 2 +- package.json | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/detritus/scripts/start.js b/examples/detritus/scripts/start.js index b70c0ec2..3d3a3b76 100644 --- a/examples/detritus/scripts/start.js +++ b/examples/detritus/scripts/start.js @@ -10,7 +10,7 @@ pm2.connect( (err) => { pm2.start( { script: 'index.js', args: ['--color'], - name: 'AxonCore.eris', + name: 'AxonCore.detritus', exec_mode: 'fork', max_memory_restart: '1G', cwd: 'example/src', diff --git a/package.json b/package.json index aa9fd3de..a4fba6c7 100644 --- a/package.json +++ b/package.json @@ -45,8 +45,10 @@ "docgen": "node ./scripts/gendoc.js && cp README.md ./docs/README.md", "start:eris": "node -r esm examples/eris/src/index.js", "start:djs": "node -r esm examples/djs/src/index.js", + "start:detritus": "node -r esm examples/detritus/src/index.js", "pm2start:eris": "node examples/eris/scripts/start.js", "pm2start:djs": "node examples/djs/scripts/start.js", + "pm2start:detritus": "node examples/detritus/scripts/start.js", "postinstall": "node ./scripts/typings.js", "dep": "yarn install --ignore-scripts" }, From 748739ebf4b1e8adbe3f1be357cbae97e53bb4b0 Mon Sep 17 00:00:00 2001 From: Khaazz Date: Sun, 22 Mar 2020 17:20:28 +0100 Subject: [PATCH 06/13] fix(detritus): Structures > Core path --- src/Libraries/detritusjs/handlers/ChannelCreateHandler.js | 2 +- src/Libraries/detritusjs/handlers/ChannelDeleteHandler.js | 2 +- src/Libraries/detritusjs/handlers/ChannelPinsUpdateHandler.js | 2 +- src/Libraries/detritusjs/handlers/ChannelUpdateHandler.js | 2 +- src/Libraries/detritusjs/handlers/GuildBanAddHandler.js | 2 +- src/Libraries/detritusjs/handlers/GuildBanRemoveHandler.js | 2 +- src/Libraries/detritusjs/handlers/GuildCreateHandler.js | 2 +- src/Libraries/detritusjs/handlers/GuildDeleteHandler.js | 2 +- src/Libraries/detritusjs/handlers/GuildEmojisUpdateHandler.js | 2 +- src/Libraries/detritusjs/handlers/GuildMemberAddHandler.js | 2 +- src/Libraries/detritusjs/handlers/GuildMemberRemoveHandler.js | 2 +- src/Libraries/detritusjs/handlers/GuildMemberUpdateHandler.js | 2 +- src/Libraries/detritusjs/handlers/GuildMembersChunkHandler.js | 2 +- src/Libraries/detritusjs/handlers/GuildReadyHandler.js | 2 +- src/Libraries/detritusjs/handlers/GuildRoleCreateHandler.js | 2 +- src/Libraries/detritusjs/handlers/GuildRoleDeleteHandler.js | 2 +- src/Libraries/detritusjs/handlers/GuildRoleUpdateHandler.js | 2 +- src/Libraries/detritusjs/handlers/GuildUpdateHandler.js | 2 +- src/Libraries/detritusjs/handlers/InviteCreateHandler.js | 2 +- src/Libraries/detritusjs/handlers/InviteDeleteHandler.js | 2 +- src/Libraries/detritusjs/handlers/MessageCreateHandler.js | 2 +- src/Libraries/detritusjs/handlers/MessageDeleteBulkHandler.js | 2 +- src/Libraries/detritusjs/handlers/MessageDeleteHandler.js | 2 +- src/Libraries/detritusjs/handlers/MessageReactionAddHandler.js | 2 +- .../detritusjs/handlers/MessageReactionRemoveAllHandler.js | 2 +- .../detritusjs/handlers/MessageReactionRemoveEmojiHandler.js | 2 +- .../detritusjs/handlers/MessageReactionRemoveHandler.js | 2 +- src/Libraries/detritusjs/handlers/MessageUpdateHandler.js | 2 +- src/Libraries/detritusjs/handlers/PresenceUpdateHandler.js | 2 +- .../detritusjs/handlers/ShardGatewayDisconnectHandler.js | 2 +- src/Libraries/detritusjs/handlers/ShardGatewayReadyHandler.js | 2 +- src/Libraries/detritusjs/handlers/TypingStartHandler.js | 2 +- src/Libraries/detritusjs/handlers/UnknownHandler.js | 2 +- src/Libraries/detritusjs/handlers/UserUpdateHandler.js | 2 +- src/Libraries/detritusjs/handlers/VoiceServerUpdateHandler.js | 2 +- src/Libraries/detritusjs/handlers/VoiceStateUpdateHandler.js | 2 +- src/Libraries/detritusjs/handlers/WebhooksUpdateHandler.js | 2 +- 37 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/Libraries/detritusjs/handlers/ChannelCreateHandler.js b/src/Libraries/detritusjs/handlers/ChannelCreateHandler.js index e53feb5c..51d108ec 100644 --- a/src/Libraries/detritusjs/handlers/ChannelCreateHandler.js +++ b/src/Libraries/detritusjs/handlers/ChannelCreateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class ChannelCreateHandler extends AHandler { handle( { channel } ) { diff --git a/src/Libraries/detritusjs/handlers/ChannelDeleteHandler.js b/src/Libraries/detritusjs/handlers/ChannelDeleteHandler.js index 24398a9a..c611a53c 100644 --- a/src/Libraries/detritusjs/handlers/ChannelDeleteHandler.js +++ b/src/Libraries/detritusjs/handlers/ChannelDeleteHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class ChannelDeleteHandler extends AHandler { handle( { channel } ) { diff --git a/src/Libraries/detritusjs/handlers/ChannelPinsUpdateHandler.js b/src/Libraries/detritusjs/handlers/ChannelPinsUpdateHandler.js index eeff3e74..c83f746d 100644 --- a/src/Libraries/detritusjs/handlers/ChannelPinsUpdateHandler.js +++ b/src/Libraries/detritusjs/handlers/ChannelPinsUpdateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class ChannelPinsUpdateHandler extends AHandler { handle( { channel } ) { diff --git a/src/Libraries/detritusjs/handlers/ChannelUpdateHandler.js b/src/Libraries/detritusjs/handlers/ChannelUpdateHandler.js index 7a7895ee..12c4a6e6 100644 --- a/src/Libraries/detritusjs/handlers/ChannelUpdateHandler.js +++ b/src/Libraries/detritusjs/handlers/ChannelUpdateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class ChannelUpdateHandler extends AHandler { handle( { channel } ) { diff --git a/src/Libraries/detritusjs/handlers/GuildBanAddHandler.js b/src/Libraries/detritusjs/handlers/GuildBanAddHandler.js index 86b4cbeb..39339d4c 100644 --- a/src/Libraries/detritusjs/handlers/GuildBanAddHandler.js +++ b/src/Libraries/detritusjs/handlers/GuildBanAddHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class GuildBanAddHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/GuildBanRemoveHandler.js b/src/Libraries/detritusjs/handlers/GuildBanRemoveHandler.js index 6ae6c767..99909fb8 100644 --- a/src/Libraries/detritusjs/handlers/GuildBanRemoveHandler.js +++ b/src/Libraries/detritusjs/handlers/GuildBanRemoveHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class GuildBanRemoveHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/GuildCreateHandler.js b/src/Libraries/detritusjs/handlers/GuildCreateHandler.js index f606a2a2..0cabbe14 100644 --- a/src/Libraries/detritusjs/handlers/GuildCreateHandler.js +++ b/src/Libraries/detritusjs/handlers/GuildCreateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class GuildCreateHandler extends AHandler { handle( { guild } ) { diff --git a/src/Libraries/detritusjs/handlers/GuildDeleteHandler.js b/src/Libraries/detritusjs/handlers/GuildDeleteHandler.js index 8424efe6..69aebd2d 100644 --- a/src/Libraries/detritusjs/handlers/GuildDeleteHandler.js +++ b/src/Libraries/detritusjs/handlers/GuildDeleteHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class GuildDeleteHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/GuildEmojisUpdateHandler.js b/src/Libraries/detritusjs/handlers/GuildEmojisUpdateHandler.js index 34df385b..27d76843 100644 --- a/src/Libraries/detritusjs/handlers/GuildEmojisUpdateHandler.js +++ b/src/Libraries/detritusjs/handlers/GuildEmojisUpdateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class GuildEmojisUpdateHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/GuildMemberAddHandler.js b/src/Libraries/detritusjs/handlers/GuildMemberAddHandler.js index 96e064c1..75410343 100644 --- a/src/Libraries/detritusjs/handlers/GuildMemberAddHandler.js +++ b/src/Libraries/detritusjs/handlers/GuildMemberAddHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class GuildMemberAddHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/GuildMemberRemoveHandler.js b/src/Libraries/detritusjs/handlers/GuildMemberRemoveHandler.js index 98d86e30..3689c91a 100644 --- a/src/Libraries/detritusjs/handlers/GuildMemberRemoveHandler.js +++ b/src/Libraries/detritusjs/handlers/GuildMemberRemoveHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class GuildMemberRemoveHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/GuildMemberUpdateHandler.js b/src/Libraries/detritusjs/handlers/GuildMemberUpdateHandler.js index cfc87708..fde8f14f 100644 --- a/src/Libraries/detritusjs/handlers/GuildMemberUpdateHandler.js +++ b/src/Libraries/detritusjs/handlers/GuildMemberUpdateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class GuildMemberUpdateHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/GuildMembersChunkHandler.js b/src/Libraries/detritusjs/handlers/GuildMembersChunkHandler.js index 2eef4c63..53c48bdd 100644 --- a/src/Libraries/detritusjs/handlers/GuildMembersChunkHandler.js +++ b/src/Libraries/detritusjs/handlers/GuildMembersChunkHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class GuildMembersChunkHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/GuildReadyHandler.js b/src/Libraries/detritusjs/handlers/GuildReadyHandler.js index 19f94a50..25b83dcf 100644 --- a/src/Libraries/detritusjs/handlers/GuildReadyHandler.js +++ b/src/Libraries/detritusjs/handlers/GuildReadyHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class GuildReadyHandler extends AHandler { handle( { guild } ) { diff --git a/src/Libraries/detritusjs/handlers/GuildRoleCreateHandler.js b/src/Libraries/detritusjs/handlers/GuildRoleCreateHandler.js index 0dcd3def..ff7bca28 100644 --- a/src/Libraries/detritusjs/handlers/GuildRoleCreateHandler.js +++ b/src/Libraries/detritusjs/handlers/GuildRoleCreateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class GuildRoleCreateHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/GuildRoleDeleteHandler.js b/src/Libraries/detritusjs/handlers/GuildRoleDeleteHandler.js index f44300ed..82b68796 100644 --- a/src/Libraries/detritusjs/handlers/GuildRoleDeleteHandler.js +++ b/src/Libraries/detritusjs/handlers/GuildRoleDeleteHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class GuildRoleDeleteHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/GuildRoleUpdateHandler.js b/src/Libraries/detritusjs/handlers/GuildRoleUpdateHandler.js index e10a6bd4..c791ab2e 100644 --- a/src/Libraries/detritusjs/handlers/GuildRoleUpdateHandler.js +++ b/src/Libraries/detritusjs/handlers/GuildRoleUpdateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class GuildRoleUpdateHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/GuildUpdateHandler.js b/src/Libraries/detritusjs/handlers/GuildUpdateHandler.js index 2b594f96..5703eb3c 100644 --- a/src/Libraries/detritusjs/handlers/GuildUpdateHandler.js +++ b/src/Libraries/detritusjs/handlers/GuildUpdateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class GuildUpdateHandler extends AHandler { handle( { guild } ) { diff --git a/src/Libraries/detritusjs/handlers/InviteCreateHandler.js b/src/Libraries/detritusjs/handlers/InviteCreateHandler.js index c9b43802..d9d5c4ad 100644 --- a/src/Libraries/detritusjs/handlers/InviteCreateHandler.js +++ b/src/Libraries/detritusjs/handlers/InviteCreateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class InviteCreateHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/InviteDeleteHandler.js b/src/Libraries/detritusjs/handlers/InviteDeleteHandler.js index 996ed388..bfebc8c4 100644 --- a/src/Libraries/detritusjs/handlers/InviteDeleteHandler.js +++ b/src/Libraries/detritusjs/handlers/InviteDeleteHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class InviteDeleteHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/MessageCreateHandler.js b/src/Libraries/detritusjs/handlers/MessageCreateHandler.js index 79b95533..c9524ed9 100644 --- a/src/Libraries/detritusjs/handlers/MessageCreateHandler.js +++ b/src/Libraries/detritusjs/handlers/MessageCreateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class MessageCreateHandler extends AHandler { handle( { message } ) { diff --git a/src/Libraries/detritusjs/handlers/MessageDeleteBulkHandler.js b/src/Libraries/detritusjs/handlers/MessageDeleteBulkHandler.js index c2c2238a..0ec1e60b 100644 --- a/src/Libraries/detritusjs/handlers/MessageDeleteBulkHandler.js +++ b/src/Libraries/detritusjs/handlers/MessageDeleteBulkHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class MessageDeleteBulkHandler extends AHandler { handle( { messages } ) { diff --git a/src/Libraries/detritusjs/handlers/MessageDeleteHandler.js b/src/Libraries/detritusjs/handlers/MessageDeleteHandler.js index 9ce00f0a..c34a7597 100644 --- a/src/Libraries/detritusjs/handlers/MessageDeleteHandler.js +++ b/src/Libraries/detritusjs/handlers/MessageDeleteHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class MessageDeleteHandler extends AHandler { handle( { message } ) { diff --git a/src/Libraries/detritusjs/handlers/MessageReactionAddHandler.js b/src/Libraries/detritusjs/handlers/MessageReactionAddHandler.js index d6c78055..ba5e2b33 100644 --- a/src/Libraries/detritusjs/handlers/MessageReactionAddHandler.js +++ b/src/Libraries/detritusjs/handlers/MessageReactionAddHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class MessageReactionAddHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/MessageReactionRemoveAllHandler.js b/src/Libraries/detritusjs/handlers/MessageReactionRemoveAllHandler.js index d792e2bf..25b6b12f 100644 --- a/src/Libraries/detritusjs/handlers/MessageReactionRemoveAllHandler.js +++ b/src/Libraries/detritusjs/handlers/MessageReactionRemoveAllHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class MessageReactionRemoveAllHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/MessageReactionRemoveEmojiHandler.js b/src/Libraries/detritusjs/handlers/MessageReactionRemoveEmojiHandler.js index 362713e2..4333cb59 100644 --- a/src/Libraries/detritusjs/handlers/MessageReactionRemoveEmojiHandler.js +++ b/src/Libraries/detritusjs/handlers/MessageReactionRemoveEmojiHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class MessageReactionRemoveEmojiHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/MessageReactionRemoveHandler.js b/src/Libraries/detritusjs/handlers/MessageReactionRemoveHandler.js index 88569467..bd44659c 100644 --- a/src/Libraries/detritusjs/handlers/MessageReactionRemoveHandler.js +++ b/src/Libraries/detritusjs/handlers/MessageReactionRemoveHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class MessageReactionRemoveHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/MessageUpdateHandler.js b/src/Libraries/detritusjs/handlers/MessageUpdateHandler.js index 24632838..746b456d 100644 --- a/src/Libraries/detritusjs/handlers/MessageUpdateHandler.js +++ b/src/Libraries/detritusjs/handlers/MessageUpdateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class MessageUpdateHandler extends AHandler { handle( { message } ) { diff --git a/src/Libraries/detritusjs/handlers/PresenceUpdateHandler.js b/src/Libraries/detritusjs/handlers/PresenceUpdateHandler.js index 16bc7521..5754b671 100644 --- a/src/Libraries/detritusjs/handlers/PresenceUpdateHandler.js +++ b/src/Libraries/detritusjs/handlers/PresenceUpdateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class PresenceUpdateHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/ShardGatewayDisconnectHandler.js b/src/Libraries/detritusjs/handlers/ShardGatewayDisconnectHandler.js index 22a318e3..6faf66f7 100644 --- a/src/Libraries/detritusjs/handlers/ShardGatewayDisconnectHandler.js +++ b/src/Libraries/detritusjs/handlers/ShardGatewayDisconnectHandler.js @@ -1,4 +1,4 @@ -/* import AHandler from '../../../Structures/Event/AHandler'; +/* import AHandler from '../../../Core/Event/AHandler'; class ShardGatewayDisconnectHandler extends AHandler { handle() { diff --git a/src/Libraries/detritusjs/handlers/ShardGatewayReadyHandler.js b/src/Libraries/detritusjs/handlers/ShardGatewayReadyHandler.js index 7e435647..0c231344 100644 --- a/src/Libraries/detritusjs/handlers/ShardGatewayReadyHandler.js +++ b/src/Libraries/detritusjs/handlers/ShardGatewayReadyHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class ShardGatewayReadyHandler extends AHandler { handle() { diff --git a/src/Libraries/detritusjs/handlers/TypingStartHandler.js b/src/Libraries/detritusjs/handlers/TypingStartHandler.js index 0347d634..5fb47cc4 100644 --- a/src/Libraries/detritusjs/handlers/TypingStartHandler.js +++ b/src/Libraries/detritusjs/handlers/TypingStartHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class TypingStartHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/UnknownHandler.js b/src/Libraries/detritusjs/handlers/UnknownHandler.js index d204e0c0..3d8b808f 100644 --- a/src/Libraries/detritusjs/handlers/UnknownHandler.js +++ b/src/Libraries/detritusjs/handlers/UnknownHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class UnknownHandler extends AHandler { handle() { diff --git a/src/Libraries/detritusjs/handlers/UserUpdateHandler.js b/src/Libraries/detritusjs/handlers/UserUpdateHandler.js index 9aef86ca..c167fc96 100644 --- a/src/Libraries/detritusjs/handlers/UserUpdateHandler.js +++ b/src/Libraries/detritusjs/handlers/UserUpdateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class UserUpdateHandler extends AHandler { handle() { diff --git a/src/Libraries/detritusjs/handlers/VoiceServerUpdateHandler.js b/src/Libraries/detritusjs/handlers/VoiceServerUpdateHandler.js index 3eeb720f..dd70c8ec 100644 --- a/src/Libraries/detritusjs/handlers/VoiceServerUpdateHandler.js +++ b/src/Libraries/detritusjs/handlers/VoiceServerUpdateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class VoiceServerUpdateHandler extends AHandler { handle( { guildId } ) { diff --git a/src/Libraries/detritusjs/handlers/VoiceStateUpdateHandler.js b/src/Libraries/detritusjs/handlers/VoiceStateUpdateHandler.js index 06521bbb..67c7ce73 100644 --- a/src/Libraries/detritusjs/handlers/VoiceStateUpdateHandler.js +++ b/src/Libraries/detritusjs/handlers/VoiceStateUpdateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class VoiceStateUpdateHandler extends AHandler { handle( { voiceState } ) { diff --git a/src/Libraries/detritusjs/handlers/WebhooksUpdateHandler.js b/src/Libraries/detritusjs/handlers/WebhooksUpdateHandler.js index c7268e40..7fd125e4 100644 --- a/src/Libraries/detritusjs/handlers/WebhooksUpdateHandler.js +++ b/src/Libraries/detritusjs/handlers/WebhooksUpdateHandler.js @@ -1,4 +1,4 @@ -import AHandler from '../../../Structures/Event/AHandler'; +import AHandler from '../../../Core/Event/AHandler'; class WebhooksUpdateHandler extends AHandler { handle( { guildId } ) { From 5a61141af1cc7517a5ce6b0111fef515655d4f59 Mon Sep 17 00:00:00 2001 From: Khaazz Date: Sun, 22 Mar 2020 17:26:05 +0100 Subject: [PATCH 07/13] fix(detritus): handler path --- src/Libraries/detritusjs/handlers/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/detritusjs/handlers/index.js b/src/Libraries/detritusjs/handlers/index.js index d65d2a27..20dbc3b7 100644 --- a/src/Libraries/detritusjs/handlers/index.js +++ b/src/Libraries/detritusjs/handlers/index.js @@ -33,7 +33,7 @@ export { default as messageUpdate } from './MessageUpdateHandler'; export { default as presenceUpdate } from './PresenceUpdateHandler'; // export { default as shardGatewayDisconnect } from './ShardGatewayDisconnectHandler'; not implemented yet, see file -export { default as shardGatewayReady } from './ShardReadyHandler'; +export { default as shardGatewayReady } from './ShardGatewayReadyHandler'; export { default as typingStart } from './TypingStartHandler'; From 751fbdc97c070b273f9ea25c8f6ba1079a5bed7e Mon Sep 17 00:00:00 2001 From: Khaazz Date: Sun, 22 Mar 2020 17:32:12 +0100 Subject: [PATCH 08/13] fix(detritus): initialisation --- examples/detritus/src/configs/customConfig.json | 4 ++-- examples/detritus/src/modules/Core/commands/Ping_Pong.js | 2 +- src/Libraries/index.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/detritus/src/configs/customConfig.json b/examples/detritus/src/configs/customConfig.json index 59ac2f13..e0af2392 100644 --- a/examples/detritus/src/configs/customConfig.json +++ b/examples/detritus/src/configs/customConfig.json @@ -55,9 +55,9 @@ }, "settings": { - "lang": "french", + "lang": "english", "debugMode": true, - "library": 0, + "library": 2, "logger": 1, "db": 1, "guildConfigCache": 1000 diff --git a/examples/detritus/src/modules/Core/commands/Ping_Pong.js b/examples/detritus/src/modules/Core/commands/Ping_Pong.js index 9eae2e34..aa98d5ff 100644 --- a/examples/detritus/src/modules/Core/commands/Ping_Pong.js +++ b/examples/detritus/src/modules/Core/commands/Ping_Pong.js @@ -29,7 +29,7 @@ class Pong extends Command { this.permissions = new CommandPermissions(this, { author: { - needed: ['manageGuild'], + needed: ['MANAGE_GUILD'], }, staff: { bypass: [...this.axon.staff.owners, ...this.axon.staff.admins], diff --git a/src/Libraries/index.js b/src/Libraries/index.js index 99cbf95b..55829d6d 100644 --- a/src/Libraries/index.js +++ b/src/Libraries/index.js @@ -46,7 +46,7 @@ class LibrarySelector extends ASelector { break; } - case LIBRARY_TYPES.DETRITUS: { + case LIBRARY_TYPES.DETRITUSJS: { libraryInterface = new DetritusInterface(axon.botClient); axon.log('INFO', 'Selected Library Interface: DETRITUS.JS.'); break; From e30e329926720b918aa1c1f5279d64630cd106ec Mon Sep 17 00:00:00 2001 From: Khaazz Date: Sun, 22 Mar 2020 17:44:41 +0100 Subject: [PATCH 09/13] fix(examples/detritus): events / editStatus --- examples/detritus/src/Client.js | 9 ++++++--- .../detritus/src/modules/Core/listeners/GuildCreate.js | 2 +- .../detritus/src/modules/Core/listeners/GuildDelete.js | 2 +- .../src/modules/Core/listeners/MessageCreateLog.js | 2 +- .../src/modules/Core/listeners/MessageCreateMod.js | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/detritus/src/Client.js b/examples/detritus/src/Client.js index ccddbbe0..a4ca6be2 100644 --- a/examples/detritus/src/Client.js +++ b/examples/detritus/src/Client.js @@ -34,9 +34,12 @@ class Client extends AxonClient { // called after ready event // overrides default editStatus // used to setup custom status - this.botClient.editStatus(null, { - name: `AxonCore | ${this.settings.prefixes[0]}help`, - type: 0, + this.botClient.gateway.setPresence( { + game: { + name: `AxonCore | ${this.settings.prefixes[0]}help`, + type: 0, + }, + status: '', } ); } diff --git a/examples/detritus/src/modules/Core/listeners/GuildCreate.js b/examples/detritus/src/modules/Core/listeners/GuildCreate.js index 667ce1dc..752aa7cf 100644 --- a/examples/detritus/src/modules/Core/listeners/GuildCreate.js +++ b/examples/detritus/src/modules/Core/listeners/GuildCreate.js @@ -17,7 +17,7 @@ class GuildCreate extends Listener { }; } - execute(guild, guildConfig) { // eslint-disable-line no-unused-vars + execute( { guild }, guildConfig) { // eslint-disable-line no-unused-vars console.log(`Guild Created: ${guild.name} [${guild.id}]`); return Promise.resolve(); } diff --git a/examples/detritus/src/modules/Core/listeners/GuildDelete.js b/examples/detritus/src/modules/Core/listeners/GuildDelete.js index 3c0f8fa0..52ad32e8 100644 --- a/examples/detritus/src/modules/Core/listeners/GuildDelete.js +++ b/examples/detritus/src/modules/Core/listeners/GuildDelete.js @@ -17,7 +17,7 @@ class GuildDelete extends Listener { }; } - execute(guild, guildConfig) { // eslint-disable-line no-unused-vars + execute( { guild }, guildConfig) { // eslint-disable-line no-unused-vars console.log(`Guild Deleted: ${guild.name} [${guild.id}]`); return Promise.resolve(); } diff --git a/examples/detritus/src/modules/Core/listeners/MessageCreateLog.js b/examples/detritus/src/modules/Core/listeners/MessageCreateLog.js index 501a477b..f6191fd7 100644 --- a/examples/detritus/src/modules/Core/listeners/MessageCreateLog.js +++ b/examples/detritus/src/modules/Core/listeners/MessageCreateLog.js @@ -17,7 +17,7 @@ class MessageCreateLog extends Listener { }; } - execute(message, guildConfig) { // eslint-disable-line no-unused-vars + execute( { message }, guildConfig) { // eslint-disable-line no-unused-vars if (!message.channel.guild) { return Promise.resolve(); } diff --git a/examples/detritus/src/modules/Core/listeners/MessageCreateMod.js b/examples/detritus/src/modules/Core/listeners/MessageCreateMod.js index 03662dfc..9eed594a 100644 --- a/examples/detritus/src/modules/Core/listeners/MessageCreateMod.js +++ b/examples/detritus/src/modules/Core/listeners/MessageCreateMod.js @@ -17,7 +17,7 @@ class MessageCreateMod extends Listener { }; } - execute(message, guildConfig) { + execute( { message }, guildConfig) { if (!message.channel.guild) { return Promise.resolve(); } From 7980dc2e2aedd7ff178faf3b05fe90004fffbb28 Mon Sep 17 00:00:00 2001 From: Khaazz Date: Sun, 22 Mar 2020 19:03:05 +0100 Subject: [PATCH 10/13] fix(detritus): hasPermission --- src/Libraries/detritusjs/lib/DetritusChannel.js | 6 ++++++ src/Libraries/detritusjs/lib/DetritusEnums.js | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Libraries/detritusjs/lib/DetritusChannel.js b/src/Libraries/detritusjs/lib/DetritusChannel.js index b3be170e..c977ee92 100644 --- a/src/Libraries/detritusjs/lib/DetritusChannel.js +++ b/src/Libraries/detritusjs/lib/DetritusChannel.js @@ -2,6 +2,12 @@ import Channel from '../../definitions/Channel'; class DetritusChannel extends Channel { hasPermission(channel, user, perm) { + if (!user.permissions && channel.guild) { + user = channel.guild.members.get(user.id); + } else { + return true; + } + return channel.can(perm, user); } diff --git a/src/Libraries/detritusjs/lib/DetritusEnums.js b/src/Libraries/detritusjs/lib/DetritusEnums.js index 9f629c2a..3e483fa0 100644 --- a/src/Libraries/detritusjs/lib/DetritusEnums.js +++ b/src/Libraries/detritusjs/lib/DetritusEnums.js @@ -25,7 +25,7 @@ * GUILD_ROLE_DELETE: 'roleDelete', * INVITE_CREATE: 'inviteCreate', * INVITE_DELETE: 'inviteDelete', - * MESSAGE_CREATE: 'message', + * MESSAGE_CREATE: 'messageCreate', * MESSAGE_UPDATE: 'messageUpdate', * MESSAGE_DELETE: 'messageDelete', * MESSAGE_DELETE_BULK: 'messageDeleteBulk', @@ -68,7 +68,7 @@ export const EVENTS = { GUILD_ROLE_DELETE: 'roleDelete', INVITE_CREATE: 'inviteCreate', INVITE_DELETE: 'inviteDelete', - MESSAGE_CREATE: 'message', + MESSAGE_CREATE: 'messageCreate', MESSAGE_UPDATE: 'messageUpdate', MESSAGE_DELETE: 'messageDelete', MESSAGE_DELETE_BULK: 'messageDeleteBulk', From 694c72bf42a019fd5d36089223c04a591ed0a4b5 Mon Sep 17 00:00:00 2001 From: Khaaz Date: Thu, 2 Jul 2020 15:01:36 +0200 Subject: [PATCH 11/13] Update examples/detritus/scripts/start.js Co-authored-by: bsian03 --- examples/detritus/scripts/start.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/detritus/scripts/start.js b/examples/detritus/scripts/start.js index 3d3a3b76..a6c5e55b 100644 --- a/examples/detritus/scripts/start.js +++ b/examples/detritus/scripts/start.js @@ -13,7 +13,7 @@ pm2.connect( (err) => { name: 'AxonCore.detritus', exec_mode: 'fork', max_memory_restart: '1G', - cwd: 'example/src', + cwd: 'examples/src', error: '../logs/error.err', output: '../../logs/output.log', pid: '../../logs/pid.pid', From 4cb994e6b636ab658c0283183914047f634a0aa4 Mon Sep 17 00:00:00 2001 From: Khaaz Date: Thu, 2 Jul 2020 15:01:50 +0200 Subject: [PATCH 12/13] Update examples/detritus/src/configs/customConfig.json Co-authored-by: bsian03 --- examples/detritus/src/configs/customConfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/detritus/src/configs/customConfig.json b/examples/detritus/src/configs/customConfig.json index e0af2392..7073f01d 100644 --- a/examples/detritus/src/configs/customConfig.json +++ b/examples/detritus/src/configs/customConfig.json @@ -3,7 +3,7 @@ "name": "Axon", "description": "AxonCore - Bot client, core module (eris lib)", "version": "1.0.0", - "library": "eris" + "library": "detritus" }, "links": { From 3d0ce0e0d18193c397ee8fbaf2095c8248714152 Mon Sep 17 00:00:00 2001 From: Khaazz Date: Wed, 29 Jul 2020 18:25:27 +0200 Subject: [PATCH 13/13] add detritus to dev deps --- package.json | 2 +- yarn.lock | 50 +++++++++++++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index a4fba6c7..3468f0ca 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "@typescript-eslint/eslint-plugin": "^2.16.0", "@typescript-eslint/parser": "^2.16.0", "chalk": "^2.4.2", - "detritus-client": "^0.10.1", + "detritus-client": "^0.11.0", "discord.js": "discordjs/discord.js", "eris": "abalabahaha/eris#dev", "eslint": "^6.8.0", diff --git a/yarn.lock b/yarn.lock index 63586b7f..7e3a0c5c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -475,35 +475,38 @@ denque@^1.4.1: resolved "https://registry.yarnpkg.com/denque/-/denque-1.4.1.tgz#6744ff7641c148c3f8a69c307e51235c1f4a37cf" integrity sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ== -detritus-client-rest@^0.6.9: - version "0.6.9" - resolved "https://registry.yarnpkg.com/detritus-client-rest/-/detritus-client-rest-0.6.9.tgz#328ce3f671c8ed5b5825a80f8cfe98c8b63c17e1" - integrity sha512-3gLb2h2L4Le7z0rMUobRDo/UfYqQupp73anqxTucsE4WO5Sbze/M+Q0q+ltaNgXo9qmWMrY4QV2EIq+WpvX6mw== +detritus-client-rest@^0.8.0: + version "0.8.0" + resolved "https://registry.yarnpkg.com/detritus-client-rest/-/detritus-client-rest-0.8.0.tgz#04441ad6bfa90ca2e4c6db55dacc6b25831ed189" + integrity sha512-mYRRy8LsPX3aBKDNZQFBFc6RaZgZYaYedetCsTeBstYxvxWBZpMxf1y/ekzkpf7g2hFxRmexVFM9DcWh+6whHw== dependencies: - detritus-rest "^0.3.1" + detritus-rest "^0.6.0" detritus-utils "^0.2.6" -detritus-client-socket@^0.4.7: - version "0.4.7" - resolved "https://registry.yarnpkg.com/detritus-client-socket/-/detritus-client-socket-0.4.7.tgz#a2a12075bdb30cf5d3997771db862407e2412d67" - integrity sha512-atnVI0tG3xnC+Ph1G2Xg6cwZ6f+q8BZ0I21iqTc+ShUVBhsO/LTqkncYQq55ssaWXn0DYSP3abAQQDfcTwrrJg== +detritus-client-socket@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/detritus-client-socket/-/detritus-client-socket-0.6.0.tgz#293bf7ab563de15cbb33ad520d877730a5f6680e" + integrity sha512-HPBE53TMTYhM1xUS1ZEVAXrbPKqz03ptQf1oxZPF7oi6SUDOgHN0VFWBGfLBj8KGiTzb4eX9gQcq3HX71jQlZQ== dependencies: detritus-utils "^0.2.6" - ws "^7.2.0" + ws "^7.3.1" -detritus-client@^0.10.1: - version "0.10.1" - resolved "https://registry.yarnpkg.com/detritus-client/-/detritus-client-0.10.1.tgz#bff65a350d7dd0bc714cc14b22940d6b3be7076b" - integrity sha512-+XBehxwq0Kn9ukAmghsYIUWEj0V2uDevqv+Szi/fVDb7VLHbzGenRGtnceV1Lfk1G7ZIlyf9MowN9JovIlW65w== +detritus-client@^0.11.0: + version "0.11.0" + resolved "https://registry.yarnpkg.com/detritus-client/-/detritus-client-0.11.0.tgz#fa63e6ec200174acb54340f800758dd9ebfab77d" + integrity sha512-syOCq0Ho4a6dvFmfnXRhd1oeMexqbKj2INwwRgQHkYvZ7I6QzsXc6R/Nt3VRz88y62Vm8jikktUCDDkR4tXKHg== dependencies: - detritus-client-rest "^0.6.9" - detritus-client-socket "^0.4.7" + detritus-client-rest "^0.8.0" + detritus-client-socket "^0.6.0" detritus-utils "^0.2.6" -detritus-rest@^0.3.1: - version "0.3.1" - resolved "https://registry.yarnpkg.com/detritus-rest/-/detritus-rest-0.3.1.tgz#75969e95e9e2200134b397c5246df23b26d69726" - integrity sha512-DW7wu/trh/Oq+u/ky3xZMgGoZErC2VnEuZ9ZHrOZd973MVcIm9a8hRqIA/N53ygf5a2qExBzuv7UaPw8nwV7yw== +detritus-rest@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/detritus-rest/-/detritus-rest-0.6.0.tgz#84dedd25bc978230952f00e8f282460ade7ea197" + integrity sha512-Y4XjabNqbOPpoSVvEwbEslGbWfa9BT0vhqnhuWKMwJcCHkA2MAatt6rhTA11mJq/8dFcHS9ysSxPaJ7lU7HuGg== + dependencies: + form-data "^3.0.0" + node-fetch "^2.6.0" detritus-utils@^0.2.6: version "0.2.6" @@ -2018,11 +2021,16 @@ write@1.0.3: dependencies: mkdirp "^0.5.1" -ws@^7.2.0, ws@^7.2.1: +ws@^7.2.1: version "7.2.3" resolved "https://registry.yarnpkg.com/ws/-/ws-7.2.3.tgz#a5411e1fb04d5ed0efee76d26d5c46d830c39b46" integrity sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ== +ws@^7.3.1: + version "7.3.1" + resolved "https://registry.yarnpkg.com/ws/-/ws-7.3.1.tgz#d0547bf67f7ce4f12a72dfe31262c68d7dc551c8" + integrity sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA== + xmlcreate@^2.0.3: version "2.0.3" resolved "https://registry.yarnpkg.com/xmlcreate/-/xmlcreate-2.0.3.tgz#df9ecd518fd3890ab3548e1b811d040614993497"