Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Commit

Permalink
Add support for plugin client intent specification
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Mar 11, 2022
1 parent 1aa88b0 commit ed45179
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
26 changes: 26 additions & 0 deletions BrackeysBot.API/Plugins/PluginIntentsAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using DisCatSharp;

namespace BrackeysBot.API.Plugins;

/// <summary>
/// Specifies the Discord client intents that this plugin will utilise.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public sealed class PluginIntentsAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="PluginIntentsAttribute" /> class.
/// </summary>
/// <param name="intents">The intents.</param>
public PluginIntentsAttribute(DiscordIntents intents)
{
Intents = intents;
}

/// <summary>
/// Gets the intents.
/// </summary>
/// <value>The intents.</value>
public DiscordIntents Intents { get; }
}
11 changes: 9 additions & 2 deletions BrackeysBot/Plugins/SimplePluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,17 @@ public Plugin LoadPlugin(string name)
}
else
{
var intents = DiscordIntents.AllUnprivileged;
var intentsAttribute = type.GetCustomAttribute<PluginIntentsAttribute>();

if (intentsAttribute is not null)
intents = intentsAttribute.Intents;

plugin.DiscordClient ??= new DiscordClient(new DiscordConfiguration
{
Token = token,
LoggerFactory = new NLogLoggerFactory()
Intents = intents,
LoggerFactory = new NLogLoggerFactory(),
Token = token
});
}

Expand Down

0 comments on commit ed45179

Please sign in to comment.