Skip to content

Commit

Permalink
[Feature] App Command Perms Channel Target (#2560)
Browse files Browse the repository at this point in the history
* Implement channel ApplicationCommandPermissionTarget

* implement channel target in ApplicationCommandPermission and add static methods for targeting @everyone and all channels
  • Loading branch information
Cenngo committed Feb 6, 2023
1 parent 1602437 commit 2616d35
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public enum ApplicationCommandPermissionTarget
/// <summary>
/// The target of the permission is a user.
/// </summary>
User = 2
User = 2,
/// <summary>
/// The target of the permission is a channel.
/// </summary>
Channel = 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,61 @@ public ApplicationCommandPermission(IRole target, bool allow)
Permission = allow;
TargetType = ApplicationCommandPermissionTarget.Role;
}

/// <summary>
/// Creates a new <see cref="ApplicationCommandPermission"/> targeting <see cref="ApplicationCommandPermissionTarget.Channel"/>.
/// </summary>
/// <param name="channel">The channel you want to target this permission value for.</param>
/// <param name="allow">The value of this permission.</param>
public ApplicationCommandPermission(IChannel channel, bool allow)
{
TargetId = channel.Id;
Permission = allow;
TargetType = ApplicationCommandPermissionTarget.Channel;
}

/// <summary>
/// Creates a new <see cref="ApplicationCommandPermission"/> targeting @everyone in a guild.
/// </summary>
/// <param name="guildId">Id of the target guild.</param>
/// <param name="allow">The value of this permission.</param>
/// <returns>
/// Instance of <see cref="ApplicationCommandPermission"/> targeting @everyone in a guild.
/// </returns>
public static ApplicationCommandPermission ForEveryone(ulong guildId, bool allow) =>
new(guildId, ApplicationCommandPermissionTarget.User, allow);

/// <summary>
/// Creates a new <see cref="ApplicationCommandPermission"/> targeting @everyone in a guild.
/// </summary>
/// <param name="guild">Target guild.</param>
/// <param name="allow">The value of this permission.</param>
/// <returns>
/// Instance of <see cref="ApplicationCommandPermission"/> targeting @everyone in a guild.
/// </returns>
public static ApplicationCommandPermission ForEveryone(IGuild guild, bool allow) =>
ForEveryone(guild.Id, allow);

/// <summary>
/// Creates a new <see cref="ApplicationCommandPermission"/> targeting every channel in a guild.
/// </summary>
/// <param name="guildId">Id of the target guild.</param>
/// <param name="allow">The value of this permission.</param>
/// <returns>
/// Instance of <see cref="ApplicationCommandPermission"/> targeting everychannel in a guild.
/// </returns>
public static ApplicationCommandPermission ForAllChannels(ulong guildId, bool allow) =>
new(guildId - 1, ApplicationCommandPermissionTarget.Channel, allow);

/// <summary>
/// Creates a new <see cref="ApplicationCommandPermission"/> targeting every channel in a guild.
/// </summary>
/// <param name="guild">Target guild.</param>
/// <param name="allow">The value of this permission.</param>
/// <returns>
/// Instance of <see cref="ApplicationCommandPermission"/> targeting everychannel in a guild.
/// </returns>
public static ApplicationCommandPermission ForAllChannels(IGuild guild, bool allow) =>
ForAllChannels(guild.Id, allow);
}
}

0 comments on commit 2616d35

Please sign in to comment.