Example #1
0
            public async Task ListCmdOverwrites([ParameterName("command")][Required] string strId)
            {
                try
                {
                    await Interaction.AcknowledgeAsync(flags : InteractionResponseFlags.Ephemeral);

                    var cmd = await getCommand(strId);

                    if (cmd == null)
                    {
                        await Interaction.FollowupAsync(":x: Command does not exist.");

                        return;
                    }
                    GuildApplicationCommandPermissions cmdPerms = null;
                    if (cmd is RestGlobalCommand g)
                    {
                        cmdPerms = await g.GetCommandPermissions(Interaction.Guild.Id);
                    }
                    else if (cmd is RestGuildCommand u)
                    {
                        cmdPerms = await u.GetCommandPermissions();
                    }
                    if (cmdPerms == null || cmdPerms.Permissions == null || cmdPerms.Permissions.Count == 0)
                    {
                        await Interaction.FollowupAsync("Default: " + emote(cmd.DefaultPermission) + "\r\n" +
                                                        "Command has no specific permissions set");

                        return;
                    }
                    var embed = new EmbedBuilder();
                    embed.Title = $"{cmd.Name} Permissions";
                    var sb = new StringBuilder();
                    sb.Append("Default: " + emote(cmd.DefaultPermission) + "\r\n");
                    foreach (var thing in cmdPerms.Permissions)
                    {
                        if (thing.Type == PermissionTarget.User)
                        {
                            sb.Append($"User <@!{thing.Id}>");
                        }
                        else
                        {
                            sb.Append($"Role <@&{thing.Id}>");
                        }
                        sb.Append(" " + emote(thing.Value));
                        sb.Append("\r\n");
                    }
                    embed.Description = sb.ToString();
                    await Interaction.FollowupAsync(embed : embed.Build(),
                                                    allowedMentions : AllowedMentions.None);
                }
                catch (Exception ex)
                {
                    Program.LogMsg(ex, "ListSlash");
                }
            }
Example #2
0
            async Task manageThing(string strId, ulong thingId, PermissionTarget thingType, bool?value)
            {
                await Interaction.AcknowledgeAsync(flags : InteractionResponseFlags.Ephemeral);

                try
                {
                    RestApplicationCommand command = await getCommand(strId);

                    if (command == null)
                    {
                        await Interaction.FollowupAsync(":x: Command does not exist");

                        return;
                    }

                    GuildApplicationCommandPermissions existingPerms = null;
                    if (command is RestGlobalCommand g)
                    {
                        existingPerms = await g.GetCommandPermissions(Interaction.Guild.Id);
                    }
                    else if (command is RestGuildCommand u)
                    {
                        existingPerms = await u.GetCommandPermissions();
                    }
                    var permBuilder   = SlashCommandPermsBuilder.From(existingPerms);
                    var existingValue = permBuilder.Get(thingId);
                    if (value.HasValue)
                    {
                        if (existingValue != value.Value)
                        {
                            permBuilder.With(thingId, thingType, value.Value);
                            await command.ModifyCommandPermissionsAsync(Interaction.Guild.Id, permBuilder.Build().ToArray());
                        }
                        await Interaction.FollowupAsync("Done!");
                    }
                    else
                    {
                        if (!existingValue.HasValue)
                        {
                            await Interaction.FollowupAsync($"{thingType} has no explicit permission set.");
                        }
                        else
                        {
                            await Interaction.FollowupAsync($"{thingType} permission for command: " + emote(existingValue.Value));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Program.LogMsg(ex, "a");
                }
            }