https://github.com/mara-li/knitting-bot
A little discord bot write in TypeScript that automatically add / remove member in thread, without pinging them!
https://github.com/mara-li/knitting-bot
bot discord management thread threadmanagement typescript
Last synced: 11 months ago
JSON representation
A little discord bot write in TypeScript that automatically add / remove member in thread, without pinging them!
- Host: GitHub
- URL: https://github.com/mara-li/knitting-bot
- Owner: Mara-Li
- License: gpl-3.0
- Created: 2023-04-29T17:42:43.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-11-25T23:19:54.000Z (over 1 year ago)
- Last Synced: 2024-12-06T08:07:32.721Z (over 1 year ago)
- Topics: bot, discord, management, thread, threadmanagement, typescript
- Language: TypeScript
- Homepage:
- Size: 920 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Knitting
→ [Traduction française](README_FR.md)
[Invitation links](https://discord.com/api/oauth2/authorize?client_id=1101559076086886500&permissions=292057785360&scope=bot)
> [!WARNING]
> When invited the bot is in `manual mode`, to prevents errors when the bot is added to a server.
> You need to activate the automatic events with the `/config auto` command.
If you want to try out the bot, you can join [this discord server](https://discord.gg/TWjfz2yTSA)!
A bot that helps you to add user to a thread, to keep the thread always visible for everyone, and without pinging them!
> [!NOTE]
> The user added to the thread needs to have the permission to see it.
The bot will automatically add a user to a thread when:
- A user joins the server and has the permission to see the thread
- A user is updated and gets a new role
- When a channel or category that have their permission edited
- When a thread is created
The bot won't do anything when joining the server. If you want to update all threads, you can use the slash command `/update-all-threads` (see below).
## Slash Commands
### Configuration
The slash command `/config` allows you to configure the bot. It will open a window with buttons to change the configuration.
#### `/config language`
Displays the current language and allows you to change it.
#### `/config mode`
Displays the current modes and allows you to change them. You can:
- Only follow a specific channel (_Note: Here, "channel" includes categories, forums, threads, and channels).
- Only follow a specific role.
- Use the "[@role] for [@channel]" mode, which cannot be used with other modes.
#### `/config auto`
Displays the current automatic events and allows you to change them. You can enable or disable the following automatic events:
- Thread creation.
- Channel, category, forum, or thread permission updates.
- User role updates.
- User joining the server.
You can also enable the "manual" mode, which disables all automatic events.
#### `/config help`
Displays general information about bot configuration, as well as a link to the README.
> [!NOTE]
> The button will be red if activate it will disable the event, and green if it will enable it.
### Follow
Allow to only "ping" specific channels or roles.
You need to activate the `follow-only` mode to use these commands. You can do that with the `/config` command.
- `/follow channel (channel)` : Add a channel to the list of followed channels[^1]. If the channel is not specified, it will use the current channel.
- `/follow role [role]` : Add a role to the list of followed roles
- `/follow specific [role] [channel]` : Add a role to the list of followed roles in a specific channel[^1].
- You can repeat the command with the same role to add multiple channels.
- To remove a channel, you need to redo the command with the same channel and role.
- To remove a role completely, you need to do the command without the channel.
- `/follow list` : List all followed channels and roles
> [!NOTE]
> To unfollow a channel/role, you need to redo the command with the same channel/role.
### Ignore
The exact opposite of the follow command. It won't ping the channels or roles ignored.
- `/ignore channel (channel)` : Add a channel to the list of ignored channels[^1]. If the channel is not specified, it will use the current channel.
- `/ignore role [role]` : Add a role to the list of ignored roles
- `/ignore specific [role] [channel]` : Add a role to the list of ignored roles in a specific channel[^1].
- You can repeat the command with the same role to add multiple channels.
- To remove a channel, you need to redo the command with the same channel and role.
- To remove a role completely, you need to do the command without the channel.
- `/ignore list` : List all ignored channels and roles
> [!NOTE]
> To un-ignore a channel, you need to redo the command with the same channel. Same for the role.
> [!WARNING]
> You can't follow and ignore "role" or "channel" at the same time.
> For example:
>
> - If the `only-channel` mode is activated, you can't ignore a channel.
> - If the `only-role` mode is activated, you can't ignore a role.
> Factually, the `follow` commands will ignore all un-specified channels/roles.
### Update
If you want to manually update a thread, you can use the slash commands:
- `/update thread (thread)` : Update a specific thread. If the thread is not specified, it will update the current thread.
- `/update all` : Update all threads in the server
- `/update help` : Get help about the manual slash commands
These commands don't appear for user that haven't the `manage thread` permission.
> [!WARNING]
> It will re-add all users that leave the thread, even if they left it on purpose.
> [!NOTE]
> There is no way that I can code something that don't add any notification on the thread.
> You **always** will have the thread that becomes white when the bot activates.
More over, you can configure the bot and disable event that you don't want to use. You can do that with the `/config` command. You can see the configuration with `/config show`
### Info
A simple embed with some information about the bot and the main developer.
## How it's work
For some optimization purpose, the bot will first @role when a thread must be updated. After it will check if some users (that don't have role/allowed role) can see the thread and add them.
Moreover, if there is no role in the server, the bot process on the members list instead.
Note that role will be mentioned if some users that have the role aren't in the thread.
After making the list of user/role to ping, there is two possibility:
- If a older message of the bot exists, it will edit it with the new list of user/role to ping.
- If not, it will send a empty message (with `_ _`) and edit it with the new list of user/role to ping.
After sending/editing the message, the bot will edit the message again to `_ _`.
> [!WARNING]
> The message send won't be deleted, because I discover that if a ping with editing an old message doesn't make a notification.
> So the bot will keep this message to edit it when the thread need to be updated.
> With that, user already in the thread won't get a white notification on the thread.
### Permission asked
The bot needs some intents to work:
- Presence
- Server members
(For some reason, the bot needs the presence intents to get the user id when they join the server)
---
# 🤖 Development
The bot is made with [discord.js](https://discord.js.org/#/). You need to have [node.js (LTS)](https://nodejs.org/en/) installed on your computer.
After cloning the repo, you need to install the dependencies with:
```bash
npm run init
```
The script will ask your for your `.env` variable, and the file will be created automatically.
It can look like this:
```dotenv
BOT_TOKEN=your_token
CLIENT_ID=your_client_id
NODE_ENV=development# or production
MESSAGE= #Anything you want
GITHUB_EMOJI="1125070935855222845" #Emoji ID
KOFI="1125071623658164274" #Emoji ID
DISCORD="1125072006937849876" #Emoji ID
```
> [!NOTE]
> If you want try your bot, you need to create an application in the [discord developer portal](https://discord.com/developers/applications).
> [Here a tutorial](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token)
> Don't forget to invite your bot in a testing discord server!
- `BOT_TOKEN` is the token of the bot that you can get in `Bot` > `Reset token` in the discord developer portal.
- `CLIENT_ID` is the client id of the bot, you can get it from `General Information` > `Client ID` in the discord developer portal.
- `NODE_ENV` is the environment of the bot. It can be `development` or `production`. If you are in development, the bot will log a lot of event. If you are in production, the bot will log only errors.
- `MESSAGE` : The message you want to send when waiting for the list of users/roles. You can use a simple message, an emoji, stickers or external emoji. Beware of them. The bot must be on the server where the emoji is (but it can use it everywhere).
The bot uses Enmap to store data. You can find the documentation [here](https://enmap.evie.dev/). You need a special installation for it, so follow the instructions [here](https://enmap.evie.dev/install).
## 🎼 Translation
The bot is translated in:
- [x] French
- [x] English
I use i18next to translate the bot. You can find the documentation [here](https://www.i18next.com/).
If you want to add a translation, you need to:
- Duplicate `src/i18next/locales/en.json` and rename it with the language code (ex: `fr.json`)
- Translate the file
- Update the `src/i18next/index.ts` and add the language in the `ressources` object, without forgetting to import it (ex: `import * as fr from "./locales/fr.json";`)
- You need to update **all** commands (`src/commands`) file, and update:
- Adding `const lang = i18next.getFixedT("lang");` at the top of the file
- Adding `setNameLocalizations({lang: lang("same key of other langue")})`
- Adding the language directly in `setDescriptionLocalizations`.
You can get more information about [commands localization on the official discordJS documentation](https://discordjs.guide/slash-commands/advanced-creation.html#localizations)
The slash commands language is directly based on your discord client language.
---
# Thread Watcher
A cool bot to use with this bot is [Thread Watcher](https://threadwatcher.xyz/)!
[^1]: Channel includes here thread, channel, forum and category.