Files
PixelDocs/assets/mobot_creating-a-module_modules-introduction.md.BWpvzdqx.lean.js
T
2025-04-21 14:23:15 +00:00

36 lines
18 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{_ as i,c as a,a0 as e,o as t}from"./chunks/framework.p2VkXzrt.js";const c=JSON.parse('{"title":"🧩 Creating a Module","description":"","frontmatter":{"banner_title":"MoBot - Creating a Module","banner_description":"Learn how to create a module for MoBot","head":[["meta",{"name":"twitter:image","content":"/assets/banner-cards/mobot-creating-a-module-modules-introduction.png"}],["meta",{"name":"twitter:image:src","content":"https://docs.pixel-services.com/assets/banner-cards/mobot-creating-a-module-modules-introduction.png"}],["meta",{"name":"twitter:card","content":"summary_large_image"}],["meta",{"name":"twitter:image:height","content":"1280"}],["meta",{"name":"twitter:image:width","content":"669"}],["meta",{"name":"twitter:description","content":""}]]},"headers":[],"relativePath":"mobot/creating-a-module/modules-introduction.md","filePath":"mobot/creating-a-module/modules-introduction.md"}'),n={name:"mobot/creating-a-module/modules-introduction.md"};function l(o,s,h,p,r,d){return t(),a("div",null,s[0]||(s[0]=[e(`<h1 id="🧩-creating-a-module" tabindex="-1">🧩 Creating a Module <a class="header-anchor" href="#🧩-creating-a-module" aria-label="Permalink to &quot;🧩 Creating a Module&quot;"></a></h1><p>MoBot is designed to be modular, allowing you to create your own modules to extend its functionality. This guide will walk you through the process of creating a module for MoBot.</p><h2 id="🧠-prerequisites" tabindex="-1">🧠 Prerequisites <a class="header-anchor" href="#🧠-prerequisites" aria-label="Permalink to &quot;🧠 Prerequisites&quot;"></a></h2><p>Before we begin, make sure youre comfortable with:</p><ul><li>Basic <strong>Java</strong> programming</li><li>Using <strong>Maven</strong> (or any preferred Java build tool)</li><li>Understanding the basics of how MoBot operates</li></ul><p>If you&#39;re new to Java or Maven, we recommend checking out a few beginner tutorials first.</p><p>Also, make sure you&#39;ve reviewed the <a href="/mobot/introduction/installation.html">MoBot Installation Guide</a> to understand how the bot is structured and how modules fit into it.</p><h2 id="🧩-what-makes-a-module" tabindex="-1">🧩 What Makes a Module? <a class="header-anchor" href="#🧩-what-makes-a-module" aria-label="Permalink to &quot;🧩 What Makes a Module?&quot;"></a></h2><p>For a module to be recognized and loaded by MoBot, it needs <strong>two essential parts</strong>:</p><ol><li>A <strong>Main class</strong> that extends <code>MbModule</code></li><li>A <strong><code>module.yml</code></strong> configuration file that defines metadata about the module</li></ol><p>Additionally, youll need to include the <strong>MoBot API</strong> as a dependency in your project.</p><h2 id="🛠-step-1-set-up-your-maven-project" tabindex="-1">🛠 Step 1: Set Up Your Maven Project <a class="header-anchor" href="#🛠-step-1-set-up-your-maven-project" aria-label="Permalink to &quot;🛠 Step 1: Set Up Your Maven Project&quot;"></a></h2><p>To create a module, you need to set up a Maven project. You can do this using your favorite IDE or by using the command line. If you&#39;re using the command line, you can create a new Maven project with the following command:</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mvn</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> archetype:generate</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -DgroupId=com.example</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -DartifactId=MyModule</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -DarchetypeArtifactId=maven-archetype-quickstart</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -DinteractiveMode=false</span></span></code></pre></div><p>This will create a new Maven project looking something like this:</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">MyModule/</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">├──</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pom.xml</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">└──</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> src/</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> └──</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> main/</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> └──</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> java/</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> └──</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> com/</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> └──</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> example/</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> └──</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> MyModule/</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> └──</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> App.java</span></span></code></pre></div><h3 id="add-mobot-api-dependency" tabindex="-1">Add MoBot API Dependency <a class="header-anchor" href="#add-mobot-api-dependency" aria-label="Permalink to &quot;Add MoBot API Dependency&quot;"></a></h3><p>To use the MoBot API in your module, you need to add it as a dependency in your <code>pom.xml</code> file. Open the <code>pom.xml</code> file and add the following lines inside the <code>&lt;repositories&gt;</code> and <code>&lt;dependencies&gt;</code> sections:</p><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">repository</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">id</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;pixel-services-releases&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">id</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;Pixel Services&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">url</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;https://maven.pixel-services.com/releases&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">url</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">repository</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">dependency</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">groupId</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;com.pixelservices.mobot&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">groupId</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">artifactId</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;mobot-api&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">artifactId</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &lt;</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">version</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;VERSION&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">version</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt; </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">&lt;!-- Replace VERSION --&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;/</span><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">dependency</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;</span></span></code></pre></div><p>Make sure to replace <code>VERSION</code> with the latest version of the MoBot API.</p><p><a href="https://maven.pixel-services.com/#/releases/com/pixelservices/mobot/mobot-api" target="_blank" rel="noreferrer"><img src="https://img.shields.io/maven-metadata/v?metadataUrl=https://maven.pixel-services.com/releases/com/pixelservices/mobot/mobot-api/maven-metadata.xml" alt="Latest Version"></a></p><h2 id="🧱-step-2-create-your-main-class" tabindex="-1">🧱 Step 2: Create Your Main Class <a class="header-anchor" href="#🧱-step-2-create-your-main-class" aria-label="Permalink to &quot;🧱 Step 2: Create Your Main Class&quot;"></a></h2><p>Either locate your existing main class or create a new one. This class will be the entry point for your module and should extend <code>MbModule</code>.</p><div class="language-java vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">java</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">public</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> MyModule</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> extends</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> MbModule</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> @</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">Override</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> public</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> void</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> onEnable</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //Do something</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> @</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">Override</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> public</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> void</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> onDisable</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //Do something</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><h2 id="📜-step-3-create-the-module-yml-file" tabindex="-1">📜 Step 3: Create the <code>module.yml</code> File <a class="header-anchor" href="#📜-step-3-create-the-module-yml-file" aria-label="Permalink to &quot;📜 Step 3: Create the \`module.yml\` File&quot;"></a></h2><p>The <code>module.yml</code> file contains metadata about your module, such as its name, version, and description. Create a new file named <code>module.yml</code> in the <code>src/main/resources</code> directory of your project.</p><div class="language-yaml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">yaml</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">MyModule</span></span>
<span class="line"><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">version</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1.0.0</span></span>
<span class="line"><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">description</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">This is a sample module for MoBot.</span></span>
<span class="line"><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">com.example.MyModule</span></span>
<span class="line"><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">authors</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: [</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">Your Name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]</span></span>
<span class="line"><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">license</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">MIT</span></span>
<span class="line"><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">depedencies</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: []</span></span></code></pre></div><h3 id="explanation-of-the-fields" tabindex="-1">Explanation of the Fields <a class="header-anchor" href="#explanation-of-the-fields" aria-label="Permalink to &quot;Explanation of the Fields&quot;"></a></h3><ul><li><strong>name</strong>: The name of your module.</li><li><strong>version</strong>: The version of your module.</li><li><strong>description</strong>: A brief description of your module.</li><li><strong>main</strong>: The fully qualified name of your main class.</li><li><strong>authors</strong>: A list of authors for your module.</li><li><strong>license</strong>: The license under which your module is distributed.</li><li><strong>dependencies</strong>: A list of other modules that your module depends on. This is optional and can be left empty if your module has no dependencies.</li></ul><h2 id="🚀-step-4-build-your-module" tabindex="-1">🚀 Step 4: Build Your Module <a class="header-anchor" href="#🚀-step-4-build-your-module" aria-label="Permalink to &quot;🚀 Step 4: Build Your Module&quot;"></a></h2><p>Once you have created your main class and <code>module.yml</code> file, you can build your module using Maven. Open a terminal in the root directory of your project and run the following command:</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">mvn</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clean</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> package</span></span></code></pre></div><p>This will create a JAR file for your module in the <code>target</code> directory. The JAR file will be named <code>MyModule-1.0.0.jar</code> (or whatever version you specified in the <code>module.yml</code> file).</p><p>Congratulations! You have successfully created a module for MoBot. Now you can load it into your MoBot instance and start using it.</p><h2 id="🔌-step-5-load-your-module-into-mobot" tabindex="-1">🔌 Step 5: Load Your Module into MoBot <a class="header-anchor" href="#🔌-step-5-load-your-module-into-mobot" aria-label="Permalink to &quot;🔌 Step 5: Load Your Module into MoBot&quot;"></a></h2><p>To load your module into MoBot, simply place the JAR file you just created into the <code>modules</code> directory of your MoBot instance. When you start MoBot, it will automatically detect and load your module.</p><p>Need help? Join our <a href="https://discord.gg/KTF3Wsk85G" target="_blank" rel="noreferrer">Discord server</a> for support and to connect with other MoBot users.</p>`,37)]))}const u=i(n,[["render",l]]);export{c as __pageData,u as default};