-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ on: | |
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
timeout-minutes: 15 | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
|
47 changes: 47 additions & 0 deletions
47
...n.Discord.Commands/Attributes/ProvidedRequirements/SlashCommandRequireChannelAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Color_Chan.Discord.Commands.Contexts; | ||
using Color_Chan.Discord.Commands.Results; | ||
using Color_Chan.Discord.Core.Results; | ||
|
||
namespace Color_Chan.Discord.Commands.Attributes.ProvidedRequirements | ||
{ | ||
/// <summary> | ||
/// This attribute requires a command to be executed in a specific channel. | ||
/// </summary> | ||
/// <example> | ||
/// <code language="cs"> | ||
/// [SlashCommandRequireChannel(0123456789)] | ||
/// public class PongCommands : SlashCommandModule | ||
/// { | ||
/// [SlashCommand("ping", "Ping Pong!")] | ||
/// public Task<IDiscordInteractionResponse> PongAsync() | ||
/// { | ||
/// // Command code... | ||
/// } | ||
/// } | ||
/// </code> | ||
/// </example> | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)] | ||
public class SlashCommandRequireChannelAttribute : SlashCommandRequirementAttribute | ||
{ | ||
private readonly ulong _channelId; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="SlashCommandRequireChannelAttribute" />. | ||
/// </summary> | ||
/// <param name="channelId">The ID of the channel.</param> | ||
public SlashCommandRequireChannelAttribute(ulong channelId) | ||
{ | ||
_channelId = channelId; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override Task<Result> CheckRequirementAsync(ISlashCommandContext context, IServiceProvider services) | ||
{ | ||
return Task.FromResult(context.ChannelId != _channelId | ||
? Result.FromError(new SlashCommandRequirementErrorResult($"Channel with ID {_channelId.ToString()} is required to use this command.")) | ||
: Result.FromSuccess()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters