Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Contributing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 this is super awesome to have, thanks for adding it.


## 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`
22 changes: 18 additions & 4 deletions src/features/emojiMod.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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}`
]
Expand Down
12 changes: 12 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};