# pie-giveaway

> An npm package that creates giveaways.

Latest version **1.1.0** (published 2021-08-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install pie-giveaway
pnpm add pie-giveaway
yarn add pie-giveaway
bun add pie-giveaway
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2021-08-19 |
| First published | 2021-06-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 1.4 MB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Pie is live |
| Maintainers | pie_is_live |
| Keywords | pie-giveaway, pie-giveaway |

## Links

- npm: https://www.npmjs.com/package/pie-giveaway
- Repository: https://github.com/djpie123/pie-giveaway
- Issues: https://github.com/djpie123/pie-giveaway/issues
- npm.io page: https://npm.io/package/pie-giveaway

## Dependencies (8)

- [ms](https://npm.io/package/ms.md) ^2.1.2
- [events](https://npm.io/package/events.md) ^3.3.0
- [moment](https://npm.io/package/moment.md) ^2.29.1
- [mongoose](https://npm.io/package/mongoose.md) ^5.12.14
- [pretty-ms](https://npm.io/package/pretty-ms.md) ^7.0.1
- [discord.js](https://npm.io/package/discord.js.md) ^12.5.3
- [node-schedule](https://npm.io/package/node-schedule.md) ^2.0.0
- [discord-buttons](https://npm.io/package/discord-buttons.md) ^4.0.0

## Recent versions

- 1.1.0 (latest) — 2021-08-19
- 1.0.9 — 2021-07-07
- 1.0.8 — 2021-07-07
- 1.0.7 — 2021-06-29
- 1.0.0 — 2021-06-29
- 0.0.2 — 2021-06-29

## README

# pie-giveaways
A package for giveaways
# Installation
npm install pie-giveaways
# Examples
![Example for start command](https://imgur.com/X7inDdl.gif)
![Example for create command](https://imgur.com/vkYnqO9.gif)
![Example for Drop command](https://i.imgur.com/N5kPXiM.gif)
# Start
Start by creating a new GiveawayCreator.
```js
const { Client } = require('discord.js');
const client = new Client();
//must add this line or it will throw err and also make sure to add it just after client declaration.
require('discord-buttons')(client);
const { GiveawayCreator } = require('pie-giveaways');
const gwcreator = new GiveawayCreator(client, 'mongodb://...');
const giveaway = gwcreator; // Access the Creator from anywhere.
```
# All Methods
##### startGiveaway(options)
Starts a giveaway. **Example**:
```js
client.on('message', async message => {
    if (message.content.startsWith('!start)) {
        const channel = message.mentions.channels.first();
        await giveaway.startGiveaway({
            prize: 'Discord Nitro Classic',
            channelId: channel.id,
            guildId: message.guild.id,
            duration: 30000, // 30 Seconds
            winners: 1, // 1 winner
            hostedBy: message.author.id
        });
    }
});
```
##### createGiveaway(message)
Creates a giveaway. **Example**:
```js
client.on('message', async message => {
    if (message.content.startsWith('!create')) {
     await giveaway.createGiveaway(message) 
    }
});
```
##### endGiveaway(messageId)
Ends a giveaway. **Example**:
```js
client.on('message', async message => {
    if (message.content.startsWith('!end')) {
        const args = message.content.split(' ').slice(1);
        const ended = await giveaway.endGiveaway(args.join(' '));
        
        if (!ended) {
            return message.channel.send('This giveaway has already ended');
        }
        else {
            message.channel.send('Ended the giveaway');
        }
    }
});
```

##### rerollGiveaway(messageId)
Rerolls a giveaway. **Example**:
```js
client.on('message', async message => {
    if (message.content.startsWith('!end')) {
        const args = message.content.split(' ').slice(1);
        const rerolled = await giveaway.rerollGiveaway(args.join(' '));
        
        if (!rerolled) {
            return message.channel.send('This giveaway hasn\'t ended');
        }
        else {
            message.channel.send('Rerolled the giveaway');
        }
    }
});
```

##### listGiveaways(guildId)
```js
const prettyMilliseconds = require('pretty-ms'); // npm i pretty-ms

client.on('message', async message => {
    if (message.content.startsWith('!list')) {
        const list = await giveaway.listGiveaways(message.guild.id);
        
        if (!list) {
            return message.channel.send('No active giveaways.');
        } else {
            message.channel.send(`${list.map(i => `\`${i.messageId}\` - **${i.prize}** | ${prettyMilliseconds(i.timeRemaining)} | Host: **${i.hostedBy}**`).join('\n')}`)
        }
    }
});
```
##### drop(message, client, options)
Creates a Drop. **Example**:
```js
client.on('message', async message => {
    if (message.content.startsWith('!create')) {
     await giveaway.drop(message, client, {
prize: 'nitro',
hostID: message.author.id
}) 
    }
});
```

---
_Source: https://npm.io/package/pie-giveaway · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
