Skip to content

Commit 81b7c92

Browse files
committed
pr review 1 - adjusting sections and removing unnecessary parts
1 parent 3dce692 commit 81b7c92

File tree

1 file changed

+23
-139
lines changed

1 file changed

+23
-139
lines changed

.github/copilot-instructions.md

Lines changed: 23 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[//]: # (This file is not a README, it is for GitHub Copilot not for contributors.)
1+
[//]: # (This file is not a README, it is for [GitHub Copilot](https://docs.github.com/en/copilot/how-tos/configure-custom-instructions/add-repository-instructions) to help the AI tool to understand the project and provide better completions and code generations.)
22

33
# Copilot Instructions
44

@@ -7,15 +7,15 @@ This project is a [Discord](https://discord.com/) Bot developed in Java, utilizi
77

88
## Tech Stack
99

10-
The project uses a variety of technologies and libraries to achieve its functionality. Below is a comprehensive list of the main technologies used :
10+
The project uses a variety of technologies and libraries to achieve its functionality. Below is a comprehensive list of the main technologies used:
1111

1212
**Languages**
1313
- Java: the primary language for the project.
1414
- SQL: for database creation and management.
1515
- Groovy: for build-tool's configurations.
1616

1717
**Build & Dependency Management**
18-
- Gradle v8: the build tool used for managing dependencies and building the project.
18+
- Gradle: Be aware of the Gradle version in use, it is written in `/gradle/wrapper/gradle-wrapper.properties`.
1919
- Shadow plugin: for creating a fat JAR with all dependencies included.
2020
- Jib plugin: for building Docker images directly from Gradle.
2121

@@ -59,111 +59,33 @@ The project uses a variety of technologies and libraries to achieve its function
5959
- Jib (for container image building)
6060

6161
**Version Control & CI/CD**
62-
- Git v2
62+
- Git
6363
- GitHub Actions (for CI/CD, under `.github/workflows`)
6464
- Dependabot (for dependency updates, under `.github/dependabot.yml`)
6565
- Docker
6666

6767
**IDE/Editor Support**
68-
- IntelliJ IDEA
69-
- Eclipse
70-
- GitHub Codespaces
68+
69+
The project is designed to be compatible with various IDEs.
7170

7271
## Repository Structure
7372

74-
A **multi-module** Gradle project composed of 5 modules :
75-
```txt
76-
TJ-Bot
77-
├── application (Application module)
78-
├── buildSrc (Custom Gradle plugin)
79-
├── database
80-
├── formatter
81-
├── utils
82-
```
73+
A **multi-module** Gradle project composed of 5 modules:
74+
75+
1. **Application:** This is the main module. It contains the entry point, core logic, feature implementations, configuration management, and logging utilities for the bot.
76+
2. **BuildSrc:** Doesn't contain any Java files, it contains a build process to the SQLite database using Flyway and JOOQ. It contains exactly one [Groovy](https://groovy-lang.org/) file `database-settings.gradle`, which is a custom Gradle plugin that handles the database schema generation and migration.
77+
3. **Database:** about creating the connection to the SQLite database and providing a way to interact with it using JOOQ.
78+
4. **Formatter:** about formatting code snippets in any text messages, using [JDA](https://github.com/discord-jda/JDA?tab=readme-ov-file#jda-java-discord-api). It's built in a way that its robust and works even for code that doesn't compile, snippets and the like
79+
5. **Utils:** contains utility classes and methods that are used across the application. It includes exactly one class `MethodsReturnNonnullByDefault`: an annotation used in most packages as a validation mechanism to ensure that methods return non-null values by default, unless explicitly annotated otherwise.
8380

84-
The repository has other directories that are not modules :
81+
The repository has other directories that are not modules:
8582

86-
- `.devcontainer` and `.vscode` directories are only about giving support to coding on [GitHub's Codespaces](https://github.com/features/codespaces).
87-
The project is not intended necessarily to be run in a container or a specific IDE_.
83+
- `.devcontainer` and `.vscode` directories are about giving support to coding on [GitHub's Codespaces](https://github.com/features/codespaces). The `.vscode` can also be used to support developers on [VS Code](https://code.visualstudio.com/) IDE. A local setup does not require running the project from a container like Docker or the use of a specific IDE.
8884
- `.github` directory contains configuration files for GitHub Actions, Dependabot, and other GitHub features.
8985
- `.gradle` directory contains the Gradle wrapper files, allowing the project to be built with a specific version of Gradle without requiring users to install it manually, ignore it.
90-
- `meta` directory currently contains 3 [draw.io](https://www.drawio.com/) diagram files about the project, and a `google-style-eclipse.xml` file used in Spotless configuration.
91-
- `scripts` directory currently contains only one file which is a git pre-commit hook that runs Spotless to format the code before committing.
92-
93-
### Module 1: Application
94-
95-
This is the main module. It contains the entry point, core logic, feature implementations, configuration management, and logging utilities for the bot.
96-
97-
Most packages are equipped with a `package-info.java` file, which contains a brief description and 2 annotations
98-
- `@MethodsReturnNonnullByDefault`: defined in the `/utils` module, indicating that all methods in the package return non-null values by default.
99-
- `@ParametersAreNonnullByDefault`: from `javax.annotation` package, indicating that all parameters in the package are non-null by default.
100-
101-
NOTE: _We recommend to all contributors to only focus on this module. The other ones are handling some aspects behind the scenes, and are not meant to be modified by contributors._
102-
103-
#### 1. `config`:
104-
105-
Purpose: Handles all configuration aspects of the bot, including loading, validating, and providing access to configuration values.
106-
107-
Contents:
108-
- Classes for parsing and representing configuration files (e.g., `config.json.template`).
109-
- Utilities for environment variable overrides and runtime configuration changes.
110-
- Central access point for configuration values used throughout the application.
111-
112-
#### 2. `features`
113-
114-
Purpose: Implements the bot’s features, including commands, event listeners, and integrations.
115-
116-
Contents:
117-
- Command classes extending `SlashCommandAdapter` for Discord slash commands.
118-
- Event listeners for handling Discord events (e.g., user asked a question, question answered).
119-
- Feature registration and lifecycle management (e.g., Features.createFeatures).
120-
- Sub-packages for organizing features by domain (e.g., basic, chatgpt (openai), code, projects, and others).
121-
122-
#### 3. `logging`
123-
124-
Purpose: Provides logging configuration and utilities for the application.
125-
126-
Contents:
127-
- Log4j2 configuration files (e.g., `resources/log4j2.xml`).
128-
- Custom logging utilities and wrappers.
129-
- Integration with `SLF4J` for consistent logging across dependencies.
130-
131-
### Module 2: BuildSrc
132-
133-
This module doesn't contain any Java files, it contains a build process to the SQLite database using Flyway and JOOQ.
134-
135-
It contains exactly one groovy file database-settings.gradle, which is a custom Gradle plugin that handles the database schema generation and migration.
136-
137-
### Module 3: Database
138-
139-
This module is about creating the connection to the SQLite database and providing a way to interact with it using JOOQ.
140-
141-
### Module 4: Formatter
142-
143-
This module is about formatting code snippets in Discord messages, using the JDA library.
144-
145-
It's a sort of support for the `features.code` package in the `application` module.
146-
147-
> formatter... is a really complex project. it was created as its own module. probably also bc it was originally intended to be run outside the bots context - Zabuzard
148-
149-
### Module 5: Utils
150-
151-
This module contains utility classes and methods that are used across the application. It includes exactly one class `MethodsReturnNonnullByDefault` which is an annotation used in most packages in the `application` module.
152-
153-
## Complex Aspects
154-
155-
This section is about some important aspects in the `application` module. Some of these aspects are complex and may require additional attention when they get modified :
156-
157-
- `BotCore` a class/component defined under a subpackage `features.system`.
158-
- `ComponentIdStore` under a subpackage `features.componentids`.
159-
- `ComponentIdGenerator` under a subpackage `features.componentids`.
160-
- `ComponentIdInteractor` under a subpackage `features.componentids`.
161-
- `ComponentIdParser` under a subpackage `features.componentids`.
162-
- `Lifespan` under a subpackage `features.componentids`.
163-
- The corresponding database table and how it hooks into the actions, i.e. `UserInteractor#acceptComponmentIdGenerator` and the like.
164-
- the unit testing setup around discord mocking: the `JdaTester` class and the files next to it (.e.g the `jda.payloads` package)
165-
166-
NOTE: _These aspects are not meant to be modified by contributors, but they are important to understand how the bot works._
86+
- `meta` directory contains 3 [draw.io](https://www.drawio.com/) diagram files about the project, and a `google-style-eclipse.xml` file used in Spotless configuration.
87+
- `scripts` directory contains only one file which is a git pre-commit hook that runs Spotless to format the code before committing.
88+
- `wiki` directory contains the project's wiki pages, which are used to document the project and its features. The wiki is an important reference to understanding core logic and coding style.
16789

16890
## Coding Style
16991

@@ -174,49 +96,11 @@ Know that the organization uses [Sonar](https://sonarcloud.io/project/overview?i
17496
Try to use the [Together-Java Sonar's Quality Profile](https://sonarcloud.io/organizations/togetherjava/quality_profiles) when you write code or help with completions.
17597

17698
In addition, the following conventions should be followed:
177-
- Use meaningful variable and method names.
178-
- Use `@Override` annotation for overridden methods.
179-
- Use `final` for fields and classes whenever is better.
99+
- Use meaningful class, method and variable names.
100+
- Use `final` for fields and classes as default. Only make them non-final when modification and extension becomes necessary. In which case it is important to document its interface and intended use with Javadoc.
180101
- Enforce using `this` keyword to refer to the current instance of a class.
181-
- No magic numbers or strings; use constants instead.
182-
- No unnecessary comments; code should be self-explanatory.
102+
- It's generally preferred to use well named constants over magic values.
103+
- Prefer writing self-explanatory code, employ clean coding techniques.
104+
- Introduce helper method when necessary before using a comment instead.
183105
- Use Javadoc for public classes and methods.
184106
- No wildcard imports; import only the necessary classes.
185-
- Adhere to the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html).
186-
187-
## Commands
188-
1. Create a new class extending `SlashCommandAdapter`.
189-
2. If the command requires dependencies (e.g., `Database`), accept them in the constructor.
190-
3. Override methods such as `onSlashCommand`, `onButtonClick`, etc., as needed.
191-
4. Add the command to the list in `Features.createFeatures`, passing any required dependencies.
192-
193-
Example:
194-
```java
195-
public class FooCommand extends SlashCommandAdapter {
196-
197-
private static final String COMMAND_NAME = "foo";
198-
199-
private final Database database;
200-
private final Config config;
201-
202-
public FooCommand(Database database, Config config) {
203-
super(COMMAND_NAME, "Foo command using database and config", CommandVisibility.GUILD);
204-
this.database = database;
205-
this.config = config;
206-
}
207-
208-
@Override
209-
public void onSlashCommand(SlashCommandInteractionEvent event) {
210-
event.reply("Foo !").queue();
211-
}
212-
}
213-
```
214-
215-
Commands are registered as features in `org.togetherjava.tjbot.features.Features.createFeatures.java`:
216-
```java
217-
public static Collection<Feature> createFeatures(JDA jda, Database database, Config config) {
218-
// ... some features
219-
220-
features.add(new FooCommand(database, config));
221-
}
222-
```

0 commit comments

Comments
 (0)