Skip to content

Commit

Permalink
Merge pull request #12 from Relism/master
Browse files Browse the repository at this point in the history
  • Loading branch information
sieadev authored Nov 23, 2024
2 parents 5388dbf + 67a87ea commit ce6ff71
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 103 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ build/
### Mac OS ###
.DS_Store
/.idea/
/modules/
188 changes: 85 additions & 103 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,124 +8,106 @@
</div>

## Overview
MoBot is a modular bot framework for Discord. It allows developers to create, extend, and manage custom modules that hook into the bot to add rich, interactive features.

MoBot is a modular, extensible bot framework designed for Discord.
With MoBot, developers can create and manage custom modules that hook into MoBot,
allowing for rich, interactive features to be added seamlessly.
Each module is loaded independently and can contain its own configuration, making it easy to extend and customize.
---

## Table of Contents
- [Roadmap](#roadmap)
- [Features](#features)
<details>
<summary><strong>📋 Table of Contents</strong></summary>

- [Setup Project](#setup-project)
- [Installation](#installation)
[Usage](#usage)
- [Getting Started](#getting-started)
- [Creating a Module](#creating-a-module)
- [Module Configuration](#module-configuration)
- [Loading and Managing Modules](#loading-and-managing-modules)
- [Module Development](#module-development)
- [Creating a Module](#creating-a-module)
- [Module Configuration](#module-configuration)
- [Loading and Managing Modules](#loading-and-managing-modules)
- [Creating a Module](#creating-a-module)
- [Module Configuration](#module-configuration)
- [Loading and Managing Modules](#loading-and-managing-modules)
- [License](#license)

## Roadmap
- [x] Modules
- [x] Load modules
- [x] Load module information from `module.yml`
- [x] Execute `preEnable`, `onEnable`, `onDisable` and `postDisable`
- [x] Account for priority when enabling
- [ ] Convenient Addons
- [x] Slash Command Addon
- [ ] ????
- [x] Module Configs

</details>

## Features
---

- **Modular Architecture:** Create and load custom modules easily.
- **Discord Integration:** Built-in support for Discord features like slash commands and event listeners.
-
- **Flexible Configuration:** Each module can have its own `config.yml`, stored in a structured directory.
- **Logging:** Centralized logging for each module, making it easy to debug and monitor activity.
- **Error Reporting:** Identify which module errors are coming from, with detailed logging.
## Setup Project

To create a module for MoBot, follow these steps:

## Module Development
1. **Create a Java Project** (Maven/Gradle):
- **Maven:**
Add the MoBot dependency in `pom.xml`:

### Creating a Module
```xml
<dependency>
<groupId>net.vitacraft</groupId>
<artifactId>MoBot</artifactId>
<version>VERSION</version> <!-- Replace VERSION -->
</dependency>
```

To create a module for MoBot, you need to extend the `MBModule` class. Below is an example of a simple module that logs a message when it is enabled and disabled.
- **Gradle:**
Add the dependency in `build.gradle`:

First, add the MoBot dependency to your `pom.xml`:
```gradle
dependencies {
implementation "net.vitacraft:MoBot:VERSION" // Replace VERSION
}
```

```xml
<repository>
<id>pixel-services-releases</id>
<name>Pixel Services</name>
<url>https://maven.pixel-services.com/releases</url>
</repository>
Find the latest version [here](https://maven.pixel-services.com/#/releases/net/vitacraft/MoBot).

<dependency>
<groupId>net.vitacraft</groupId>
<artifactId>MoBot</artifactId>
<version>VERSION</version> <!-- Replace VERSION with the latest version -->
</dependency>
```
2. **Create Main Module Class**: Extend the `MBModule` class:

Next, create a new class that extends `MBModule`. Here is an example:
```java
public class WelcomeModule extends MBModule {
@Override
public void onEnable() {
getLogger().info("WelcomeModule enabled!");
}

```java
public class WelcomeModule extends MBModule {
@Override
public void onEnable() {
// Log a message when the module is enabled
getLogger().info("WelcomeModule enabled!");
@Override
public void onDisable() {
getLogger().info("WelcomeModule disabled!");
}
}
```

@Override
public void onDisable() {
// Log a message when the module is disabled
getLogger().info("WelcomeModule disabled!");
}
}
```

Last but not least your bot needs a `bot.yml` file in your `resources` directory with information about the bot:

```yaml
name: WelcomeModule
version: '${project.version}'
description: A Test Module
dependencies: [ANOTHER_MODULE]
authors: [sieadev]
priority: DEFAULT
```
### Module Configuration
Each module can have its own configuration file. You can load the configuration using the `getConfigLoader` method. If no file name is passed, it defaults to `config.yml`. Here is an example:

```java
@Override
public void onEnable() {
// Load the default configuration (config.yml)
ConfigLoader config = getConfigLoader();
// Log a message when the module is enabled
getLogger().info("Hello World!");
}
```

### Loading and Managing Modules

Modules are loaded and managed by MoBot. You can use the `getModuleInfo` method to get information about the module, such as its name and version. Here is an example:

```java
@Override
public void onEnable() {
// Get module information
ModuleInfo info = getModuleInfo();
// Log the module name and version
getLogger().info("Hey from: module - " + info.getName() + " v" + info.getVersion());
}
```
3. **Create Service File**: Create `resources/META-INF/services/net.vitacraft.api.MBModule`, and to this file add **one line** to it: the fully qualified name of your main module class, for example:

```text
com.example.WelcomeModule
```

---

## Installation

1. **Install MoBot** by adding it as a dependency in your Maven or Gradle project (see the Setup Project section).

2. **Create `bot.yml`** file inside the `resources` folder to configure your bot:

```yaml
name: WelcomeModule
version: '1.0.0'
description: A Test Module
dependencies: []
authors: [Your Name]
priority: DEFAULT
```

---

## Creating a Module

1. **Extend `MBModule`**:
In your Java class, override `onEnable()` and `onDisable()`:

```java
public class WelcomeModule extends MBModule {
@Override
public void onEnable() {
getLogger().info("Module enabled!");
}

@Override
public void onDisable() {
getLogger().info("Module disabled!");
}
}

0 comments on commit ce6ff71

Please sign in to comment.