diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..cf5f3b8b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,18 @@ +# Contributing + +## Setting up the bot + +1. Fork the repository and clone it to your workstation. +2. Create a `.env` file and copy the contents of `.env.example` into it. +3. Go to your [Github Settings](https://github.com/settings/tokens) and create a personal access token with the scope "gist" +4. Copy the token and put it into the `.env` file as `GITHUB_TOKEN` +5. [Create a new Discord application](https://discord.com/developers/applications) +6. Switch to the "Bot" tab and click "Add Bot" +7. Toggle off the "Public Bot" switch and save. +8. Copy the token and put it into the `.env` file as `DISCORD_HASH`. +9. Go to the OAuth2 Tab and choose the "bot" scope. +10. Check the "Administrator" permission. +11. Copy the url out of the "Scopes" Panel and paste it into your browser. +12. (We recommend to create a new Discord Server before Step 12) +13. Select the server to add your bot. +14. run `npm install` and then `npm run dev` diff --git a/src/features/emojiMod.ts b/src/features/emojiMod.ts index 07a6a187..cc2586ba 100644 --- a/src/features/emojiMod.ts +++ b/src/features/emojiMod.ts @@ -1,6 +1,6 @@ import { MessageReaction, Message, GuildMember, TextChannel } from "discord.js"; import cooldown from "./cooldown"; -import { isStaff } from "../utils"; +import { isStaff, truncateMessage } from "../utils"; import { ChannelHandlers } from "../types"; const config = { @@ -30,7 +30,7 @@ type ReactionHandlers = { const reactionHandlers: ReactionHandlers = { "⚠️": (reaction, message, member) => { - // Skip if the user that reacted isn't in the staff of the post is from someone + // Skip if the user that reacted isn't in the staff or the post is from someone // from the staff if ( !message.guild || @@ -63,9 +63,10 @@ const reactionHandlers: ReactionHandlers = { .join(", "); let logMessage = ""; + const logMessageEnding = [ "\n\n", - `\`${message.content}\``, + `\`${truncateMessage(message.content)}\``, "\n\n", `Link: https://discord.com/channels/${message.guild?.id}/${message.channel.id}/${message.id}`, "\n\n", @@ -97,6 +98,19 @@ const reactionHandlers: ReactionHandlers = { }); } } + + const privateMessageToSender = `You've received a warning from the moderators on your message in ${ + message.channel + } + +Your message: +\`${truncateMessage(message.content)}\` + +Link: https://discord.com/channels/${message.guild?.id}/${message.channel.id}/${ + message.id + }`; + + message.author.send(privateMessageToSender); }, "👎": (reaction, message, member) => { if (!message.guild || cooldown.hasCooldown(member.id, "thumbsdown")) { @@ -132,7 +146,7 @@ const reactionHandlers: ReactionHandlers = { let logMessage = ""; const logMessageEnding = [ "\n\n", - `\`${message.content}\``, + `${truncateMessage(message.content)}`, "\n\n", `Link: https://discord.com/channels/${message.guild.id}/${message.channel.id}/${message.id}` ] diff --git a/src/utils.ts b/src/utils.ts index 8d7d9293..3f25c60e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -9,3 +9,15 @@ export const isStaff = (member: GuildMember | null | undefined) => { staffRoles.includes(role.name.toLowerCase()) ); }; + +// Discord's limit for message length +const maxMessageLength = 2000; + +export const truncateMessage = ( + message: string, + maxLength = maxMessageLength - 500 +) => { + if (message.length > maxLength) return `${message.slice(0, maxLength)}...`; + + return message; +};