Skip to content

Commit

Permalink
Features/upgrade djs13 (#2)
Browse files Browse the repository at this point in the history
* feat: Support DJS13

* fix: correct issue when sending a reply from guild

* docs: specify that djs13 requires upgrade of node
  • Loading branch information
HunteRoi authored Oct 17, 2021
1 parent e7681bf commit 30b13a9
Show file tree
Hide file tree
Showing 21 changed files with 2,096 additions and 842 deletions.
60 changes: 45 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
<a href="https://www.npmjs.com/package/@hunteroi/discord-mailbox"><img src="https://badge.fury.io/js/%40hunteroi%2Fdiscord-mailbox.svg" alt="npm version" height="18"></a>

# Discord Mailbox

Discord Mailbox is a framework to easily add a mailbox inside your bot. The feature is also fully customizable.

- Supports multiple tickets per users
- Logs everything like you want it
- Emits events like `ticketCreate`, `ticketUpdate` and **6 more**
- Allow full customization of the embed (you can add image, thumbnail, etc)
- And much more!
- Supports multiple tickets per users
- Logs everything like you want it
- Emits events like `ticketCreate`, `ticketUpdate` and **6 more**
- Allow full customization of the embed (you can add image, thumbnail, etc)
- And much more!

![IMAGE](./assets/example.gif)

## Prerequisites ⚠️

Starting at **v2.0.0**, you must use **NodeJS v16.6.0 or higher** to run a bot with this library.

You also must not forget to include [mandatory intents and partials](#mandatory-intents-and-partials) as well as give your bot the rights to read messages.

### Mandatory intents and partials

- GUILDS: used to access guild content such as channels.
- GUILD_MESSAGES: used to read guild messages.
- GUILD_MESSAGE_REACTIONS: used to access guild messages reactions.
- DIRECT_MESSAGES: used to access direct messages to the bot.
- CHANNEL: used to receive events when the bot is DMed.
- MESSAGE: used to read the messages even if incomplete.

## Installation

Expand All @@ -16,34 +34,46 @@ npm install --save @hunteroi/discord-mailbox
```

## Examples
See [./example/index.js](example/index.js).

![IMAGE](assets/example.gif)
See [./example/index.js](example/index.js).

## Events

```ts
manager.on('ticketCreate', (ticket: Ticket) => {});
manager.on(MailboxManagerEvents.ticketCreate, (ticket: Ticket) => {});

manager.on('ticketUpdate', (ticket: Ticket) => {});
manager.on(MailboxManagerEvents.ticketUpdate, (ticket: Ticket) => {});

manager.on('ticketLog', (ticket: Ticket) => {});
manager.on(MailboxManagerEvents.ticketLog, (ticket: Ticket) => {});

manager.on('ticketClose', (ticket: Ticket) => {});
manager.on(MailboxManagerEvents.ticketClose, (ticket: Ticket) => {});

manager.on('ticketForceClose', (ticket: Ticket, user: User | PartialUser) => {});
manager.on(
MailboxManagerEvents.ticketForceClose,
(ticket: Ticket, user: User | PartialUser) => {}
);

manager.on('ticketDelete', (ticket: Ticket) => {});
manager.on(MailboxManagerEvents.ticketDelete, (ticket: Ticket) => {});

manager.on('replySent', (message: Message, answer: Message) => {});
manager.on(
MailboxManagerEvents.replySent,
(message: Message, answer: Message) => {}
);

manager.on('replyDelete', (message: Message) => {});
manager.on(MailboxManagerEvents.replyDelete, (message: Message) => {});
```

## Contribution

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

1. Fork the Project
2. Create your Branch: `git checkout -b patch/YourAmazingWork`
3. Commit your Changes: `git commit -m 'Add some amazing work'`
4. Push to the Branch: `git push origin patch/YourAmazingWork`
5. Open a Pull Request

## Todo

- auto reply when a ticket is opened
- support thread
110 changes: 72 additions & 38 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,81 @@
const { Client } = require('discord.js');
const { MailboxManager } = require('../lib');
const { Client, Intents, Constants } = require('discord.js');

const client = new Client();
const { MailboxManager, MailboxManagerEvents } = require('../lib');

const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGES,
],
partials: [Constants.PartialTypes.CHANNEL, Constants.PartialTypes.MESSAGE],
});
const manager = new MailboxManager(client, {
forceCloseEmoji: '❌',
replySentEmoji: '📤',
loggingOptions: {
generateFilename: ticket => `log-ticket-${ticket.id}.txt`,
format: msg => `[${new Date(msg.createdTimestamp)}] ${msg.author.username} | ${msg.cleanContent}`,
generateMessage: ticket => `Logs for ticket ${ticket.id} - closed at ${new Date(ticket.closedAt)}`,
sendToRecipient: false,
channel: 'LOG_CHANNEL_ID',
showName: false
},
mailboxChannel: 'MAIL_CHANNEL_ID',
deleteReplies: true,
cronTime: '* * * * *', // run each minute
closeTicketAfter: 60, // in seconds
maxOngoingTicketsPerUser: 3,
notAllowedToPing: 'You are not allowed to mention @everyone or @here in a mail!',
replyMessage: 'Please use the "reply" feature to send an answer to this message.',
tooMuchTickets: 'You have too much tickets that are not closed! Please wait for your tickets to be closed before submitting new ones.',
ticketClose: nbTickets => `This ticket has been closed due to inactivity or manually by the receiver. You now have ${nbTickets} tickets left opened.`,
replyMessageInFooter: true,
embedOptions: {
send: true,
color: 12272523
},
formatTitle: id => `[Ticket] ${id}`
forceCloseEmoji: '❌',
replySentEmoji: '📤',
loggingOptions: {
generateFilename: (ticket) => `log-ticket-${ticket.id}.txt`,
format: (msg) =>
`[${new Date(msg.createdTimestamp)}] ${msg.author.username} | ${
msg.cleanContent
}`,
generateMessage: (ticket) =>
`Logs for ticket ${ticket.id} - closed at ${new Date(
ticket.closedAt
)}`,
sendToRecipient: false,
channel: 'TEXT_CHANNEL_ID',
showName: false,
},
mailboxChannel: 'TEXT_CHANNEL_ID',
deleteReplies: true,
cronTime: '* * * * *', // run each minute
closeTicketAfter: 60, // in seconds
maxOngoingTicketsPerUser: 3,
notAllowedToPing:
'You are not allowed to mention @everyone or @here in a mail!',
replyMessage:
'Please use the "reply" feature to send an answer to this message.',
tooMuchTickets:
'You have too much tickets that are not closed! Please wait for your tickets to be closed before submitting new ones.',
ticketClose: (nbTickets) =>
`This ticket has been closed due to inactivity or manually by the receiver. You now have ${nbTickets} tickets left opened.`,
replyMessageInFooter: true,
embedOptions: {
send: true,
color: 12272523,
},
formatTitle: (id) => `[Ticket] ${id}`,
});

client.on('ready', () => console.log('Connected!'));

client.on('message', message => {
if (message.content === 'show me the tickets collection') {
message.reply(`\`\`\`js\n${JSON.stringify(manager.userTickets, null, 2)}\n\`\`\``);
}
})
client.on('messageCreate', (message) => {
if (message.content === 'show me the tickets collection') {
message.reply(
`\`\`\`js\n${JSON.stringify(manager.userTickets, null, 2)}\n\`\`\``
);
}
});

