Assuming you have added all the action codes to analcategories:
if lastaction.scene.code in sceneref.analcategories && ((lastaction.takers.has(self) != lastaction.scene.code in ['cowgirlanal','revcowgirlanal']) || lastaction.scene.code == 'doubledildoass'):
Otherwise:
if (lastaction.scene.code in sceneref.analcategories && (lastaction.takers.has(self) || lastaction.scene.code == 'doubledildoass')) || (lastaction.givers.has(self) && lastaction.scene.code in ['cowgirlanal','revcowgirlanal']):