diff --git a/sirbot/slack/dispatcher/command.py b/sirbot/slack/dispatcher/command.py index c996fd4..5bb9dc0 100644 --- a/sirbot/slack/dispatcher/command.py +++ b/sirbot/slack/dispatcher/command.py @@ -40,12 +40,12 @@ async def _incoming(self, request): logger.debug('Command handler received: %s', data['command']) slack = registry.get('slack') - settings = self._endpoints.get(data['command']) + func = self._endpoints.get(data['command']) - if not settings: + if not func: raise SlackUnknownCommand(data['command']) - command = await SlackCommand.from_raw(data, slack, settings=settings) + command = await SlackCommand.from_raw(data, slack) if isinstance(self._save, list) and data['command'] in self._save \ or self._save is True: @@ -56,19 +56,11 @@ async def _incoming(self, request): db, command) await db.commit() - coroutine = settings['func'](command, slack) + coroutine = func(command, slack) ensure_future(coroutine=coroutine, loop=self._loop, logger=logger) - - # if settings.get('public'): - # return Response( - # status=200, - # body=json.dumps({"response_type": "in_channel"}), - # content_type='application/json' - # ) - # else: return Response(status=200) - def register(self, command, func, public=False): + def register(self, command, func): logger.debug('Registering slash command: %s, %s from %s', command, func.__name__, @@ -77,5 +69,4 @@ def register(self, command, func, public=False): if not asyncio.iscoroutinefunction(func): func = asyncio.coroutine(func) - settings = {'func': func, 'public': public} - self._endpoints[command] = settings + self._endpoints[command] = func diff --git a/sirbot/slack/store/message/command.py b/sirbot/slack/store/message/command.py index f60c6ba..1425d7f 100644 --- a/sirbot/slack/store/message/command.py +++ b/sirbot/slack/store/message/command.py @@ -8,14 +8,11 @@ class SlackCommand: def __init__(self, command, frm, to, response_url, timestamp, - text='', raw=None, settings=None): + text='', raw=None): if not raw: raw = dict() - if not settings: - settings = dict() - self.command = command self.frm = frm self.to = to @@ -23,10 +20,9 @@ def __init__(self, command, frm, to, response_url, timestamp, self.timestamp = timestamp self.text = text self.raw = raw - self.settings = settings @classmethod - async def from_raw(cls, data, slack, timestamp=None, settings=None): + async def from_raw(cls, data, slack, timestamp=None): frm = await slack.users.get(data['user_id']) if data['channel_id'].startswith('C'): @@ -47,18 +43,16 @@ async def from_raw(cls, data, slack, timestamp=None, settings=None): text=data['text'], timestamp=timestamp, raw=data, - settings=settings, ) - def response(self): + def response(self, type_='in_channel'): - if self.settings.get('public'): - response_type = 'in_channel' - else: - response_type = 'ephemeral' + if type_ not in ('in_channel', 'ephemeral'): + raise ValueError('''response type must be one of 'in_channel', + 'ephemeral' ''') return SlackMessage( to=self.to, response_url=self.response_url, - response_type=response_type + response_type=type_ ) diff --git a/sirbot/slack/wrapper.py b/sirbot/slack/wrapper.py index c374bd6..f81c555 100644 --- a/sirbot/slack/wrapper.py +++ b/sirbot/slack/wrapper.py @@ -145,9 +145,9 @@ def add_event(self, event, func): else: raise SlackInactiveDispatcher - def add_command(self, command, func, public=False): + def add_command(self, command, func): if 'command' in self._dispatcher: - self._dispatcher['command'].register(command, func, public=public) + self._dispatcher['command'].register(command, func) else: raise SlackInactiveDispatcher