Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slash Command Permissions #67

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Instagram Reels Bot/Instagram Reels Bot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Discord.Net.Interactions" Version="3.9.0" />
<PackageReference Include="Otp.NET" Version="1.3.0" />
<PackageReference Include="Bman46InstagramApiSharpLabs" Version="1.7.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
19 changes: 8 additions & 11 deletions Instagram Reels Bot/Modules/SlashCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public SlashCommands(CommandHandler handler, Subscriptions subs, IConfiguration
}

[SlashCommand("link","Processes an Instagram link.", runMode: RunMode.Async)]
public async Task Link(string url, [Summary(description: "The post number for the desired post in a carousel.")][MinValue(1)] int index = 1, [Summary(description: "Set to true to mark the image/video and caption as a spoiler.")] bool HasSpoilers = false)
public async Task Link(string url, [Summary(description: "The post number for the desired post in a carousel.")][MinValue(1)] int index = 1, [Summary(description: "Set to true to mark the image/video and caption as a spoiler.")] bool HasSpoilers = false)
{
// Check whitelist:
if (!Whitelist.IsServerOnList(((Context.Guild == null) ? (0) : (Context.Guild.Id))))
Expand Down Expand Up @@ -231,10 +231,9 @@ public async Task Github()
[SlashCommand("subscribe", "Get updates when a user posts a new post on Instagram.", runMode: RunMode.Async)]
[RequireBotPermission(ChannelPermission.SendMessages)]
[RequireBotPermission(ChannelPermission.AttachFiles)]
[RequireUserPermission(GuildPermission.Administrator, Group = "UserPerm")]
[RequireRole("InstagramBotSubscribe", Group = "UserPerm")]
[RequireContext(ContextType.Guild)]
public async Task Subscribe([Summary("username", "The username of the Instagram user.")]string username)
[DefaultMemberPermissions(GuildPermission.Administrator)]
[RequireContext(ContextType.Guild)]
public async Task Subscribe([Summary("username", "The username of the Instagram user.")]string username)
{
// Check whitelist:
if (!Whitelist.IsServerOnList(((Context.Guild == null) ? (0) : (Context.Guild.Id))))
Expand Down Expand Up @@ -304,9 +303,8 @@ public async Task Subscribe([Summary("username", "The username of the Instagram
await FollowupAsync("Success! You will receive new posts to this channel. They will not be instant and accounts are checked on a time interval.");
}
[SlashCommand("unsubscribe", "Unsubscribe to updates from selectable Instagram accounts.", runMode: RunMode.Async)]
[RequireUserPermission(GuildPermission.Administrator, Group = "UserPerm")]
[RequireRole("InstagramBotSubscribe", Group = "UserPerm")]
[RequireContext(ContextType.Guild)]
[DefaultMemberPermissions(GuildPermission.Administrator)]
[RequireContext(ContextType.Guild)]
public async Task Unsubscribe()
{
//Ensure subscriptions are enabled:
Expand Down Expand Up @@ -383,9 +381,8 @@ public async Task Unsubscribe()
await FollowupAsync(embed: embed.Build(), components: builder.Build());
}
[SlashCommand("unsubscribeall", "Unsubscribe from all Instagram accounts.", runMode: RunMode.Async)]
[RequireUserPermission(GuildPermission.Administrator, Group = "UserPerm")]
[RequireRole("InstagramBotSubscribe", Group = "UserPerm")]
[RequireContext(ContextType.Guild)]
[DefaultMemberPermissions(GuildPermission.Administrator)]
[RequireContext(ContextType.Guild)]
public async Task UnsubscribeAll()
{
//Ensure subscriptions are enabled:
Expand Down
3 changes: 3 additions & 0 deletions docs/subscribe.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ Please sign up for a [MongoDB Atlas](https://www.mongodb.com/atlas/database) acc
7. Paste the connection string into the `MongoDBUrl` parameter in the `config.json` file.
8. Set `AllowSubscriptions` to `true` in the config.json file.
9. Start the bot and test the commands!

## Step 3: Configure Permissions
By default, the bot allows anyone with `Administrator` permission to manage subscribed accounts on a Discord server. You can override this in the Discord settings by setting permissions on the slash commands. Please see the linked [support article](https://support.discord.com/hc/en-us/articles/4644915651095-Command-Permissions) for instructions.