From 18883d5d2023feb3fed5b5c440aa33c8a892c432 Mon Sep 17 00:00:00 2001 From: Isaac Date: Mon, 22 Feb 2021 00:05:37 +0000 Subject: [PATCH] do stuff --- .github/CODE_OF_CONDUCT.md | 76 +++++++++++++++++++++++++++++ .github/CONTRIBUTING.md | 82 +++++++++++++++++++++++++++----- .github/PULL_REQUEST_TEMPLATE.md | 19 ++++---- src/database/index.js | 74 ++++------------------------ src/listeners/message.js | 24 +++++++--- src/listeners/messageDelete.js | 29 +++++++++++ src/listeners/messageUpdate.js | 44 ++++++++++++++++- src/listeners/rateLimit.js | 7 +++ src/listeners/warn.js | 6 +++ src/modules/commands/command.js | 7 +-- src/modules/tickets/index.js | 28 +++++++++-- src/modules/tickets/manager.js | 26 ---------- src/modules/tickets/ticket.js | 0 src/utils/discord.js | 9 ---- user/example.config.js | 2 + 15 files changed, 298 insertions(+), 135 deletions(-) create mode 100644 .github/CODE_OF_CONDUCT.md create mode 100644 src/listeners/messageDelete.js create mode 100644 src/listeners/rateLimit.js create mode 100644 src/listeners/warn.js delete mode 100644 src/modules/tickets/manager.js delete mode 100644 src/modules/tickets/ticket.js diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..aa49712 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at contact@eartharoid.me. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq \ No newline at end of file diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 75d82e1..7a9b5c3 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,23 +1,83 @@ # Contributing -## Submitting issues +Thank you for considering contributing to DiscordTickets. -### Submitting a bug report +Before contributing, please read the [code of conduct](CODE_OF_CONDUCT.md), which all contributors must follow. -To submit a bug report, please use the "Bug report" template when creating a [new issue](https://github.com/eartharoid/DiscordTickets/issues/new/choose). Describe the bug in as much detail as possible, including how to reproduce the problem, using screenshots or code snippets if possible. Check that someone else hasn't already created a similar first. +You don't need to write code to contribute; all contributions are welcome and encouraged. You could: -### Submitting a feature request +- [Contributing](#contributing) + - [Submitting a bug report](#submitting-a-bug-report) + - [Submitting a feature request](#submitting-a-feature-request) + - [Creating a pull request](#creating-a-pull-request) + - [Contributing code](#contributing-code) + - [Translating](#translating) + - [Updating documentation](#updating-documentation) + - [Website](#website) + - [JSDoc](#jsdoc) -~~To submit a new feature request, please use the "Feature request" template when creating a [new issue](https://github.com/eartharoid/DiscordTickets/issues/new/choose).~~ +If you want to contribute but don't know how, and this file doesn't answer your questions, [start a discussion](https://github.com/eartharoid/DiscordTickets/discussions/new) or [join the Discord support & community server](https://go.eartharoid.me/discord) to ask for guidance. -You can request new features on [Feedbacky](https://app.feedbacky.net/b/dsctickets/). +**Issues are for:** -### Submitting other issues +- Bug reports +- Requesting changes to existing features -For issues not related to feature requests or bugs, you can [create a blank issue](https://github.com/eartharoid/DiscordTickets/issues/new). Please give us as much information as possible. If you just want to talk (if you need help or have questions), you can join the [Discord server](https://go.eartharoid.me/discord) or use the [Discussions tab](https://github.com/eartharoid/DiscordTickets/discussions). +Please label your issues appropriately. -## Submitting a pull request +**Discussions are for:** -To contribute code to this project, create a new [pull request](https://github.com/eartharoid/DiscordTickets/pulls). For anything other than patches (bug fixes, documentation or minor code changes that have no affect on usage), such as a new feature, please create a [new issue](https://github.com/eartharoid/DiscordTickets/issues/new/choose) first, describing what you intend to change and why. Please ensure you update the documentation if needed. +- Support (also on [Discord](https://go.eartharoid.me/discord)) +- General questions (also on [Discord](https://go.eartharoid.me/discord)) +- Requesting new features -When contributing, you should follow the same code style already used throughout, to ensure code is consistent. +Please read ["Welcome to DiscordTickets Discussions!"](https://github.com/eartharoid/DiscordTickets/discussions/77) before starting a discussion! + +## Submitting a bug report + +Issues should be used to report bugs. If you have found a bug, check to see if it has already been reported or resolved. If it hasn't, you can [create a new issue](https://github.com/eartharoid/DiscordTickets/issues/new/choose) using the "Bug report" template. Please include as much information as possible in your report. + +## Submitting a feature request + +To request a new feature, [start a new discussion](https://github.com/eartharoid/DiscordTickets/discussions/new?category=Ideas) under the Ideas category so other members of the community can discuss the request and vote on it. + +If you would like to request changes to an existing feature, it may be better to [create an issue](https://github.com/eartharoid/DiscordTickets/issues/new) instead (use the `enhancement` label). + +## Creating a pull request + +To edit the documentation, translate, or contribute code to this project, you will need to [create a new pull request](https://github.com/eartharoid/DiscordTickets/compare). For large changes, you should **consider creating an issue** (or commenting on an existing one) first, as it could save you some time. + +### Contributing code + +Any code changes should be accompanied by any necessary documentation changes. + +You should install the ESLint extension in your editor help you follow the code style. + +- Use single quotes +- Functions should be named in camelCase +- Variables and constants should be named in snake_case + +### Translating + +Please try to keep the meaning of the translation as close to the original as possible. + +1. Copy [`en-GB.json`](https://github.com/eartharoid/DiscordTickets/blob/master/src/locales/en-GB.json) and name it correctly +2. Without modifying the keys (left side of the colon), translate the values (on the right side of the colon). +3. [Create a pull request](#creating-a-pull-request) + +### Updating documentation + +#### Website + +The documentation is written in Markdown, with extensions for additional features. See the [Material for MkDocs Reference](https://squidfunk.github.io/mkdocs-material/reference/abbreviations/) for details. + +Please install a Markdown linting extension in your editor. + +If you would like to see a live preview of your changes you can install MkDocs locally after cloning the repository (requires python). + +1. Install with `pip install -r requirements.txt` +2. Run `mkdocs serve` + +#### JSDoc + +Feel free to improve or add JSDoc comments in the JavaScript files. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 11aa112..9e58b30 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,29 +1,30 @@ -#### Information +**Versioning information** - [ ] This includes major changes (breaking changes) - [ ] This includes minor changes (minimal usage changes, minor new features) - [ ] This includes patches (bug or typo fixes) -- [ ] This is includes **only** documentation changes +- [ ] This includes **only** documentation changes -#### Is this related to an issue? +**Is this related to an issue?** -#### Changes made +**Changes made** -#### Confirmations +**Confirmations** - [ ] I have updated any necessary documentation -- [ ] This uses consistent code style -- [ ] This is tested and works +- [ ] My changes use consistent code style +- [ ] My changes are tested and work diff --git a/src/database/index.js b/src/database/index.js index d88181d..c7eaa12 100644 --- a/src/database/index.js +++ b/src/database/index.js @@ -125,6 +125,14 @@ module.exports = async (log) => { type: DataTypes.CHAR(18), allowNull: false, }, + edited: { + type: DataTypes.BOOLEAN, + defaultValue: false, + }, + deleted: { + type: DataTypes.BOOLEAN, + defaultValue: false, + }, updates: { type: DataTypes.JSON }, @@ -132,72 +140,6 @@ module.exports = async (log) => { tableName: DB_TABLE_PREFIX + 'messages' }); - // eslint-disable-next-line no-unused-vars - const Channel = sequelize.define('Channel', { - id: { - type: DataTypes.CHAR(18), - primaryKey: true, - allowNull: false, - }, - name: { - type: DataTypes.STRING, - allowNull: false, - }, - }, { - tableName: DB_TABLE_PREFIX + 'channel_entities' - }); - - // eslint-disable-next-line no-unused-vars - const Role = sequelize.define('Role', { - id: { - type: DataTypes.CHAR(18), - primaryKey: true, - allowNull: false, - }, - name: { - type: DataTypes.STRING, - allowNull: false, - }, - colour: { - type: DataTypes.INTEGER, - defaultValue: 7506394 - }, - }, { - tableName: DB_TABLE_PREFIX + 'role_entities' - }); - - // eslint-disable-next-line no-unused-vars - const Member = sequelize.define('Member', { - id: { - type: DataTypes.CHAR(18), - primaryKey: true, - allowNull: false, - }, - username: { - type: DataTypes.STRING, - allowNull: false, - }, - discriminator: { - type: DataTypes.STRING, - allowNull: false, - }, - nickname: { - type: DataTypes.STRING, - allowNull: false, - }, - avatar: { - type: DataTypes.STRING, - }, - colour: { - type: DataTypes.INTEGER, - }, - bot: { - type: DataTypes.BOOLEAN, - }, - }, { - tableName: DB_TABLE_PREFIX + 'member_entities' - }); - sequelize.sync(); return sequelize; diff --git a/src/listeners/message.js b/src/listeners/message.js index 4a19548..ec6c2d6 100644 --- a/src/listeners/message.js +++ b/src/listeners/message.js @@ -2,18 +2,30 @@ module.exports = { event: 'message', execute: async (client, message) => { - let settings = await message.guild.settings; + let settings = await message.guild?.settings; - if (settings.log_messages) { - if (message.type !== 'DEFAULT') return; + if (settings?.log_messages) { + if (message.system) return; - let ticket = await client.tickets.get(message.channel.id); + let ticket = await client.db.models.Ticket.findOne({ + where: { + id: message.channel.id + } + }); if (ticket) { - client.db.models.Message.create({ + await client.db.models.Message.create({ id: message.id, ticket: ticket.id, - author: message.author.id + author: message.author.id, + updates: [{ + content: message.content, + time: message.createdTimestamp, + embeds: message.embeds.map(embed => { + return { ...message.embeds[embed] }; + }), + attachments: [ ...message.attachments.values() ] + }] }); } } diff --git a/src/listeners/messageDelete.js b/src/listeners/messageDelete.js new file mode 100644 index 0000000..f4d467e --- /dev/null +++ b/src/listeners/messageDelete.js @@ -0,0 +1,29 @@ +module.exports = { + event: 'messageDelete', + execute: async (client, message) => { + + if (message.partial) + try { + await message.fetch(); + } catch (err) { + return client.log.error(err); + } + + let settings = await message.guild?.settings; + + if (settings?.log_messages) { + if (message.system) return; + + let msg = await client.db.models.Message.findOne({ + where: { + id: message.channel.id + } + }); + + if (msg) { + msg.deleted = true; + await msg.save(); // save changes to message row + } + } + } +}; \ No newline at end of file diff --git a/src/listeners/messageUpdate.js b/src/listeners/messageUpdate.js index d66512d..d934a37 100644 --- a/src/listeners/messageUpdate.js +++ b/src/listeners/messageUpdate.js @@ -1,5 +1,45 @@ module.exports = { - event: 'messageUpdate', - execute: (client, m1, m2) => { + event: 'msgUpdate', + execute: async (client, oldm, newm) => { + + if (newm.partial) + try { + await newm.fetch(); + } catch (err) { + return client.log.error(err); + } + + let settings = await newm.guild?.settings; + + if (settings?.messages) { + if (newm.system) return; + + let msg = await client.db.models.msg.findOne({ + where: { + id: newm.channel.id + } + }); + + if (msg) { + let embeds = msg.embeds.map(embed => { + return { ...msg.embeds[embed] }; + }); + + if (msg.editedTimestamp) { // message has been edited + msg.updates.unshift({ + content: msg.content, + time: msg.editedTimestamp, + embeds, + attachments: [ ...msg.attachments.values() ] + }); + msg.edited = true; + } + else { // probably just a link embed loading + msg.updates[0] = Object.assign(msg.updates[0], embeds); + } + + await msg.save(); // save changes to msg row + } + } } }; \ No newline at end of file diff --git a/src/listeners/rateLimit.js b/src/listeners/rateLimit.js new file mode 100644 index 0000000..f030e1f --- /dev/null +++ b/src/listeners/rateLimit.js @@ -0,0 +1,7 @@ +module.exports = { + event: 'rateLimit', + execute: (client, limit) => { + client.log.warn('Rate-limited!'); + client.log.debug(limit); + } +}; \ No newline at end of file diff --git a/src/listeners/warn.js b/src/listeners/warn.js new file mode 100644 index 0000000..fe1cc6a --- /dev/null +++ b/src/listeners/warn.js @@ -0,0 +1,6 @@ +module.exports = { + event: 'warn', + execute: (client, warning) => { + client.log.warn(warning); + } +}; \ No newline at end of file diff --git a/src/modules/commands/command.js b/src/modules/commands/command.js index 94416c1..7d9564c 100644 --- a/src/modules/commands/command.js +++ b/src/modules/commands/command.js @@ -174,8 +174,9 @@ module.exports = class Command { * @param {boolean} secret - Ephemeral message? **NOTE: EMBEDS AND ATTACHMENTS DO NOT RENDER IF TRUE** */ async sendResponse(interaction, content, secret) { + const send = this.client.api.interactions(interaction.id, interaction.token).messages['@original'].patch; if (typeof content === 'object') - this.client.api.interactions(interaction.id, interaction.token).callback.post({ + send({ data: { type: 4, data: { @@ -184,8 +185,8 @@ module.exports = class Command { } } }); - else - this.client.api.interactions(interaction.id, interaction.token).callback.post({ + else if (typeof content === 'string') + send({ data: { type: 4, data: { diff --git a/src/modules/tickets/index.js b/src/modules/tickets/index.js index 2a2ca20..9946a15 100644 --- a/src/modules/tickets/index.js +++ b/src/modules/tickets/index.js @@ -1,4 +1,26 @@ -module.exports = { - TicketManager: require('./manager'), - Ticket: require('./ticket'), +const EventEmitter = require('events'); +// eslint-disable-next-line no-unused-vars +const { Client } = require('discord.js'); + +/** Manages tickets */ +module.exports = class extends EventEmitter { + /** + * Create a TicketManager instance + * @param {Client} client + */ + constructor(client) { + super(); + + /** The Discord Client */ + this.client = client; + + this.setMaxListeners(this.client.config.max_listeners); + } + + /** + * Create a new ticket + */ + async create() { + + } }; \ No newline at end of file diff --git a/src/modules/tickets/manager.js b/src/modules/tickets/manager.js deleted file mode 100644 index 17bf2a0..0000000 --- a/src/modules/tickets/manager.js +++ /dev/null @@ -1,26 +0,0 @@ -const EventEmitter = require('events'); -// eslint-disable-next-line no-unused-vars -const { Client } = require('discord.js'); - -/** Manages tickets */ -module.exports = class extends EventEmitter { - /** - * Create a TicketManager instance - * @param {Client} client - */ - constructor(client) { - super(); - - /** The Discord Client */ - this.client = client; - - this.setMaxListeners(this.client.config.max_listeners); - } - - /** - * Create a new ticket - */ - async create() { - - } -}; \ No newline at end of file diff --git a/src/modules/tickets/ticket.js b/src/modules/tickets/ticket.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/utils/discord.js b/src/utils/discord.js index 6615540..f5bb8ac 100644 --- a/src/utils/discord.js +++ b/src/utils/discord.js @@ -25,15 +25,6 @@ module.exports = { */ flags: (secret) => secret ? 1 << 64 : undefined, - /** - * Set message entities - * @param {Discord.Message} message - The message to set entities for - */ - - messageEntities(message) { - const { client } = message; - }, - /** * Select a presence from the config * @returns {Discord.PresenceData} diff --git a/user/example.config.js b/user/example.config.js index bdc6ce8..22d29ba 100644 --- a/user/example.config.js +++ b/user/example.config.js @@ -28,6 +28,8 @@ module.exports = { colour: '#009999', locale: 'en-GB', log_messages: true, // required for transcripts/archives + prefix: '-', + ticket_welcome: 'Hello {{name}}, thank you for creating a ticket. A member of staff will soon be available to assist you.\n\n__All messages in this channel are stored for future reference.__', }, logs: { enabled: true,