manager.on('ticketCreate', ticket => console.log(`${ticket.id} has been created!`));
manager.on('ticketUpdate', ticket => console.log(`${ticket.id} has been updated with a new message.`));
manager.on('ticketLog', (ticket) => console.log(`${ticket.id} got logged.`));
manager.on('ticketClose', ticket => console.log(`${ticket.id} got closed!`));
manager.on('ticketDelete', ticket => console.log(`${ticket.id} got deleted.`));
manager.on(MailboxManagerEvents.ticketCreate, (ticket) =>
console.log(`${ticket.id} has been created!`)
);
manager.on(MailboxManagerEvents.ticketUpdate, (ticket) =>
console.log(`${ticket.id} has been updated with a new message.`)
);
manager.on(MailboxManagerEvents.ticketLog, (ticket) =>
console.log(`${ticket.id} got logged.`)
);
manager.on(MailboxManagerEvents.ticketClose, (ticket) =>
console.log(`${ticket.id} got closed!`)
);
manager.on(MailboxManagerEvents.ticketForceClose, (ticket, user) =>
console.log(`${user.username} forced closed ticket ${ticket.id}.`)
);
manager.on(MailboxManagerEvents.ticketDelete, (ticket) =>
console.log(`${ticket.id} got deleted.`)
);

client.login('TOKEN');
Loading

0 comments on commit 30b13a9

Please sign in to comment.