If this is for your own client, then you can't use the ON TEXT event.
The following should work, but as the networks that I'm currently on don't have +d for a deaf mode, I'm unable to test.
on *:input:*:{
if $istok(.+d .-d,$1,32) {
.mode $me $right($1,2)
}
}