From 36140a7bd0385ae313113d59962f0f7ff3e86371 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 8 Aug 2021 15:10:31 +0200 Subject: [PATCH] Update 1.3.0 :tada: --- README.md | 197 ++++++++++++++++++++---------- {dist => lib}/index.js | 4 +- package-lock.json | 265 ++++++++++++++++++++++++++++------------- package.json | 9 +- src/index.ts | 4 +- test/test.js | 26 ++++ test/test.ts | 27 +++++ test/tsconfig.json | 26 ++++ tsconfig.json | 8 +- tsconfig.typing.json | 2 +- typing/index.d.ts | 8 +- 11 files changed, 414 insertions(+), 162 deletions(-) rename {dist => lib}/index.js (97%) create mode 100644 test/test.js create mode 100644 test/test.ts create mode 100644 test/tsconfig.json diff --git a/README.md b/README.md index e437b54..371d7e7 100644 --- a/README.md +++ b/README.md @@ -1,74 +1,145 @@ # Discord-resolve -This module groups together functions to retrieve data from different types of arguments. The functions group together all the possible cases each time (id, mention, name, start of name, name + tag). +This module groups together functions to retrieve data from different types of arguments. The functions group together all the possible cases each time (id, mention, name, start of name, name + tag). This module can also be used with slash-commands to give several options to a user. + +## Getting Started + +Prerequisites + +Node.js 16.6.0 or newer is required. + +### Instalation + +With npm : + +```sh-session +npm install discord-resolve +``` + +With yarn : + +```sh-session +yarn add discord-resolve +``` ## Usage -Create a new instance of DiscordResolve with the client has a parameter. Example : `const resolve = new DiscordResolve(client)`. - -### Methods - -- `resolveUser(arg)` : Get a user. -Parameter : - - arg : Id, mention, name, start of name, name + discriminator. (string) - - Return : User or undefined - -- `resolveGuild(arg)` : Get a guild. -Parameter : - - arg : Name or id of guild. (string) - - Return : Guild or undefined - -- `resolveMember(guild, arg)` : Get a guild member. -Parameter : - - guild : The guild (Guild) - - arg : Id, mention, username, start of username. (string) - - Return : Member or undefined - -- `resolveChannel(guild, arg)` : Get a guild channel. -Parameter : - - guild : The guild (Guild) - - arg : Id, mention, name, start of name. (string) - - Return : GuildChannel or undefined - -- `resolveRole(guild, arg)` : Get a guild role. -Parameter : - - guild : The guild (Guild) - - arg : Id, mention, name, start of name. (string) - - Return : Role or undefined - -- `resolveGuildEmoji(guild, arg)` : Get a guild emoji. -Parameter : - - guild : The guild (Guild) - - arg : Id, name, emoji. (string) - - Return : GuildEmoji or undefined - -- `resolveModo(member)` : Check if user is modo. -Parameter : - - member : GuildMember - - Return : Boolean or undefined +Import the module from node_modules : + +With CommonJS syntax : + +```js +const { DiscordResolve } = require("discord-resolve"); +``` + +With module syntax : ```js +import { DiscordResolve } = from 'discord-resolve'; +``` + +Create a new instance of DiscordResolve with the client has a parameter. + +```js +const resolve = new DiscordResolve(client)`. +``` + +## Methods + +--- + +## [async] resolveUser(arg) + +Get a user and fetch discord if it is not in the cache. + +Parameters : + +- arg : Id, mention, name, start of name, name + discriminator. (string) + +Return : User or undefined + +## resolveGuild(arg) + +Get a guild in common with the bot. + +Parameters : -const {DiscordResolve} = require('discord-resolve'); -const {Client, Intents} = require('discord.js'); +- arg : Name or id of guild. (string) + +Return : Guild or undefined + +## [async] resolveMember(guild, arg) + +Get a guild member and fetch discord if it is not in the cache. + +Parameters : + +- guild : The guild where is the member (Guild) +- arg : Id, mention, username, start of username. (string) + +Return : GuildMember or undefined + +## resolveChannel(guild, arg) + +Get a guild channel from a guild. + +Parameters : + +- guild : The guild where is the channel (Guild) +- arg : Id, mention, name, start of name. (string) + +Return : GuildChannel or undefined + +## resolveRole(guild, arg) + +Get a guild role. + +Parameters : + +- guild : The guild (Guild) +- arg : Id, mention, name, start of name. (string) + +Return : Role or undefined + +## resolveGuildEmoji(guild, arg) + +Get a emoji from a guild. + +Parameters : + +- guild : The guild where is the emoji (Guild) +- arg : Id, name, emoji (mention). (string) + +Return : GuildEmoji or undefined + +## resolveModo(member) + +Check if user have a moderator permissions (ADMINISTRATOR, MANAGE_GUILD or BAN_MEMBERS). + +Parameters : + +- member : GuildMember + +Return : Boolean + +## Example + +```js +const { DiscordResolve } = require("discord-resolve"); +const { Client, Intents } = require("discord.js"); -const client = new Client({intents:Intents.NON_PRIVILEGED}); +const client = new Client({ + intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES], +}); const util = new DiscordResolve(client); -client.on('message', async msg => { - const args = msg.content.split(' '); - const user = await util.resolveUser(args[0]) // args[0] accept id, mention, name, start of name and username + discriminator. - const guild = util.resolveGuild(args[1]) // args[1] accept id, and name. - const member = await util.resolveMember(msg.guild, args[2]) // args[2] accept id, mention, username, start of username. - const channel = util.resolveChannel(msg.guild, args[3]) // args[3] accept id, mention and name. - const role = util.resolveRole(msg.guild, args[4]) // args[4] accept id, mention, name and start of name. - const emoji = util.resolveGuildEmoji(msg.guild, args[5]) // args[5] accept id, name and emoji. -}) -client.login('token') +client.on("message", async (msg) => { + const args = msg.content.split(" "); + const user = await util.resolveUser(args[0]); // args[0] accept id, mention, name, start of name and username + discriminator. + const guild = util.resolveGuild(args[1]); // args[1] accept id, and name. + const member = await util.resolveMember(msg.guild, args[2]); // args[2] accept id, mention, username, start of username. + const channel = util.resolveChannel(msg.guild, args[3]); // args[3] accept id, mention and name. + const role = util.resolveRole(msg.guild, args[4]); // args[4] accept id, mention, name and start of name. + const emoji = util.resolveGuildEmoji(msg.guild, args[5]); // args[5] accept id, name and emoji. +}); +client.login("token"); ``` diff --git a/dist/index.js b/lib/index.js similarity index 97% rename from dist/index.js rename to lib/index.js index b7a3525..06a0b94 100644 --- a/dist/index.js +++ b/lib/index.js @@ -105,7 +105,7 @@ class DiscordResolve { * @param {string} arg The argument (id, name, emoji ) * @returns {GuildEmoji} */ - this.resolveGuildEmoji = async (guild, arg) => { + this.resolveGuildEmoji = (guild, arg) => { if (!guild || !arg) return null; const emoji = guild.emojis.cache.find((e) => e.id == arg || e.name == arg) || @@ -117,7 +117,7 @@ class DiscordResolve { * @param {GuildMember} member * @returns {boolean} */ - this.resolveModo = async (member) => { + this.resolveModo = (member) => { if (member.permissions.has('ADMINISTRATOR') || member.permissions.has('MANAGE_GUILD') || member.permissions.has('BAN_MEMBERS')) return true; return false; diff --git a/package-lock.json b/package-lock.json index a4db25d..a3b460a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "discord-resolve", - "version": "1.2.0", + "version": "1.2.0-beta.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "discord-resolve", - "version": "1.2.0", + "version": "1.2.0-beta.0", "license": "MIT", "dependencies": { - "discord.js": "^13.0.0-dev.t1627732975.331a9d3" + "discord.js": "^13.0.1" }, "devDependencies": { "@types/node": "^15.12.2", @@ -17,11 +17,14 @@ } }, "node_modules/@discordjs/builders": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.2.0.tgz", - "integrity": "sha512-TVq7NZBCJrrTRc3CfxOr3IdgY5nrtqVxZ7qDUF1mN6LgxIiOldmFxsSwMrQBzLFVmOwqFyNLKCeblley8UpEuw==", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.4.0.tgz", + "integrity": "sha512-EiwLltKph6TSaPJIzJYdzNc1PnA2ZNaaE0t0ODg3ghnpVHqfgd0YX9/srsleYHW2cw1sfIq+kbM+h0etf7GWLA==", "dependencies": { - "discord-api-types": "^0.18.1", + "@sindresorhus/is": "^4.0.1", + "discord-api-types": "^0.22.0", + "ow": "^0.27.0", + "ts-mixer": "^6.0.0", "tslib": "^2.3.0" }, "engines": { @@ -29,15 +32,6 @@ "npm": ">=7.0.0" } }, - "node_modules/@discordjs/builders/node_modules/discord-api-types": { - "version": "0.18.1", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.18.1.tgz", - "integrity": "sha512-hNC38R9ZF4uaujaZQtQfm5CdQO58uhdkoHQAVvMfIL0LgOSZeW575W8H6upngQOuoxWd8tiRII3LLJm9zuQKYg==", - "deprecated": "No longer supported. Install the latest release (0.20.2)", - "engines": { - "node": ">=12" - } - }, "node_modules/@discordjs/collection": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.2.1.tgz", @@ -68,35 +62,43 @@ "npm": ">=6" } }, + "node_modules/@sindresorhus/is": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.0.1.tgz", + "integrity": "sha512-Qm9hBEBu18wt1PO2flE7LPb30BHMQt1eQgbV76YntdNk73XZGpn3izvGTYxbGgzXKgbCjiia0uxTd3aTNQrY/g==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sindresorhus/is?sponsor=1" + } + }, "node_modules/@types/node": { "version": "15.12.2", "resolved": "https://registry.npmjs.org/@types/node/-/node-15.12.2.tgz", "integrity": "sha512-zjQ69G564OCIWIOHSXyQEEDpdpGl+G348RAKY0XXy9Z5kU9Vzv1GMNnkar/ZJ8dzXB3COzD9Mo9NtRZ4xfgUww==" }, "node_modules/@types/ws": { - "version": "7.4.5", - "resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.4.5.tgz", - "integrity": "sha512-8mbDgtc8xpxDDem5Gwj76stBDJX35KQ3YBoayxlqUQcL5BZUthiqP/VQ4PQnLHqM4PmlbyO74t98eJpURO+gPA==", + "version": "7.4.7", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.4.7.tgz", + "integrity": "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww==", "dependencies": { "@types/node": "*" } }, - "node_modules/abort-controller": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", - "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", - "dependencies": { - "event-target-shim": "^5.0.0" - }, - "engines": { - "node": ">=6.5" - } - }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, + "node_modules/callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "engines": { + "node": ">=6" + } + }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -117,41 +119,59 @@ } }, "node_modules/discord-api-types": { - "version": "0.21.0", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.21.0.tgz", - "integrity": "sha512-x/YpcXK2tS7kQRavirl5/QnYD1U8L3HzCTMkg+gwDEp+IkE8XGCLJHiZZoEKIAvpJFv5XzT5IPsduTIB2ONbuA==", + "version": "0.22.0", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.22.0.tgz", + "integrity": "sha512-l8yD/2zRbZItUQpy7ZxBJwaLX/Bs2TGaCthRppk8Sw24LOIWg12t9JEreezPoYD0SQcC2htNNo27kYEpYW/Srg==", "engines": { "node": ">=12" } }, "node_modules/discord.js": { - "version": "13.0.0-dev.t1627732975.331a9d3", - "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.0.0-dev.t1627732975.331a9d3.tgz", - "integrity": "sha512-AOA/jJNzdtkJjjCBuiwVx5Q3cEVBClYB8XPBJ0wdrm6VUu+YNqJJyPFHM1DqyYwtPN8Jw7YPzPEqDVidCOn+Pg==", + "version": "13.0.1", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.0.1.tgz", + "integrity": "sha512-pEODCFfxypBnGEYpSgjkn1jt70raCS1um7Zp0AXEfW1DcR29wISzQ/WeWdnjP5KTXGi0LTtkRiUjOsMgSoukxA==", "dependencies": { - "@discordjs/builders": "^0.2.0", + "@discordjs/builders": "^0.4.0", "@discordjs/collection": "^0.2.1", "@discordjs/form-data": "^3.0.1", "@sapphire/async-queue": "^1.1.4", - "@types/ws": "^7.4.5", - "abort-controller": "^3.0.0", - "discord-api-types": "^0.21.0", + "@types/ws": "^7.4.7", + "discord-api-types": "^0.22.0", "node-fetch": "^2.6.1", "ws": "^7.5.1" }, "engines": { - "node": ">=14.6.0", + "node": ">=16.6.0", "npm": ">=7.0.0" } }, - "node_modules/event-target-shim": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", - "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "node_modules/dot-prop": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-6.0.1.tgz", + "integrity": "sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==", + "dependencies": { + "is-obj": "^2.0.0" + }, "engines": { - "node": ">=6" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/is-obj": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", + "integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==", + "engines": { + "node": ">=8" + } + }, + "node_modules/lodash.isequal": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" + }, "node_modules/mime-db": { "version": "1.48.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.48.0.tgz", @@ -179,11 +199,54 @@ "node": "4.x || >=6.0.0" } }, + "node_modules/ow": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/ow/-/ow-0.27.0.tgz", + "integrity": "sha512-SGnrGUbhn4VaUGdU0EJLMwZWSupPmF46hnTRII7aCLCrqixTAC5eKo8kI4/XXf1eaaI8YEVT+3FeGNJI9himAQ==", + "dependencies": { + "@sindresorhus/is": "^4.0.1", + "callsites": "^3.1.0", + "dot-prop": "^6.0.1", + "lodash.isequal": "^4.5.0", + "type-fest": "^1.2.1", + "vali-date": "^1.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ts-mixer": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.0.tgz", + "integrity": "sha512-nXIb1fvdY5CBSrDIblLn73NW0qRDk5yJ0Sk1qPBF560OdJfQp9jhl+0tzcY09OZ9U+6GpeoI9RjwoIKFIoB9MQ==" + }, "node_modules/tslib": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" }, + "node_modules/type-fest": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-1.4.0.tgz", + "integrity": "sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/vali-date": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/vali-date/-/vali-date-1.0.0.tgz", + "integrity": "sha1-G5BKWWCfsyjvB4E4Qgk09rhnCaY=", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/ws": { "version": "7.5.3", "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.3.tgz", @@ -207,19 +270,15 @@ }, "dependencies": { "@discordjs/builders": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.2.0.tgz", - "integrity": "sha512-TVq7NZBCJrrTRc3CfxOr3IdgY5nrtqVxZ7qDUF1mN6LgxIiOldmFxsSwMrQBzLFVmOwqFyNLKCeblley8UpEuw==", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.4.0.tgz", + "integrity": "sha512-EiwLltKph6TSaPJIzJYdzNc1PnA2ZNaaE0t0ODg3ghnpVHqfgd0YX9/srsleYHW2cw1sfIq+kbM+h0etf7GWLA==", "requires": { - "discord-api-types": "^0.18.1", + "@sindresorhus/is": "^4.0.1", + "discord-api-types": "^0.22.0", + "ow": "^0.27.0", + "ts-mixer": "^6.0.0", "tslib": "^2.3.0" - }, - "dependencies": { - "discord-api-types": { - "version": "0.18.1", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.18.1.tgz", - "integrity": "sha512-hNC38R9ZF4uaujaZQtQfm5CdQO58uhdkoHQAVvMfIL0LgOSZeW575W8H6upngQOuoxWd8tiRII3LLJm9zuQKYg==" - } } }, "@discordjs/collection": { @@ -242,32 +301,34 @@ "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.1.4.tgz", "integrity": "sha512-fFrlF/uWpGOX5djw5Mu2Hnnrunao75WGey0sP0J3jnhmrJ5TAPzHYOmytD5iN/+pMxS+f+u/gezqHa9tPhRHEA==" }, + "@sindresorhus/is": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.0.1.tgz", + "integrity": "sha512-Qm9hBEBu18wt1PO2flE7LPb30BHMQt1eQgbV76YntdNk73XZGpn3izvGTYxbGgzXKgbCjiia0uxTd3aTNQrY/g==" + }, "@types/node": { "version": "15.12.2", "resolved": "https://registry.npmjs.org/@types/node/-/node-15.12.2.tgz", "integrity": "sha512-zjQ69G564OCIWIOHSXyQEEDpdpGl+G348RAKY0XXy9Z5kU9Vzv1GMNnkar/ZJ8dzXB3COzD9Mo9NtRZ4xfgUww==" }, "@types/ws": { - "version": "7.4.5", - "resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.4.5.tgz", - "integrity": "sha512-8mbDgtc8xpxDDem5Gwj76stBDJX35KQ3YBoayxlqUQcL5BZUthiqP/VQ4PQnLHqM4PmlbyO74t98eJpURO+gPA==", + "version": "7.4.7", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.4.7.tgz", + "integrity": "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww==", "requires": { "@types/node": "*" } }, - "abort-controller": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", - "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", - "requires": { - "event-target-shim": "^5.0.0" - } - }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, + "callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==" + }, "combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -282,30 +343,42 @@ "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, "discord-api-types": { - "version": "0.21.0", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.21.0.tgz", - "integrity": "sha512-x/YpcXK2tS7kQRavirl5/QnYD1U8L3HzCTMkg+gwDEp+IkE8XGCLJHiZZoEKIAvpJFv5XzT5IPsduTIB2ONbuA==" + "version": "0.22.0", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.22.0.tgz", + "integrity": "sha512-l8yD/2zRbZItUQpy7ZxBJwaLX/Bs2TGaCthRppk8Sw24LOIWg12t9JEreezPoYD0SQcC2htNNo27kYEpYW/Srg==" }, "discord.js": { - "version": "13.0.0-dev.t1627732975.331a9d3", - "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.0.0-dev.t1627732975.331a9d3.tgz", - "integrity": "sha512-AOA/jJNzdtkJjjCBuiwVx5Q3cEVBClYB8XPBJ0wdrm6VUu+YNqJJyPFHM1DqyYwtPN8Jw7YPzPEqDVidCOn+Pg==", + "version": "13.0.1", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.0.1.tgz", + "integrity": "sha512-pEODCFfxypBnGEYpSgjkn1jt70raCS1um7Zp0AXEfW1DcR29wISzQ/WeWdnjP5KTXGi0LTtkRiUjOsMgSoukxA==", "requires": { - "@discordjs/builders": "^0.2.0", + "@discordjs/builders": "^0.4.0", "@discordjs/collection": "^0.2.1", "@discordjs/form-data": "^3.0.1", "@sapphire/async-queue": "^1.1.4", - "@types/ws": "^7.4.5", - "abort-controller": "^3.0.0", - "discord-api-types": "^0.21.0", + "@types/ws": "^7.4.7", + "discord-api-types": "^0.22.0", "node-fetch": "^2.6.1", "ws": "^7.5.1" } }, - "event-target-shim": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", - "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==" + "dot-prop": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-6.0.1.tgz", + "integrity": "sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==", + "requires": { + "is-obj": "^2.0.0" + } + }, + "is-obj": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", + "integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==" + }, + "lodash.isequal": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" }, "mime-db": { "version": "1.48.0", @@ -325,11 +398,39 @@ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" }, + "ow": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/ow/-/ow-0.27.0.tgz", + "integrity": "sha512-SGnrGUbhn4VaUGdU0EJLMwZWSupPmF46hnTRII7aCLCrqixTAC5eKo8kI4/XXf1eaaI8YEVT+3FeGNJI9himAQ==", + "requires": { + "@sindresorhus/is": "^4.0.1", + "callsites": "^3.1.0", + "dot-prop": "^6.0.1", + "lodash.isequal": "^4.5.0", + "type-fest": "^1.2.1", + "vali-date": "^1.0.0" + } + }, + "ts-mixer": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.0.tgz", + "integrity": "sha512-nXIb1fvdY5CBSrDIblLn73NW0qRDk5yJ0Sk1qPBF560OdJfQp9jhl+0tzcY09OZ9U+6GpeoI9RjwoIKFIoB9MQ==" + }, "tslib": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" }, + "type-fest": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-1.4.0.tgz", + "integrity": "sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==" + }, + "vali-date": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/vali-date/-/vali-date-1.0.0.tgz", + "integrity": "sha1-G5BKWWCfsyjvB4E4Qgk09rhnCaY=" + }, "ws": { "version": "7.5.3", "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.3.tgz", diff --git a/package.json b/package.json index 9a3170e..85cb715 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,19 @@ { "name": "discord-resolve", - "version": "1.2.0-beta.0", + "version": "1.3.0", "description": "This module groups together functions to retrieve data from different types of arguments", - "main": "dist/index.js", + "main": "lib/index.js", "types": "./typing/index.d.ts", "dependencies": { - "discord.js": "^13.0.0-dev.t1627732975.331a9d3" + "discord.js": "^13.0.1" }, "devDependencies": { "@types/node": "^15.12.2", "@types/ws": "^7.4.5" }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "build": "tsc", + "build:typing": "tsc --build tsconfig.typing.json" }, "repository": { "type": "git", diff --git a/src/index.ts b/src/index.ts index aa0edfc..c17d6a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -108,7 +108,7 @@ export class DiscordResolve { * @param {string} arg The argument (id, name, emoji ) * @returns {GuildEmoji} */ - resolveGuildEmoji = async (guild: Guild, arg: string) => { + resolveGuildEmoji = (guild: Guild, arg: string) => { if (!guild || !arg) return null; const emoji = guild.emojis.cache.find((e: GuildEmoji) => e.id == arg || e.name == arg) || @@ -120,7 +120,7 @@ export class DiscordResolve { * @param {GuildMember} member * @returns {boolean} */ - resolveModo = async (member: GuildMember) => { + resolveModo = (member: GuildMember) => { if (member.permissions.has('ADMINISTRATOR') || member.permissions.has('MANAGE_GUILD') || member.permissions.has('BAN_MEMBERS')) return true; return false; } diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..30dbe8a --- /dev/null +++ b/test/test.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const { DiscordResolve } = require("../lib"); +const discord_js_1 = require("discord.js"); +const client = new discord_js_1.Client({ + intents: [discord_js_1.Intents.FLAGS.GUILDS, discord_js_1.Intents.FLAGS.GUILD_MESSAGES], +}); +const util = new DiscordResolve(client); +client.on("message", async (msg) => { + const args = msg.content.split(" "); + if (msg.content.startsWith("!test")) { + const user = await util.resolveUser(args[1]); // args[1] accept id, mention, name, start of name and username + discriminator. + const guild = util.resolveGuild(args[2]); // args[2] accept id, and name. + const member = await util.resolveMember(msg.guild, args[3]); // args[3] accept id, mention, username, start of username. + const channel = util.resolveChannel(msg.guild, args[4]); // args[4] accept id, mention and name. + const role = util.resolveRole(msg.guild, args[5]); // args[5] accept id, mention, name and start of name. + const emoji = util.resolveGuildEmoji(msg.guild, args[6]); // args[6] accept id, name and emoji. + console.log(`User : ` + user.username); + console.log(`Guild : ` + guild.name); + console.log(`Member : ` + member.user.username); + console.log(`Channel : ` + channel.name); + console.log(`Role : ` + role.name); + console.log(`Emoji : ` + emoji.name); + } +}); +client.login(""); diff --git a/test/test.ts b/test/test.ts new file mode 100644 index 0000000..c61d009 --- /dev/null +++ b/test/test.ts @@ -0,0 +1,27 @@ +const { DiscordResolve } = require("../lib"); +import { Client, Intents } from "discord.js"; +import type { Message } from 'discord.js' +const client = new Client({ + intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES], +}); +const util = new DiscordResolve(client); +client.on("message", async (msg: Message) => { + const args = msg.content.split(" "); + if (msg.content.startsWith("!test")) { + const user = await util.resolveUser(args[1]); // args[1] accept id, mention, name, start of name and username + discriminator. + const guild = util.resolveGuild(args[2]); // args[2] accept id, and name. + const member = await util.resolveMember(msg.guild, args[3]); // args[3] accept id, mention, username, start of username. + const channel = util.resolveChannel(msg.guild, args[4]); // args[4] accept id, mention and name. + const role = util.resolveRole(msg.guild, args[5]); // args[5] accept id, mention, name and start of name. + const emoji = util.resolveGuildEmoji(msg.guild, args[6]); // args[6] accept id, name and emoji. + console.log(`User : ` + user.username); + console.log(`Guild : ` + guild.name); + console.log(`Member : ` + member.user.username); + console.log(`Channel : ` + channel.name); + console.log(`Role : ` + role.name); + console.log(`Emoji : ` + emoji.name); + + } + +}); +client.login(""); \ No newline at end of file diff --git a/test/tsconfig.json b/test/tsconfig.json new file mode 100644 index 0000000..9f765cb --- /dev/null +++ b/test/tsconfig.json @@ -0,0 +1,26 @@ +{ + "version": "2.4.2", + "compilerOptions": { + "lib": [ + "ES2021" + ], + "target": "ES2021", + "module": "CommonJS", + //"module": "system", + "noEmitOnError": true, //Pas de compilation en cas d'erreur, + "strict": true, + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "sourceMap": false, + "outDir": ".", + "rootDir": ".", + "removeComments": false, + "noImplicitAny": true, + "noUnusedLocals": false, + "noUnusedParameters": false, + }, + "exclude": [ + "node_modules" + ] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index ec91f6c..33286db 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,10 +2,10 @@ "version": "2.4.2", "compilerOptions": { "lib": [ - "es6" + "ES2021" ], - "target": "es2021", - "module": "commonjs", + "target": "ES2021", + "module": "CommonJS", //"module": "system", "noEmitOnError": true, //Pas de compilation en cas d'erreur, "strict": true, @@ -13,7 +13,7 @@ "emitDecoratorMetadata": true, "experimentalDecorators": true, "sourceMap": false, - "outDir": "dist", + "outDir": "lib", //"outFile": "./dist/main.js", "rootDir": "./src", "removeComments": false, diff --git a/tsconfig.typing.json b/tsconfig.typing.json index 5c907ef..43644ef 100644 --- a/tsconfig.typing.json +++ b/tsconfig.typing.json @@ -3,7 +3,7 @@ "src/**/*" ], "compilerOptions": { - "target": "ES2020", + "target": "ES2021", "allowJs": true, "declaration": true, "emitDeclarationOnly": true, diff --git a/typing/index.d.ts b/typing/index.d.ts index 40565c7..a7d6ee2 100644 --- a/typing/index.d.ts +++ b/typing/index.d.ts @@ -1,4 +1,4 @@ -import type { Client, Guild, GuildMember, Role, GuildEmoji, GuildChannel } from "discord.js"; +import type { Client, Guild, GuildMember, Role, GuildEmoji, GuildChannel, ThreadChannel } from "discord.js"; export declare class DiscordResolve { client: any; constructor(client: Client); @@ -21,7 +21,7 @@ export declare class DiscordResolve { * @param {string} arg The argument (id, mention, name) * @returns {GuildChannel} */ - resolveChannel: (guild: Guild, arg: string) => GuildChannel; + resolveChannel: (guild: Guild, arg: string) => GuildChannel | ThreadChannel; /** * * @param {string} arg The argument (id, name) @@ -41,11 +41,11 @@ export declare class DiscordResolve { * @param {string} arg The argument (id, name, emoji ) * @returns {GuildEmoji} */ - resolveGuildEmoji: (guild: Guild, arg: string) => Promise; + resolveGuildEmoji: (guild: Guild, arg: string) => GuildEmoji; /** * * @param {GuildMember} member * @returns {boolean} */ - resolveModo: (member: GuildMember) => Promise; + resolveModo: (member: GuildMember) => boolean; }