Finished fixing types

This commit is contained in:
Jacob Henry 2018-11-08 00:38:25 -05:00
parent 3a7bd1811f
commit 418a7029bd
4 changed files with 17 additions and 5 deletions

View File

@ -119,7 +119,7 @@ def lookup_slackid_brother(slack_id: str) -> Optional[scroll_util.Brother]:
return None
async def lookup_brother_userids(brother: scroll_util.Brother) -> List[str]:
def lookup_brother_userids(brother: scroll_util.Brother) -> List[str]:
"""
Returns a list of all userids associated with the given brother.

View File

@ -57,6 +57,14 @@ def main() -> None:
help_callback = management_commands.list_hooks_callback_gen(wrap.hooks)
wrap.add_hook(slack_util.Hook(help_callback, pattern=management_commands.bot_help_pattern))
# Schedule?
async def do_later(slk: SlackClient, msg: dict, match: typing.Match):
time = int(match.group(1))
await asyncio.sleep(time)
slack_util.reply(slk, msg, "hello!")
wrap.add_hook(slack_util.Hook(do_later, "pingme\s+(\d+)"))
event_loop = asyncio.get_event_loop()
event_loop.run_until_complete(wrap.listen())

View File

@ -6,7 +6,7 @@ import channel_util
import slack_util
async def list_hooks_callback_gen(hooks: List[slack_util.Hook]):
def list_hooks_callback_gen(hooks: List[slack_util.Hook]) -> slack_util.Callback:
# noinspection PyUnusedLocal
async def callback(slack, msg, match):
slack_util.reply(slack, msg, "\n".join(hook.pattern for hook in hooks))

View File

@ -1,10 +1,10 @@
from time import sleep
import re
from time import sleep
from typing import Any, Optional, Generator, Match, Callable, List, Coroutine
from slackclient import SlackClient
import channel_util
from typing import Any, Optional, Generator, Match, Callable, List, Awaitable, Coroutine
"""
Slack helpers. Separated for compartmentalization
@ -82,9 +82,13 @@ def message_stream(slack: SlackClient) -> Generator[dict, None, None]:
print("Connection failed - retrying")
MsgAction = Coroutine[Any, Any, None]
Callback = Callable[[SlackClient, dict, Match], MsgAction]
class Hook(object):
def __init__(self,
callback: Coroutine[[SlackClient, dict, Match]],
callback: Callback,
pattern: str = None,
channel_whitelist: Optional[List[str]] = None,
channel_blacklist: Optional[List[str]] = None):