Skip to content

Commit

Permalink
docs(Bot): Add summaries to API
Browse files Browse the repository at this point in the history
  • Loading branch information
JayXTQ committed Nov 25, 2024
1 parent b4fec55 commit 917e822
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 8 deletions.
9 changes: 9 additions & 0 deletions DiscordLab.Bot/API/Features/UpdateStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
{
public class UpdateStatus
{
/// <summary>
/// The name of the module/plugin.
/// </summary>
public string ModuleName { get; set; }
/// <summary>
/// The version of the module/plugin.
/// </summary>
public Version Version { get; set; }
/// <summary>
/// The download url of this version of the module/plugin.
/// </summary>
public string Url { get; set; }
}
}
8 changes: 8 additions & 0 deletions DiscordLab.Bot/API/Interfaces/IRegisterable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
{
public interface IRegisterable
{
/// <summary>
/// Here is where you put your code that you want to run at the same time as OnEnabled in your plugin root.
/// Useful things would be stuff like binding your static Instance variable.
/// </summary>
public void Init();

/// <summary>
/// Here is what you want to run when the plugin is just above to disable.
/// </summary>
public void Unregister();
}
}
4 changes: 2 additions & 2 deletions DiscordLab.Bot/API/Interfaces/ISlashCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public interface ISlashCommand
SlashCommandBuilder Data { get; }

/// <summary>
/// Here is where your slash command runs
/// Here is where your slash command runs.
/// </summary>
/// <remarks>
/// This type contains information about the command that was executed
/// This type contains information about the command that was executed.
/// </remarks>
Task Run(SocketSlashCommand command);
}
Expand Down
15 changes: 14 additions & 1 deletion DiscordLab.Bot/API/Modules/HandlerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ public class HandlerLoader
{
private readonly List<IRegisterable> _inits = new();

/// <summary>
/// Once you run this, it will grab all the <see cref="IRegisterable"/> classes from your plugin's <see cref="Assembly"/> and run their <see cref="IRegisterable.Init"/> method.
/// It also grabs your <see cref="ISlashCommand"/> classes and registers them. You will need to do no command handling on your side. DiscordLab does it all.
/// </summary>
/// <param name="assembly">
/// Your plugin's <see cref="Assembly"/>.
/// </param>
/// <remarks>
/// If you use this function, you are required to call <see cref="Unload"/> when your plugin is about to be disabled. No need to pass in any params though.
/// </remarks>
public void Load(Assembly assembly)
{
Type registerType = typeof(IRegisterable);
Expand All @@ -22,7 +32,10 @@ public void Load(Assembly assembly)

SlashCommandLoader.LoadCommands(assembly);
}


/// <summary>
/// Unloads all IRegisterable classes that were loaded.
/// </summary>
public void Unload()
{
foreach (IRegisterable init in _inits)
Expand Down
14 changes: 13 additions & 1 deletion DiscordLab.Bot/API/Modules/QueueSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ namespace DiscordLab.Bot.API.Modules
public static class QueueSystem
{
private static List<string> _openQueueIds = new();


/// <summary>
/// Will run code after 5 seconds, but will only run once per id.
/// This is different from <see cref="Timing.CallDelayed(float, System.Action)"/> because it will only run once
/// 5 seconds after the initial call.
/// </summary>
/// <param name="id">
/// A unique identifier for this queue. Like DiscordLab.BotStatus.PlayerVerified
/// </param>
/// <param name="action">
/// The bit of code you want to run after 5 seconds, this shouldn't have any hard coded variables unless they
/// will never change within the 5 seconds.
/// </param>
public static void QueueRun(string id, Action action)
{
if (_openQueueIds.Contains(id)) return;
Expand Down
14 changes: 13 additions & 1 deletion DiscordLab.Bot/API/Modules/SlashCommandLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ namespace DiscordLab.Bot.API.Modules
public static class SlashCommandLoader
{
public static List<ISlashCommand> Commands = new();


/// <summary>
/// Adds all commands in a <see cref="Assembly"/> from the <see cref="ISlashCommand"/> classes to a list.
/// </summary>
/// <param name="assembly">
/// Your plugin's <see cref="Assembly"/>.
/// </param>
public static void LoadCommands(Assembly assembly)
{
Type registerType = typeof(ISlashCommand);
Expand All @@ -22,6 +28,12 @@ public static void LoadCommands(Assembly assembly)
}
}

/// <summary>
/// This clears all commands from the list.
/// </summary>
/// <remarks>
/// This should only be used by the main bot, you should have no reason to run this.
/// </remarks>
public static void ClearCommands()
{
Commands = new();
Expand Down
8 changes: 7 additions & 1 deletion DiscordLab.Bot/API/Modules/UpdateStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ public class GitHubReleaseAsset
public class UpdateStatus
{
private static readonly HttpClient client = new ();


/// <summary>
/// This will check the GitHub API for the latest version of the modules and plugins.
/// </summary>
/// <remarks>
/// Should only be run once via the main bot, otherwise you'll just be doing unnecessary requests.
/// </remarks>
public static async Task GetStatus()
{
client.DefaultRequestHeaders.UserAgent.ParseAdd("request");
Expand Down
20 changes: 18 additions & 2 deletions DiscordLab.Bot/API/Modules/WriteableConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ public static class WriteableConfig
{
private static string Path =
System.IO.Path.Combine(System.IO.Path.Combine(Paths.Configs, "DiscordLab"), "config.json");


/// <summary>
/// This will get the config.json file from the DiscordLab folder in the Exiled configs.
/// </summary>
/// <returns>
/// The config.json file as a <see cref="JObject"/>.
/// </returns>
public static JObject GetConfig()
{
if (!File.Exists(Path))
Expand All @@ -19,7 +25,17 @@ public static JObject GetConfig()

return JObject.Parse(File.ReadAllText(Path));
}


/// <summary>
/// This will write a new option to the config.json file.
/// It can also overwrite options.
/// </summary>
/// <param name="key">
/// The key of the option you want to write.
/// </param>
/// <param name="value">
/// The value of the option you want to write. Should be JSON serializable.
/// </param>
public static void WriteConfigOption(string key, JToken value)
{
JObject config = GetConfig();
Expand Down

0 comments on commit 917e822

Please sign in to comment.