@JToivonen got what you mean and here is the "un modified" solution...simply if you're playing plug the usb controller and when you finish just unplug it and it will shutdown automatically!, even when a power trigger happens "electricity went off then come back again" and found that your gamepad isn't connected it will shut down :)
here is the python file you just need to edit the line that kills qjoypad to kill whole system add poweroff or shutdown -h as you use in your momentry switch
don't forget to make the file run at start and special thanks to pablo
idea behind the script is that system creates a js0 file for controller 1 inputs and js1 for controller 2 when connected and so on, the script searches for that file if it's found that mean you've connected the gamepad and probably playing a game and when you finish unplugging the gamepad removes js0 file and when the script discovers the file is not found it kills an app process called qjoypad which you'll change to shutdown
please note you're not gonna use //User Variables section in this code so just ignore it.