Skip to content

Latest commit

 

History

History
230 lines (146 loc) · 7.06 KB

README.md

File metadata and controls

230 lines (146 loc) · 7.06 KB

discord_message_cleaner

English | 日本語

A Discord bot that periodically deletes messages in designated channels.

Features

  • Set target channels for deletion
  • Remove channels from deletion targets
  • Set exclusions
  • Remove exclusions
  • View settings within the server
  • Delete all messages in a channel

Feature Details

Set Target Channels for Deletion

Set the channels to be monitored. To prevent accidental deletions, a confirmation message is displayed after executing the command. Press the Ok button within 10 seconds to complete the setting. If the same channel is set again, the setting will be overwritten. Note that messages with exclusion settings will not be deleted.

/enable [#target_channel] [lifetime]

Parameter ① Target Channel for Deletion

Enter the target channel in the form of a channel mention (#channel_name). This is a required parameter.

Parameter ② Lifetime

Specify how long the messages should remain. Enter the lifetime as a string as shown below.

Input Abbreviation Duration

| 1week | 1w| 1 week | | 1day | 1d | 1 day (24 hours) | | 1hour | 1h | 1 hour | | 1min | 1mi | 1 minute | | 1sec | 1s | 1 second |

You can also specify multiple combinations.

Input Duration
"1week 2day 3hour 4min 5sec" 9 days 3 hours 4 minutes 5 seconds
"1 day 1 hour 30 min" 1 day 1 hour 30 minutes
"90mi" 1 hour 30 minutes
"1h90mi" 2 hour 30 minutes

This is an optional parameter. If omitted, "1day" will be set by default.

Remove Target Channels for Deletion

Remove channels from the monitoring targets.

/disable {#target_channel}

Parameter ① Target Channel for Removal

Enter the target channel in the form of a channel mention (#channel_name). This is a required parameter.

Set Message Exclusions

Exclude messages from deletion by specifying the message URL or message ID.

/exclude add [msgurl]

Parameter ① Message URL

Specify the message URL. This is a required parameter.

Remove Message Exclusions

Remove the set exclusion settings. To prevent accidental deletions, a confirmation message is displayed after executing the command. Press the Ok button within 10 seconds to complete the setting.

/exclude remove [msgurl]

Parameter ① Message URL

Specify the message URL. This is a required parameter.

View Settings Within the Server

Display the current settings in the server.

/setttings [channel]

Parameter ① Channel to Display

This is an optional parameter. If omitted, all settings within the server will be displayed.

Delete All Messages in a Channel

Delete all messages in the specified channel. To prevent accidental deletions, a confirmation message is displayed after executing the command. Press the Ok button within 10 seconds to complete the setting.

/clear {#target_channel}

Parameter ① Target Channel for Deletion

Enter the target channel in the form of a channel mention (#channel_name). This is a required parameter.

Required Permissions for the Bot

The bot requires the following permissions.

Permission Name Description
Manage Messages Required to access and delete messages in the target channels
Read Message History Required to delete messages sent before the bot was added

Data Collection

The bot collects the following data for its operation.

Data Target Data Content
Server ID, Channel ID Used to identify the target server and channels
Message ID Used to set exclusions (the content of the messages or reactions are not read)

Permissions to Operate the Bot

For security reasons, only users with the role "message_cleaner_admin" are allowed to operate this function. The Bot does not automatically generate this role, so an administrator must create it and assign it only to trusted individuals. Even if the "message_cleaner_admin" role exists, deletion commands cannot be used unless the command executor has message management permissions. Therefore, it is recommended to grant message management permissions to that role.

Development Environment

Environment Setup

The basic settings are summarized in the devcontainer.

  1. Clone the source using git
  2. Prepare environment files in the config folder
    1. .env (copy .env.example)
    2. .env.db.production (copy .env.db.production and edit the DB connection information)
    3. .env.testing (copy .env.example)
  3. Open with VSCode and select "Reopen in Container"

Debug Execution

You can run the debugger directly from the "Run" tab as .vscode/launch.json is provided.

Test Execution

We use pytest and pytest-asyncio. These environments are automatically created during the devcontainer setup, so you can run tests from the "Test" tab.

Production Environment

Execution

We use docker-compose. Note: We plan to migrate to k8s in the future.

Start production environment

sh prod.up.sh

To clear cache and start

sh prod.up.nocache.sh

To stop

sh prod.down.sh

Libraries and Licenses

discord.py

python-dotenv

asyncpg

sqlalchemy

result

pytest

pytest-asyncio

pytest-mock