Rabergsel.DSharpPlus.SettingsManager 1.2.0

dotnet add package Rabergsel.DSharpPlus.SettingsManager --version 1.2.0                
NuGet\Install-Package Rabergsel.DSharpPlus.SettingsManager -Version 1.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rabergsel.DSharpPlus.SettingsManager" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rabergsel.DSharpPlus.SettingsManager --version 1.2.0                
#r "nuget: Rabergsel.DSharpPlus.SettingsManager, 1.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Rabergsel.DSharpPlus.SettingsManager as a Cake Addin
#addin nuget:?package=Rabergsel.DSharpPlus.SettingsManager&version=1.2.0

// Install Rabergsel.DSharpPlus.SettingsManager as a Cake Tool
#tool nuget:?package=Rabergsel.DSharpPlus.SettingsManager&version=1.2.0                

Rabergsel.DSharpPlus.SettingsManager

Rabergsel.DSharpPlus.SettingsManager is an extension for DSharpPlus that provides an easy infrastructure for managing settings for Discord Servers and Channels.

Installation

This package is under heavy development and not yet available on NuGet. However, you can clone the repository and build the project locally.

Usage

With DSharpPlus 5.0 (nightly), the process of building a discord client has changed. This has been patched with SettingsManager v1.2.0, so if you are using an older version of DSharpPlus, please use an older version of this package.

This example is a minimum example that makes use of all important features of the library.

using DSharpPlus;
using DSharpPlus.SettingsManager;
using Microsoft.Extensions.Logging;

namespace MyFirstBot
{
    internal class Program
    {
        private static async Task Main(string[] args)
        {
            //Create Discord Builder
            DiscordClientBuilder builder = DiscordClientBuilder.CreateDefault(File.ReadAllText("token.txt"), DiscordIntents.All);

            SettingsManager? settings = new SettingsManager();
            settings.Register(ref builder);   //!!! ALWAYS CALL BEFORE REGISTERING

            //The following section registers an event that will respond "pong" to "ping" as often
            //as set in the "pings" setting.
            builder.ConfigureEventHandlers
                (
                    b => b.HandleMessageCreated(async (s, e) =>
                    {
                        if (e.Message.Content.ToLower().StartsWith("ping"))
                        {
                            for (int i = 0; i < settings.GetSettingValueAsLong(e.Guild.Id, "pings"); i++)
                            {
                                await e.Message.RespondAsync("pong " + i);
                            }
                        }
                    })
                );

            var discord = builder.Build();

            //Add Extension
            discord.AddExtension(settings);

            settings.AddDefaultGuildSetting(new SettingEntity<object>("pings", 1)
            {
                AllowedValues = new List<object>() { 0, 1, 3, 5 }    //Only allow the values of 0, 1, 3 and 5
            });

            await discord.ConnectAsync();
            await Task.Delay(-1);
        }
    }
}

Note

This package is under heavy development and may undergo frequent changes. It's recommended to keep an eye on updates and consult the documentation for any breaking changes.

TODO

  • User settings
  • Complete generic User Settings
  • More customization
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 71 7/16/2024
1.1.0 150 4/12/2024
1.0.2 123 3/31/2024
1.0.1 127 3/30/2024
1.0.0 129 3/30/2024