Skip to content

Commit

Permalink
💥 Rename Giveaway#time to Giveaway#duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Androz2091 committed Aug 29, 2021
1 parent 936fe6c commit a2f7025
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ client.on('interactionCreate', (interaction) => {
// /start-giveaway 2d 1 Awesome prize!
// Will create a giveaway with a duration of two days, with one winner and the prize will be "Awesome prize!"

const time = interaction.options.getString('time');
const duration = interaction.options.getString('duration');
const winnerCount = interaction.options.getInteger('winner_count');
const prize = interaction.options.getString('prize');

client.giveawaysManager.start(interaction.channel, {
time: ms(time),
duration: ms(duration),
winnerCount,
prize
}).then((gData) => {
Expand All @@ -104,7 +104,7 @@ client.on('interactionCreate', (interaction) => {
});
```

- **options.time**: the giveaway duration.
- **options.duration**: the giveaway duration.
- **options.prize**: the giveaway prize. You can [access giveaway properties](https://github.com/Androz2091/discord-giveaways#access-giveaway-properties-in-messages).
- **options.winnerCount**: the number of giveaway winners.
- **[and many other optional parameters to customize the giveaway - read documentation](https://discord-giveaways.js.org/global.html#GiveawayStartOptions)**
Expand Down Expand Up @@ -181,7 +181,7 @@ client.on('interactionCreate', (interaction) => {
- **options.newBonusEntries**: the new BonusEntry objects (for example, to change the amount of entries).
- **options.newLastChance**: the new options for the last chance system. Will get merged with the existing object, if there.

**Note**: to reduce giveaway time, define `addTime` with a negative number! For example `addTime: -5000` will reduce giveaway time by 5 seconds!
**Note**: to reduce giveaway duration, define `addDuration` with a negative number! For example `addDuration: -5000` will reduce giveaway duration by 5 seconds!

### Delete a giveaway

Expand Down Expand Up @@ -278,7 +278,7 @@ Function to filter members. If true is returned, the member will not be able to

```js
client.giveawaysManager.start(interaction.channel, {
time: 60000,
duration: 60000,
winnerCount: 1,
prize: 'Free Steam Key',
// Only members who have the "Nitro Boost" role are able to win
Expand All @@ -292,7 +292,7 @@ client.giveawaysManager.start(interaction.channel, {
const roleName = 'Nitro Boost';

client.giveawaysManager.start(interaction.channel, {
time: 60000,
duration: 60000,
winnerCount: 1,
prize: 'Free Steam Key',
// Only members who have the the role which is assigned to "roleName" are able to win
Expand All @@ -311,7 +311,7 @@ _The special format would "convert" the external string snowflake into a number,

```js
client.giveawaysManager.start(interaction.channel, {
time: 60000,
duration: 60000,
winnerCount: 1,
prize: 'Discord Nitro!',
lastChance: {
Expand All @@ -336,7 +336,7 @@ client.giveawaysManager.start(interaction.channel, {

```js
client.giveawaysManager.start(interaction.channel, {
time: 60000,
duration: 60000,
winnerCount: 1,
prize: 'Discord Nitro!',
pauseOptions: {
Expand All @@ -361,7 +361,7 @@ client.giveawaysManager.start(interaction.channel, {

```js
client.giveawaysManager.start(interaction.channel, {
time: 60000,
duration: 60000,
winnerCount: 1,
prize: 'Free Steam Key',
bonusEntries: [
Expand All @@ -384,7 +384,7 @@ const roleName = 'Nitro Boost';
const roleBonusEntries = 2;

client.giveawaysManager.start(interaction.channel, {
time: 60000,
duration: 60000,
winnerCount: 1,
prize: 'Free Steam Key',
bonusEntries: [
Expand Down Expand Up @@ -440,10 +440,14 @@ You can also pass a `messages` parameter for `start()` function, if you want to
For example:

```js
const duration = interaction.options.getString('duration');
const winnerCount = interaction.options.getInteger('winnerCount');
const prize = interaction.options.getString('prize');

client.giveawaysManager.start(interaction.channel, {
time: ms(args[0]),
winnerCount: parseInt(args[1]),
prize: args.slice(2).join(' '),
duration: ms(duration),
winnerCount,
prize,
messages: {
giveaway: '🎉🎉 **GIVEAWAY** 🎉🎉',
giveawayEnded: '🎉🎉 **GIVEAWAY ENDED** 🎉🎉',
Expand Down
2 changes: 1 addition & 1 deletion src/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exports.GiveawayMessages = {
* The start options for new giveaways.
* @typedef GiveawayStartOptions
*
* @property {number} time The giveaway duration.
* @property {number} duration The giveaway duration (milliseconds).
* @property {number} winnerCount The number of winners for the giveaway.
* @property {string} prize The giveaway prize.
* @property {Discord.User} [hostedBy] The user who hosts the giveaway.
Expand Down
8 changes: 4 additions & 4 deletions src/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class GiveawaysManager extends EventEmitter {
* manager.start(message.channel, {
* prize: 'Free Steam Key',
* // Giveaway will last 10 seconds
* time: 10000,
* duration: 10000,
* // One winner
* winnerCount: 1,
* // Limit the giveaway to members who have the "Nitro Boost" role
Expand All @@ -217,8 +217,8 @@ class GiveawaysManager extends EventEmitter {
: Discord.Permissions.FLAGS.SEND_MESSAGES
])
) return reject(`The manager is unable to send messages in the provided ThreadChannel. (id=${channel.id})`);
if (isNaN(options.time) || typeof options.time !== 'number' || options.time < 1) {
return reject(`options.time is not a positive number. (val=${options.time})`);
if (isNaN(options.duration) || typeof options.duration !== 'number' || options.duration < 1) {
return reject(`options.duration is not a positive number. (val=${options.duration})`);
}
if (typeof options.prize !== 'string' || options.prize.length > 256) {
return reject(`options.prize is not a string or longer than 256 characters. (val=${options.prize})`);
Expand All @@ -232,7 +232,7 @@ class GiveawaysManager extends EventEmitter {

const giveaway = new Giveaway(this, {
startAt: Date.now(),
endAt: Date.now() + options.time,
endAt: Date.now() + options.duration,
winnerCount: options.winnerCount,
channelId: channel.id,
guildId: channel.guildId,
Expand Down
2 changes: 1 addition & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ declare module 'discord-giveaways' {
};
}
interface GiveawayStartOptions {
time: number;
duration: number;
winnerCount: number;
prize: string;
hostedBy?: User;
Expand Down

0 comments on commit a2f7025

Please sign in to comment.