Skip to content

Commit

Permalink
Merge pull request #1 from Lebyy/development
Browse files Browse the repository at this point in the history
🎉Release 1.0.2!
  • Loading branch information
Lebyy authored Mar 25, 2021
2 parents 1b30f5a + 972ef0b commit a94e03b
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
patreon: Lebyy
github: Lebyy
28 changes: 28 additions & 0 deletions .github/workflows/jsdoc-deploy.yml
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -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:
node-version: 12
registry-url: 'https://npm.pkg.github.com/'
scope: '@lebyy'
- run: npm run gpr
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package-lock.json
test.js
docs/
.npmrc
.replit
.replit
scripts/
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,17 @@ Promise<Object>

It removes a specified amount of messages to the current amount of messages for that user, in that guild.
```js
Messages.subtractXp(<UserID - String>, <GuildID - String>, <Amount - Integer>);
Messages.subtractMessages(<UserID - String>, <GuildID - String>, <Amount - Integer>);
```
- Output:
```
Promise<Boolean/Object>
```
**resetGuild**

It deletes the entire guild's data.
```js
Messages.resetGuild(<GuildID - String>);
```
- Output:
```
Expand Down
21 changes: 11 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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);
}
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;
}
76 changes: 49 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const mongoose = require("mongoose");
const Messages = require("./models/messages.js");
var mongoUrl;
let mongoUrl;

/**
*
Expand All @@ -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,
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
*/
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "discord-messages",
"version": "1.0.1",
"scripts": {
"gpr": "node scripts/gpr.js"
},
"version": "1.0.2",
"description": "A lightweight and easy to use message tracking framework for discord bots, uses MongoDB.",
"main": "index.js",
"dependencies": {
Expand Down Expand Up @@ -39,4 +42,4 @@
"url": "https://github.com/Lebyy/discord-messages/issues"
},
"homepage": "https://discord-messages.js.org"
}
}
8 changes: 8 additions & 0 deletions scripts/gpr.js
Original file line number Diff line number Diff line change
@@ -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));

0 comments on commit a94e03b

Please sign in to comment.