This is a guide on how to develop and contribute to this project
Make sure you can run these commands and install them if not present.
- Python 3.10
- pip3 (packaged as python3-pip)
- A Python IDE
- Anything will work, but people generally use Visual Studio Code or JetBrains PyCharm.
- .Net 7 SDK
- A C# IDE
- Preferably Visual Studio Community (Windows only) or JetBrains Rider (cross-platform, free with a student email)
- Go to https://discordapp.com/developers/applications (log in if needed)
- Create an application (name doesn't matter)
- Click "Bot" in the left sidebar
- Create a bot
- The bot's name will be what users see in servers
- Changing the bot's name changes the BotToken
- Make note of the token on this page (later referred to as BotToken)
- Enable Discord member intents
Click here to join the server ping @Jayy#6249 for permissions to add bots
- Click "OAuth2" in the left sidebar
- In the "scopes" section, check
bot
- In the "bot permissions" section, check the following boxes
- Copy the link from the "scopes" section and open in a new tab/window
- Select the test server to add the bot to
- Fork this repo
git clone
your fork to wherever you want to work on this bot
ClemBot.Api
uses dotnet user-secrets
(documentation)
to securely store sensitive values like database connection strings and API keys. After you have started up and
configured PostgreSQL with your desired username and password, you need to set the connection string for ClemBot.Api:
cd
intoClemBot/ClemBot.Api/ClemBot.Api.Core
- Run
dotnet user-secrets set "ClemBotConnectionString" "YourConnectionString"
- Example connection string:
Server=127.0.0.1;Port=5432;Database=clembotdb;User Id=XXXXX;Password=XXXXX;
- Example connection string:
- Generate a
BotApiKey
with this website. - Run
dotnet user-secrets set "BotApiKey" "KeyYouGeneratedAbove"
- Copy
BotSecrets.json.template
and rename that copy toBotSecrets.json
- Copy/paste the token from the Discord page into the
BotToken
empty string - Make the
ApiUrl
rowhttps://localhost:5001/
- Copy and paste the ClemBot.Api key value that you generated above into the
ApiKey
row - Copy and paste the channel IDs of the channels in the test server that you want to use for Connection Status updates
and Error Logging into the
ErrorLogChannelIds
andStartupLogChannelIds
. If you don't want this, leave the field as empty brackets, like so:[]
- Set a custom bot prefix in the
BotPrefix
field that will invoke your commands
Name | Type | Required | Project | Description |
---|---|---|---|---|
BotToken |
str |
Yes | Bot | Used to log into the bot account. |
ApiUrl |
str |
Yes | API | URL of the API endpoints (defaults to http://localhost:5001/ ) |
ApiKey |
str |
Yes | API | Access key for the bot endpoints in the API. |
ClientToken |
str |
No | Site | Used for the website. |
ClientSecret |
str |
No | Site | Used for the website. |
BotPrefix |
str |
Yes | Bot | The prefix your bot will respond to. |
SiteUrl |
str |
No | Bot | The URL of your local site or hosted instance for the bot to link to. |
StartupLogChannelIds |
list[int] |
No | Bot | The IDs of the channels for the bot to send start-up/shutdown events to. |
ErrorLogChannelIds |
list[int] |
No | Bot | The IDs of the channels for the bot to send error events to. |
ReplUrl |
str |
No | Bot | The URL of the Snekbox container. |
GitHubSourceUrl |
str |
No | Bot | The URL that the !source command uses to link to source. |
BotOnly |
bool |
No | Bot | If set to true , ClemBot.Bot operates without ClemBot.Api (with limited functionality). |
AllowBotInputIds |
list[int] |
No | Bot | The IDs of Discord bots that are allowed to run ClemBot commands. |
MessageApiBatchSize |
int |
No | API | The max cache size for ClemBot's internal message catch before it is flushed to the API (defaults to 5 ). |
Installing Poetry:
pip3 install poetry
(Windows: py -m pip install poetry
)
Tell Poetry to put the venv in the project folder
poetry config virtualenvs.in-project true
Installing dependencies with Poetry:
poetry install
You can then test-run the bot with the command...
poetry run python3 -m bot
(Windows: poetry run py -m bot
)
...when you are in the directory ClemBot/ClemBot.Bot
.
The bot should show up in the test server and respond to commands (test with <your_prefix>hello
)
- Open the
ClemBot.Api.sln
file in theClemBot/ClemBot.Api
folder to open the project in either Visual Studio or Rider - Click the run button in your preferred IDE
- Navigate to the ClemBot.Site folder in your shell
- Install Node.js 16 with nvm with the command
nvm install 16
thennvm use 16
- Install dependencies with yarn with the command
yarn install
- The dev server can then be run with the command
yarn run dev
ClemBot is composed of several separate components that all talk to each other over HTTP to form a complete system. Depending on what you are developing, you might not need all of them running simultaneously to develop what you want.
Here are some common scenarios and what portions of ClemBot you need to have running:
Developing a... | ClemBot.Bot | ClemBot.Api | ClemBot.Site |
---|---|---|---|
Discord command (no database) | Yes | No | No |
Discord command (with database) | Yes | Yes | No |
Website bug fix/feature (not dashboard) | No | No | Yes |
Dashboard bug fix/feature | Yes | Yes | Yes |
In instances where ClemBot.Bot is not using ClemBot.Api, the BotOnly
setting in the BotSecrets.json
file can
be toggled to true
and vice versa.