Finished fixing types
This commit is contained in:
parent
3a7bd1811f
commit
418a7029bd
|
|
@ -119,7 +119,7 @@ def lookup_slackid_brother(slack_id: str) -> Optional[scroll_util.Brother]:
|
||||||
return None
|
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.
|
Returns a list of all userids associated with the given brother.
|
||||||
|
|
||||||
|
|
|
||||||
8
main.py
8
main.py
|
|
@ -57,6 +57,14 @@ def main() -> None:
|
||||||
help_callback = management_commands.list_hooks_callback_gen(wrap.hooks)
|
help_callback = management_commands.list_hooks_callback_gen(wrap.hooks)
|
||||||
wrap.add_hook(slack_util.Hook(help_callback, pattern=management_commands.bot_help_pattern))
|
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 = asyncio.get_event_loop()
|
||||||
event_loop.run_until_complete(wrap.listen())
|
event_loop.run_until_complete(wrap.listen())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import channel_util
|
||||||
import slack_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
|
# noinspection PyUnusedLocal
|
||||||
async def callback(slack, msg, match):
|
async def callback(slack, msg, match):
|
||||||
slack_util.reply(slack, msg, "\n".join(hook.pattern for hook in hooks))
|
slack_util.reply(slack, msg, "\n".join(hook.pattern for hook in hooks))
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
from time import sleep
|
|
||||||
import re
|
import re
|
||||||
|
from time import sleep
|
||||||
|
from typing import Any, Optional, Generator, Match, Callable, List, Coroutine
|
||||||
|
|
||||||
from slackclient import SlackClient
|
from slackclient import SlackClient
|
||||||
|
|
||||||
import channel_util
|
import channel_util
|
||||||
from typing import Any, Optional, Generator, Match, Callable, List, Awaitable, Coroutine
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Slack helpers. Separated for compartmentalization
|
Slack helpers. Separated for compartmentalization
|
||||||
|
|
@ -82,9 +82,13 @@ def message_stream(slack: SlackClient) -> Generator[dict, None, None]:
|
||||||
print("Connection failed - retrying")
|
print("Connection failed - retrying")
|
||||||
|
|
||||||
|
|
||||||
|
MsgAction = Coroutine[Any, Any, None]
|
||||||
|
Callback = Callable[[SlackClient, dict, Match], MsgAction]
|
||||||
|
|
||||||
|
|
||||||
class Hook(object):
|
class Hook(object):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
callback: Coroutine[[SlackClient, dict, Match]],
|
callback: Callback,
|
||||||
pattern: str = None,
|
pattern: str = None,
|
||||||
channel_whitelist: Optional[List[str]] = None,
|
channel_whitelist: Optional[List[str]] = None,
|
||||||
channel_blacklist: Optional[List[str]] = None):
|
channel_blacklist: Optional[List[str]] = None):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue