refactor chat command handling