Discord.Addons.SimplePermissions 1.2.0-alpha2

This is a prerelease version of Discord.Addons.SimplePermissions.
dotnet add package Discord.Addons.SimplePermissions --version 1.2.0-alpha2
NuGet\Install-Package Discord.Addons.SimplePermissions -Version 1.2.0-alpha2
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="Discord.Addons.SimplePermissions" Version="1.2.0-alpha2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Discord.Addons.SimplePermissions --version 1.2.0-alpha2
#r "nuget: Discord.Addons.SimplePermissions, 1.2.0-alpha2"
#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 Discord.Addons.SimplePermissions as a Cake Addin
#addin nuget:?package=Discord.Addons.SimplePermissions&version=1.2.0-alpha2&prerelease

// Install Discord.Addons.SimplePermissions as a Cake Tool
#tool nuget:?package=Discord.Addons.SimplePermissions&version=1.2.0-alpha2&prerelease

Discord.Addons.SimplePermissions

Discord.Net module for command permission management.

Quickstart

You need a config store provider for this. I have basic implementations for both JSON, and databases via EF Core available.

First you need a config object; you can use a base implementation if using a pre-made provider.

//example for the JSON provider
public class MyBotConfig : JsonConfigBase
{
    // You could add some more properties here that don't exist in the base class
    // for example:
    public string Token { get; set; }
}

Next, create an instance of your config store as your bot starts up and call the UseSimplePermissions() extension method.

// At the top in your Program class:
private readonly IConfigStore<MyBotConfig> _configstore = new JsonConfigStore<MyBotConfig>("config.json");

// When configuring all your services:
.AddSingleton(new PermissionsService(_configstore, _commands, _client, Logger))
// 'Logger' is an optional delegate that can point to your logging method

// When setting up your commands:
await _commands.AddModuleAsync<PermissionsModule>(_services);

Now you can also use the _configstore for other parts of your configuration. Note, since the config is also an IDisposable, wrap all the access to the config object in a using statement:

using (var config = configstore.Load())
{
    // Actually a pretty bad idea, but it demonstrates well
    await client.LoginAsync(TokenType.Bot, config.Token);
}

Permissions

For optimal management, you should mark every command you make with the Permission attribute to specify who can use which commands. For example:

// When using method commands:
[Permission(MinimumPermission.ModRole)]
public async Task MyCmd()
{
    //.....
}

// When using Command builders:
//....
.AddPrecondition(new PermissionAttribute(MinimumPermission.ModRole))
//....

There are six permission levels provided:

Everyone = 0,
ModRole = 1,
AdminRole = 2,
GuildOwner = 3,
Special,
BotOwner

The first four levels are in a hierarchy; these can execute commands of their own level or of lower value. Special and BotOwner are not part of the permission hierarchy, these must match exactly in order to pass.

Once your bot has joined a new Guild (server), the owner of that Guild has to set which roles are considered Mods and Admins respectively. The roles command can be used to list all roles and their ID, then setmod <id> and setadmin <id> to do it.

Once the roles are set, Mods and above can whitelist/blacklist specific Modules either per Channel or per Guild. The modules command will list the names of all Modules registered in the CommandService, then use wl <module name> to whitelist a Module in that Channel, or wl <module name> g to use it in all channels.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Discord.Addons.SimplePermissions:

Package Downloads
Discord.Addons.SimplePermissions.EFProvider

EF provider for Discord.Addons.SimplePermissions

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0-alpha2 876 5/9/2018