diff --git a/docs/medusa/creating-a-medusa.md b/docs/medusa/creating-a-medusa.md index b01a6e2bd..8402020bc 100644 --- a/docs/medusa/creating-a-medusa.md +++ b/docs/medusa/creating-a-medusa.md @@ -1,8 +1,55 @@ # Creating A Medusa -## Theory +## Getting started -### Introduction +This section will guide you through how to create a simple custom medusa. You can find the entirety of this code hosted [here](https://gitlab.com/nadeko/example_medusa) + +#### Prerequisite +- [.net8 sdk](https://dotnet.microsoft.com/en-us/download) installed +- Optional: use [vscode](https://code.visualstudio.com/download) to write code + +#### Guide + +- Open your favorite terminal and navigate to a folder where you will keep your project . + +- Create a new folder and move into it + - `mkdir example_medusa ` + - `cd example_medusa` + +- Install nadeko-medusa template + - `dotnet new install nadeko-medusa` + +- Make a new Nadeko Medusa project + - `dotnet new nadeko-medusa` + +### Build it + +- Build your Medusa into a dll that Nadeko can load. In your terminal, type: + - `dotnet publish -o bin/medusae/example_medusa /p:DebugType=embedded` + +- Done. You can now try it out in action. + +### Try it out + +- Copy the `bin/medusae/example_medusa` folder into your NadekoBot's `data/medusae/` folder. (Nadeko version 4.1.0+) + +- Load it with `.meload example_medusa` + +- In the channel your bot can see, run the following commands to try it out + - `.hello` and + - `.hello @` + +- Check its information with + - `.meinfo example_medusa` + +- Unload it + - `.meunload example_medusa` + +- :tada: Congrats! You've just made your first medusa! :tada: + + + +## Theory Medusa system allows you to write independent medusae (known as "modules", "cogs" or "plugins" in other software) which you can then load, unload and update at will without restarting the bot. @@ -99,9 +146,9 @@ If you don't want any auxiliary files, and you don't want to bother making new . If you update your response strings .yml file(s) while the medusa is loaded and running, running `.stringsreload` will reload the responses without the need to reload the medusa or restart the bot. -#### Config +#### Bot medusa config file -- Medusa config is kept in `medusae/medusa.yml` file +- Medusa config is kept in `data/medusae/medusa.yml` file in NadekoBot installation folder - At the moment this config only keeps track of which medusae are currently loaded (they will also be always loaded at startup) - If a medusa is causing issues and you're unable to unload it, you can remove it from the `loaded:` list in this config file and restart the bot. It won't be loaded next time the bot is started up @@ -115,138 +162,4 @@ To make sure your medusa can be properly unloaded/reloaded you must: - If you are still having issues, you can always run `.meunload` followed by a bot restart, or if you want to find what is causing the medusa unloadability issues, you can check the [microsoft's assembly unloadability debugging guide](https://docs.microsoft.com/en-us/dotnet/standard/assembly/unloadability) -## Practice -This section will guide you through how to create a simple custom medusa. You can find the entirety of this code hosted [here](https://gitlab.com/nadeko/example_medusa) - -#### Prerequisite -- [.net6 sdk](https://dotnet.microsoft.com/en-us/download) installed -- Optional: use [vscode](https://code.visualstudio.com/download) to write code - -#### Guide - - -- Open your favorite terminal and navigate to a folder where you will keep your project . - -- Create a new folder - - `mkdir example_medusa` -- Create a new .net class library - - `dotnet new classlib` -- Open the current folder with your favorite editor/IDE. In this case we'll use VsCode - - `code .` -- Remove the `Class1.cs` file -- Replace the contents of the `.csproj` file with the following contents -```xml - - - net6.0 - - - enable - - - preview - true - true - - - true - - - - - - - all - - - - - - - - - PreserveNewest - - - - -``` -- Create a `MySnek.cs` file and add the following contents -```cs -using NadekoBot.Medusa; -using Discord; - -public sealed class MySnek : Snek -{ - [cmd] - public async Task Hello(AnyContext ctx) - { - await ctx.Channel.SendMessageAsync($"Hello everyone!"); - } - - [cmd] - public async Task Hello(AnyContext ctx, IUser target) - { - await ctx.ConfirmLocalizedAsync("hello", target); - } -} -``` -- Create `res.yml` and `cmds.yml` files with the following contents - -`res.yml` -```yml -medusa.description: "This is my medusa's description" -hello: "Hello {0}, from res.yml!" -``` - -`cmds.yml` -```yml -hello: - desc: "This is a basic hello command" - args: - - "" - - "@Someone" -``` - -- Add `NuGet.Config` file which will let you use the base Nadeko.Medusa package. This file should always look like this and you shouldn't change it - -```xml - - - - - - -``` - -### Build it - -- Build your Medusa into a dll that Nadeko can load. In your terminal, type: - - `dotnet publish -o bin/medusae/example_medusa /p:DebugType=embedded` - -- Done. You can now try it out in action. - -### Try it out - -- Copy the `bin/medusae/example_medusa` folder into your NadekoBot's `data/medusae/` folder. (Nadeko version 4.1.0+) - -- Load it with `.meload example_medusa` - -- In the channel your bot can see, run the following commands to try it out - - `.hello` and - - `.hello @` - -- Check its information with - - `.meinfo example_medusa` - -- Unload it - - `.meunload example_medusa` - -- Congrats! You've just made your first medusa!