Skip to content

Commit

Permalink
🔖 v5.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico105 authored Jan 23, 2022
2 parents fbf9e1b + f0d0724 commit 776e2c0
Show file tree
Hide file tree
Showing 16 changed files with 760 additions and 532 deletions.
25 changes: 24 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@
"accessor-pairs": "off",
"no-async-promise-executor": "off",
"no-unused-vars": "off",
"node/no-missing-require": "off"
"node/no-missing-require": "off",
"no-restricted-globals": [
"error",
{
"name": "Buffer",
"message": "Import Buffer from `node:buffer` instead"
},
{
"name": "process",
"message": "Import process from `node:process` instead"
},
{
"name": "setTimeout",
"message": "Import setTimeout from `node:timers` instead"
},
{
"name": "setInterval",
"message": "Import setInterval from `node:timers` instead"
},
{
"name": "setImmediate",
"message": "Import setImmediate from `node:timers` instead"
}
]
}
}
16 changes: 2 additions & 14 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,9 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 16.6
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/
- run: npm install
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"printWidth": 200,
"printWidth": 120,
"trailingComma": "none",
"singleQuote": true,
"tabWidth": 4,
Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript"]
}
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ client.giveawaysManager.start(interaction.channel, {
isPaused: true,
content: '⚠️ **THIS GIVEAWAY IS PAUSED !** ⚠️',
unPauseAfter: null,
embedColor: '#FFFF00'
embedColor: '#FFFF00',
infiniteDurationText: '`NEVER`'
}
});
```
Expand All @@ -350,6 +351,8 @@ client.giveawaysManager.start(interaction.channel, {
^^^ You can [access giveaway properties](https://github.com/Androz2091/discord-giveaways#access-giveaway-properties-in-messages).
- **pauseOptions.unPauseAfter**: the number of milliseconds after which the giveaway will automatically unpause.
- **pauseOptions.embedColor**: the color of the embed when the giveaway is paused.
- **pauseOptions.infiniteDurationText**: The text that gets displayed next to "GiveawayMessages#drawing" in the paused embed, when there is no "unPauseAfter".
^^^ You can [access giveaway properties](https://github.com/Androz2091/discord-giveaways#access-giveaway-properties-in-messages).

<a href="https://zupimages.net/viewer.php?id=21/24/dxhk.png">
<img src="https://zupimages.net/up/21/24/dxhk.png"/>
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-databases/mongoose.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Discord = require('discord.js'),

// Connect to the database
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/giveaways');
mongoose.connect('mongodb://localhost/database');
const db = mongoose.connection;

// Check the connection
Expand Down
16 changes: 8 additions & 8 deletions examples/custom-databases/nano.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const Discord = require('discord.js'),
const nano = require('nano')('http://admin:mypassword@localhost:5984');
let giveawayDB;

// Check the DB
(async () => {
if (!(await nano.db.list()).includes('giveaways')) await nano.db.create('giveaways');
giveawayDB = nano.use('giveaways');
// Start the manager only after the DB got checked to prevent an error
client.giveawaysManager._init();
})();

const { GiveawaysManager } = require('discord-giveaways');
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
// This function is called when the manager needs to get all giveaways which are stored in the database.
Expand Down Expand Up @@ -63,14 +71,6 @@ const manager = new GiveawayManagerWithOwnDatabase(client, {
// We now have a giveawaysManager property to access the manager everywhere!
client.giveawaysManager = manager;

// Check the DB
(async () => {
if (!(await nano.db.list()).includes('giveaways')) await nano.db.create('giveaways');
giveawayDB = nano.use('giveaways');
// Start the manager only after the DB got checked to prevent an error
client.giveawaysManager._init();
})();

client.on('ready', () => {
console.log('I\'m ready!');
});
Expand Down
14 changes: 7 additions & 7 deletions examples/custom-databases/quick.replit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ const Discord = require('discord.js'),
const { Database } = require('quick.replit');
const db = new Database();

// Check the DB when it is ready
db.once('ready', async () => {
if (!Array.isArray(await db.get('giveaways'))) await db.set('giveaways', []);
// Start the manager only after the DB got checked to prevent an error
client.giveawaysManager._init();
});

const { GiveawaysManager } = require('discord-giveaways');
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
// This function is called when the manager needs to get all giveaways which are stored in the database.
Expand Down Expand Up @@ -69,13 +76,6 @@ const manager = new GiveawayManagerWithOwnDatabase(client, {
// We now have a giveawaysManager property to access the manager everywhere!
client.giveawaysManager = manager;

// Check the DB when it is ready
db.on('ready', async () => {
if (!Array.isArray(await db.get('giveaways'))) await db.set('giveaways', []);
// Start the manager only after the DB got checked to prevent an error
client.giveawaysManager._init();
});

client.on('ready', () => {
console.log('I\'m ready!');
});
Expand Down
34 changes: 10 additions & 24 deletions examples/custom-databases/quickmongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,39 @@ const Discord = require('discord.js'),

// Load quickmongo
const { Database } = require('quickmongo');
const db = new Database('mongodb://localhost/giveaways');
const giveawayDB = new Database('mongodb://localhost/database', { collectionName: 'giveaways' });

// Start the manager only after the DB turned ready to prevent an error
giveawayDB.once('ready', () => client.giveawaysManager._init());

const { GiveawaysManager } = require('discord-giveaways');
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
// This function is called when the manager needs to get all giveaways which are stored in the database.
async getAllGiveaways() {
// Get all giveaways from the database
return await db.get('giveaways');
return await giveawayDB.all();
}

// This function is called when a giveaway needs to be saved in the database.
async saveGiveaway(messageId, giveawayData) {
// Add the new giveaway to the database
await db.push('giveaways', giveawayData);
await giveawayDB.set(messageId, giveawayData);
// Don't forget to return something!
return true;
}

// This function is called when a giveaway needs to be edited in the database.
async editGiveaway(messageId, giveawayData) {
// Get all giveaways from the database
const giveaways = await db.get('giveaways');
// Remove the unedited giveaway from the array
const newGiveawaysArray = giveaways.filter((giveaway) => giveaway.messageId !== messageId);
// Push the edited giveaway into the array
newGiveawaysArray.push(giveawayData);
// Save the updated array
await db.set('giveaways', newGiveawaysArray);
// Replace the unedited giveaway with the edited giveaway
await giveawayDB.set(messageId, giveawayData);
// Don't forget to return something!
return true;
}

// This function is called when a giveaway needs to be deleted from the database.
async deleteGiveaway(messageId) {
// Get all giveaways from the database
const giveaways = await db.get('giveaways');
// Remove the giveaway from the array
const newGiveawaysArray = giveaways.filter((giveaway) => giveaway.messageId !== messageId);
// Save the updated array
await db.set('giveaways', newGiveawaysArray);
// Remove the giveaway from the database
await giveawayDB.delete(messageId);
// Don't forget to return something!
return true;
}
Expand All @@ -69,13 +62,6 @@ const manager = new GiveawayManagerWithOwnDatabase(client, {
// We now have a giveawaysManager property to access the manager everywhere!
client.giveawaysManager = manager;

// Check the DB when it is ready
db.on('ready', async () => {
if (!Array.isArray(await db.get('giveaways'))) await db.set('giveaways', []);
// Start the manager only after the DB got checked to prevent an error
client.giveawaysManager._init();
});

client.on('ready', () => {
console.log('I\'m ready!');
});
Expand Down
2 changes: 1 addition & 1 deletion examples/sharding.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const GiveawayManagerWithShardSupport = class extends GiveawaysManager {

// Create a new instance of your new class
const manager = new GiveawayManagerWithShardSupport(client, {
storage: './storage.json',
storage: './giveaways.json',
default: {
botsCanWin: false,
embedColor: '#FF0000',
Expand Down
20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-giveaways",
"version": "5.0.1",
"version": "5.1.0",
"description": "A complete framework to facilitate the creation of giveaways using discord.js",
"main": "index.js",
"exports": {
Expand All @@ -11,16 +11,18 @@
},
"./index.js"
],
"./": "./",
"./*": "./",
"./esm": "./esm.mjs"
},
"types": "typings/index.d.ts",
"files": [
"src/",
"typings/"
"typings/",
"esm.mjs"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint .",
"generate-docs": "jsdoc node_modules/.bin/jsdoc --configure .jsdoc.json --verbose"
},
"repository": {
Expand All @@ -39,23 +41,29 @@
"giveaway"
],
"author": "Androz2091",
"contributors": [
"Nico105"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/Androz2091/discord-giveaways/issues"
},
"homepage": "https://discord-giveaways.js.org",
"dependencies": {
"deepmerge": "^4.2.2",
"discord.js": "^13.1.0",
"serialize-javascript": "^6.0.0"
},
"devDependencies": {
"@types/node": "^16.6.0",
"eslint": "^7.32.0",
"discord.js": "^13.5.0",
"eslint": "^8.5.0",
"eslint-plugin-node": "^11.1.0",
"jsdoc": "^3.6.4",
"jsdoc-skyceil": "Androz2091/jsdoc-skyceil",
"typescript": "^4.4.2"
"typescript": "^4.5.4"
},
"peerDependencies": {
"discord.js": ">=13.5.0"
},
"engines": {
"node": ">=16.6.0"
Expand Down
9 changes: 6 additions & 3 deletions src/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ exports.GiveawayMessages = {
*
* @property {string} [content] The raw message
* @property {Discord.MessageEmbed|Discord.MessageEmbedOptions} [embed] The embed
* @property {Boolean} [replyToGiveaway] If the sent message should reply to the giveaway embed.
*/

/**
Expand Down Expand Up @@ -106,14 +107,16 @@ exports.LastChanceOptions = {
* @property {string} [content='⚠️ **THIS GIVEAWAY IS PAUSED !** ⚠️'] The text of the embed when the giveaway is paused.
* @property {number} [unPauseAfter=null] The number of milliseconds after which the giveaway will automatically unpause.
* @property {Discord.EmbedColorResolveAble} [embedColor='#FFFF00'] The color of the embed when the giveaway is paused.
* @property {number} [durationAfterPause=null|giveaway.remainingTime] The remaining duration after the giveaway is unpaused. ⚠ This property gets set by the manager so that the pause system works properly. It is not recommended to set it manually!
* @private @property {number} [durationAfterPause=null|giveaway.remainingTime] The remaining duration after the giveaway is unpaused. ⚠ This property gets set by the manager so that the pause system works properly. It is not recommended to set it manually!
* @property {string} [infiniteDurationText='`NEVER`'] The text that gets displayed next to "GiveawayMessages#drawing" in the paused embed, when there is no "unPauseAfter".
*/
exports.PauseOptions = {
isPaused: false,
content: '⚠️ **THIS GIVEAWAY IS PAUSED !** ⚠️',
unPauseAfter: null,
embedColor: '#FFFF00',
durationAfterPause: null
durationAfterPause: null,
infiniteDurationText: '`NEVER`'
};

/**
Expand Down Expand Up @@ -199,7 +202,7 @@ exports.GiveawayEditOptions = {};
* @property {Discord.Snowflake} channelId The Id of the channel.
* @property {Discord.Snowflake} guildId The Id of the guild.
* @property {Discord.Snowflake[]} [winnerIds] The winner Ids of the giveaway after it ended.
* @property {Discord.Snowflake} [messageId] The Id of the message.
* @property {Discord.Snowflake} messageId The Id of the message.
* @property {Discord.EmojiIdentifierResolvable} [reaction] The reaction to participate in the giveaway.
* @property {boolean} [botsCanWin] If bots can win the giveaway.
* @property {Discord.PermissionResolvable[]} [exemptPermissions] Members with any of these permissions will not be able to win the giveaway.
Expand Down
Loading

0 comments on commit 776e2c0

Please sign in to comment.