Exemple #1
0
            public async Task ClearOverwrite(
                [ParameterName("command")]
                [Required]
                string strId, [Required] string thingId)
            {
                await Interaction.AcknowledgeAsync(flags : InteractionResponseFlags.Ephemeral);

                if (!ulong.TryParse(thingId, out var id))
                {
                    await Interaction.FollowupAsync(":x: `thingId` must be a valid ulong of the user or role.");

                    return;
                }
                var cmd = await getCommand(strId);

                if (cmd == null)
                {
                    await Interaction.RespondAsync(":x: Command does not exist",
                                                   ephemeral : true);

                    return;
                }
                var existingPerms = await cmd.GetCommandPermissions(Interaction.Guild.Id);

                var permBuilder = SlashCommandPermsBuilder.From(existingPerms);

                permBuilder.Remove(id);
                await cmd.ModifyCommandPermissionsAsync(Interaction.Guild.Id, permBuilder.Build().ToArray());

                await Interaction.FollowupAsync("Done!");
            }
Exemple #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");
                }
            }