Discord.Addons.SimplePermissions 1.2.0-alpha2

Discord.Net module for command permission management.

This is a prerelease version of Discord.Addons.SimplePermissions.
Install-Package Discord.Addons.SimplePermissions -Version 1.2.0-alpha2
dotnet add package Discord.Addons.SimplePermissions --version 1.2.0-alpha2
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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 &lt;id&gt; and setadmin &lt;id&gt; 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 &lt;module name&gt;
to whitelist a Module in that Channel, or wl &lt;module name&gt; g to use it in all channels.

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 &lt;id&gt; and setadmin &lt;id&gt; 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 &lt;module name&gt;
to whitelist a Module in that Channel, or wl &lt;module name&gt; g to use it in all channels.

This package is not used by any popular GitHub repositories.

Version History

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