From 4de1f4ce1c720b6f15c95bf3eb09f88971b51cbd Mon Sep 17 00:00:00 2001 From: Lebyy <45114019+Lebyy@users.noreply.github.com> Date: Thu, 25 Mar 2021 20:37:52 +0530 Subject: [PATCH 1/9] Commits for update 1.0.2! --- README.md | 12 +++++++- index.js | 76 ++++++++++++++++++++++++++++++++------------------ package.json | 3 ++ scripts/gpr.js | 8 ++++++ test.js | 14 ++++++++++ 5 files changed, 85 insertions(+), 28 deletions(-) create mode 100644 scripts/gpr.js create mode 100644 test.js diff --git a/README.md b/README.md index 82ca4f6..1e91ae8 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,17 @@ Promise It removes a specified amount of messages to the current amount of messages for that user, in that guild. ```js -Messages.subtractXp(, , ); +Messages.subtractMessages(, , ); +``` +- Output: +``` +Promise +``` +**resetGuild** + +It deletes the entire guild's data. +```js +Messages.resetGuild(); ``` - Output: ``` diff --git a/index.js b/index.js index 02d9360..99ee8c9 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ const mongoose = require("mongoose"); const Messages = require("./models/messages.js"); -var mongoUrl; +let mongoUrl; /** * @@ -13,12 +13,13 @@ class DiscordMessages { * * * @static - * @param {string} [dbUrl] - A valid mongo database URI. + * @param {string} dbUrl - A valid mongo database URI. * @return {Promise} - The mongoose connection promise. * @memberof DiscordMessages */ static async setURL(dbUrl) { if (!dbUrl) throw new TypeError("A database url was not provided."); + if(mongoUrl) throw new TypeError("A database url was already configured."); mongoUrl = dbUrl; return mongoose.connect(dbUrl, { useNewUrlParser: true, @@ -31,9 +32,9 @@ class DiscordMessages { * * * @static - * @param {string} [userId] - Discord user id. - * @param {string} [guildId] - Discord guild id. - * @return {objcet} - The user data object. + * @param {string} userId - Discord user id. + * @param {string} guildId - Discord guild id. + * @return {object} - The user data object. * @memberof DiscordMessages */ static async createUser(userId, guildId) { @@ -57,9 +58,9 @@ class DiscordMessages { * * * @static - * @param {string} [userId] - Discord user id. - * @param {string} [guildId] - Discord guild id. - * @return {objcet} - The user data object. + * @param {string} userId - Discord user id. + * @param {string} guildId - Discord guild id. + * @return {object} - The user data object. * @memberof DiscordMessages */ static async deleteUser(userId, guildId) { @@ -78,10 +79,10 @@ class DiscordMessages { * * * @static - * @param {string} [userId] - Discord user id. - * @param {string} [guildId] - Discord guild id. - * @param {number} [messages] - Amount of messages to append. - * @return {objcet} - The user data object. + * @param {string} userId - Discord user id. + * @param {string} guildId - Discord guild id. + * @param {number} messages - Amount of messages to append. + * @return {object} - The user data object. * @memberof DiscordMessages */ static async appendMessage(userId, guildId, messages) { @@ -113,10 +114,10 @@ class DiscordMessages { * * * @static - * @param {string} [userId] - Discord user id. - * @param {string} [guildId] - Discord guild id. - * @param {number} [messages] - Amount of messages to set. - * @return {objcet} - The user data object. + * @param {string} userId - Discord user id. + * @param {string} guildId - Discord guild id. + * @param {number} messages - Amount of messages to set. + * @return {object} - The user data object. * @memberof DiscordMessages */ static async setMessages(userId, guildId, messages) { @@ -138,10 +139,10 @@ class DiscordMessages { * * * @static - * @param {string} [userId] - Discord user id. - * @param {string} [guildId] - Discord guild id. + * @param {string} userId - Discord user id. + * @param {string} guildId - Discord guild id. * @param {boolean} [fetchPosition=false] - Wheter to fetch the users position. - * @return {objcet} - The user data object. + * @return {object} - The user data object. * @memberof DiscordMessages */ static async fetch(userId, guildId, fetchPosition = false) { @@ -167,10 +168,10 @@ class DiscordMessages { * * * @static - * @param {string} [userId] - Discord user id. - * @param {string} [guildId] - Discord guild id. - * @param {number} [messages] - Amount of messages to subtract. - * @return {objcet} - The user data object. + * @param {string} userId - Discord user id. + * @param {string} guildId - Discord guild id. + * @param {number} messages - Amount of messages to subtract. + * @return {object} - The user data object. * @memberof DiscordMessages */ static async subtractMessages(userId, guildId, messages) { @@ -188,12 +189,33 @@ class DiscordMessages { return user; } + /** + * + * + * @static + * @param {string} guildId - Discord guild id. + * @return {boolean} - Return's true if success. + * @memberof DiscordMessages + */ + static async resetGuild(guildId) { + if (!guildId) throw new TypeError("A guild id was not provided."); + + const user = await Messages.findOne({ guildID: guildId }); + if (!user) return false; + + await Messages.findOneAndDelete({ + guildID: guildId + }).catch(e => console.log(`Failed to reset guild: ${e}`)); + + return true; + } + /** * * * @static - * @param {string} [guildId] - Discord guild id. - * @param {number} [limit] - Amount of maximum enteries to return. + * @param {string} guildId - Discord guild id. + * @param {number} limit - Amount of maximum enteries to return. * @return {Array} - The leaderboard array. * @memberof DiscordMessages */ @@ -210,8 +232,8 @@ class DiscordMessages { * * * @static - * @param {string} [client] - Your Discord.CLient. - * @param {array} [leaderboard] - The output from 'fetchLeaderboard' function. + * @param {string} client - Your Discord.CLient. + * @param {array} leaderboard - The output from 'fetchLeaderboard' function. * @param {boolean} [fetchUsers=false] - Wheter to fetch each users position. * @return {*} * @memberof DiscordMessages diff --git a/package.json b/package.json index b11dbf3..b79b6a6 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,8 @@ { "name": "discord-messages", + "scripts": { + "gpr": "node scripts/gpr.js" + }, "version": "1.0.1", "description": "A lightweight and easy to use message tracking framework for discord bots, uses MongoDB.", "main": "index.js", diff --git a/scripts/gpr.js b/scripts/gpr.js new file mode 100644 index 0000000..fb765c8 --- /dev/null +++ b/scripts/gpr.js @@ -0,0 +1,8 @@ +const fs = require('fs'); +const { join } = require('path'); + +const pkg = require('../package.json'); + +pkg.name = `@Lebyy/${pkg.name}`; + +fs.writeFileSync(join(__dirname, '../package.json'), JSON.stringify(pkg)); \ No newline at end of file diff --git a/test.js b/test.js new file mode 100644 index 0000000..b4f9865 --- /dev/null +++ b/test.js @@ -0,0 +1,14 @@ +const Messages = require("./index.js"); +async function lol(){ +let e = await Messages.setURL("mongodb+srv://arc:arcisthebest@arc.lx8o9.mongodb.net/testdb?retryWrites=true&w=majority"); +//console.log(e) +const hasLeveledUp = await Messages.appendMessage("541282732609765377", "630058179547627592", "1"); +const hasLeveledUp1 = await Messages.appendMessage("725619404330631229", "630058179547627592", "1"); +//console.log(hasLeveledUp) +const user = await Messages.fetch("541282732609765377", "630058179547627592", true); +console.log(user) + +const rawLeaderboard = await Messages.fetchLeaderboard("630058179547627592", 10); +//console.log(rawLeaderboard) +} +lol() \ No newline at end of file From 0827907bd7b176ab3ad40b7d65f4d6384a0fdb38 Mon Sep 17 00:00:00 2001 From: Lebyy <45114019+Lebyy@users.noreply.github.com> Date: Thu, 25 Mar 2021 20:39:10 +0530 Subject: [PATCH 2/9] Create FUNDING.yml --- .github/FUNDING.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..76b33ab --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +patreon: Lebyy +github: Lebyy From b3ffe64ecbd723f576cf36a396810d57a3a892d9 Mon Sep 17 00:00:00 2001 From: Lebyy <45114019+Lebyy@users.noreply.github.com> Date: Thu, 25 Mar 2021 20:39:33 +0530 Subject: [PATCH 3/9] Add files via upload --- .github/workflows/jsdoc-deploy.yml | 28 +++++++++++++++++++++++ .github/workflows/npm-publish.yml | 36 ++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 .github/workflows/jsdoc-deploy.yml create mode 100644 .github/workflows/npm-publish.yml diff --git a/.github/workflows/jsdoc-deploy.yml b/.github/workflows/jsdoc-deploy.yml new file mode 100644 index 0000000..5ef12e7 --- /dev/null +++ b/.github/workflows/jsdoc-deploy.yml @@ -0,0 +1,28 @@ +name: GitHub pages + +on: + push: + branches: + - master + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Build + uses: andstor/jsdoc-action@v1 + with: + output_dir: ./docs + config_file: .jsdoc.json + template: Androz2091/jsdoc-skyceil + front_page: README.md + + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs + cname: discord-messages.js.org \ No newline at end of file diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..6704c6f --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,36 @@ +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created +# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages + +name: Node.js Package + +on: + release: + types: [created] + +jobs: + + publish-npm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 12 + registry-url: https://registry.npmjs.org/ + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.npm_token}} + + publish-gpr: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + registry-url: 'https://npm.pkg.github.com/' + scope: '@Lebyy' + - run: npm install + - run: npm run gpr + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 4b4916aab72dd3568647f09e0b5dac10e82b9b65 Mon Sep 17 00:00:00 2001 From: Lebyy <45114019+Lebyy@users.noreply.github.com> Date: Thu, 25 Mar 2021 20:47:53 +0530 Subject: [PATCH 4/9] Update .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 71b87bc..27101f6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ package-lock.json test.js docs/ .npmrc -.replit \ No newline at end of file +.replit +scripts/ From 1e2ed3bb41339deaaa0f77bea0fe4e2e2d162068 Mon Sep 17 00:00:00 2001 From: Lebyy <45114019+Lebyy@users.noreply.github.com> Date: Thu, 25 Mar 2021 21:00:16 +0530 Subject: [PATCH 5/9] Updating typings --- index.d.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/index.d.ts b/index.d.ts index 842354d..5315e31 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,12 +1,13 @@ export class DiscordMessages{ -public setURL(dbUrl:string); -public createUser(userId:string, guildId:string); -public deleteUser(userId:string, guildId:string); -public appendMessage(userId:string, guildId:string, messages:number); -public setMessages(userId:string, guildId:string, messages:number); -public fetch(userId:string, guildId:string, fetchPosition:boolean); -public subtractMessages(userId:string, guildId:string, messages:number); -public fetchLeaderboard(guildId:string, limit:number); -public computeLeaderboard(client:any, leaderboard:any, fetchUsers:boolean); -} \ No newline at end of file +public setURL(dbUrl:string): object; +public createUser(userId:string, guildId:string): object; +public deleteUser(userId:string, guildId:string): object; +public appendMessage(userId:string, guildId:string, messages:number): object; +public setMessages(userId:string, guildId:string, messages:number): object; +public fetch(userId:string, guildId:string, fetchPosition:boolean): object; +public subtractMessages(userId:string, guildId:string, messages:number): object; +public resetGuild(guildId:string): object; +public fetchLeaderboard(guildId:string, limit:number): object; +public computeLeaderboard(client:any, leaderboard:any, fetchUsers:boolean): object; +} From 672b95cd77033ff115d0f72f36e931b026e81d28 Mon Sep 17 00:00:00 2001 From: Lebyy <45114019+Lebyy@users.noreply.github.com> Date: Thu, 25 Mar 2021 21:01:25 +0530 Subject: [PATCH 6/9] Delete test.js --- test.js | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 test.js diff --git a/test.js b/test.js deleted file mode 100644 index b4f9865..0000000 --- a/test.js +++ /dev/null @@ -1,14 +0,0 @@ -const Messages = require("./index.js"); -async function lol(){ -let e = await Messages.setURL("mongodb+srv://arc:arcisthebest@arc.lx8o9.mongodb.net/testdb?retryWrites=true&w=majority"); -//console.log(e) -const hasLeveledUp = await Messages.appendMessage("541282732609765377", "630058179547627592", "1"); -const hasLeveledUp1 = await Messages.appendMessage("725619404330631229", "630058179547627592", "1"); -//console.log(hasLeveledUp) -const user = await Messages.fetch("541282732609765377", "630058179547627592", true); -console.log(user) - -const rawLeaderboard = await Messages.fetchLeaderboard("630058179547627592", 10); -//console.log(rawLeaderboard) -} -lol() \ No newline at end of file From a8f02a55f4179b451b51f4ae2df1663f777232bd Mon Sep 17 00:00:00 2001 From: Lebyy <45114019+Lebyy@users.noreply.github.com> Date: Thu, 25 Mar 2021 21:12:42 +0530 Subject: [PATCH 7/9] Update package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b79b6a6..54623fb 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "scripts": { "gpr": "node scripts/gpr.js" }, - "version": "1.0.1", + "version": "1.0.2", "description": "A lightweight and easy to use message tracking framework for discord bots, uses MongoDB.", "main": "index.js", "dependencies": { @@ -42,4 +42,4 @@ "url": "https://github.com/Lebyy/discord-messages/issues" }, "homepage": "https://discord-messages.js.org" -} \ No newline at end of file +} From 7b835b4bc52ac3fb135e7452c1d398e99f399452 Mon Sep 17 00:00:00 2001 From: Lebyy <45114019+Lebyy@users.noreply.github.com> Date: Thu, 25 Mar 2021 21:12:54 +0530 Subject: [PATCH 8/9] Update gpr.js --- scripts/gpr.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/gpr.js b/scripts/gpr.js index fb765c8..29fa39f 100644 --- a/scripts/gpr.js +++ b/scripts/gpr.js @@ -3,6 +3,6 @@ const { join } = require('path'); const pkg = require('../package.json'); -pkg.name = `@Lebyy/${pkg.name}`; +pkg.name = `@lebyy/${pkg.name}`; -fs.writeFileSync(join(__dirname, '../package.json'), JSON.stringify(pkg)); \ No newline at end of file +fs.writeFileSync(join(__dirname, '../package.json'), JSON.stringify(pkg)); From 972ef0b0d6543b51a5e09b209b0bf369bfa4969f Mon Sep 17 00:00:00 2001 From: Lebyy <45114019+Lebyy@users.noreply.github.com> Date: Thu, 25 Mar 2021 21:13:30 +0530 Subject: [PATCH 9/9] Update npm-publish.yml --- .github/workflows/npm-publish.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 6704c6f..65b8f4c 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -27,10 +27,10 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: + node-version: 12 registry-url: 'https://npm.pkg.github.com/' - scope: '@Lebyy' - - run: npm install + scope: '@lebyy' - run: npm run gpr - run: npm publish env: - NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}