Basically, I want to leave open the option for any of the following commands directed at my slackbot:
@torbot
@torbot [command]
@torbot [command] [arguments]
Below is what I've been using for now, but it looks ugly. From my experience, usually when something looks ugly, it means there's likely a more intuitive way to do the same thing.
class TorbotCommand(object):
def __init__(self, input):
self.__input = input
# TODO: There has to be a better way..
try:
self.__command_string = self.__input['text'].split(' ', 1)[1].strip().lower()
except:
self.__command_string = None
pass
try:
self.__command = self.__command_string.split(' ', 1)[0]
except:
self.__command = None
pass
try:
self.__text = self.__command_string.split(' ', 1)[1]
except:
self.__text = None
pass
def getCommand(self): return self.__command
def getText(self): return self.__text
def getInput(self): return self.__input