Added some aliases. Maybe fixed some shit idk.

This commit is contained in:
Jacob Henry 2018-11-29 15:30:48 -05:00
parent 3446558487
commit d2843fb7ed
8 changed files with 44 additions and 24 deletions

View File

@ -28,4 +28,4 @@ async def channel_check_callback(slack: SlackClient, msg: dict, match: Match) ->
channel_check_hook = slack_util.Hook(channel_check_callback,
pattern=r"channel id\s*(.*)")
patterns=r"channel id\s*(.*)")

View File

@ -138,7 +138,7 @@ def lookup_brother_userids(brother: scroll_util.Brother) -> List[str]:
return result
identify_hook = slack_util.Hook(identify_callback, pattern=r"my scroll is (.*)")
identify_other_hook = slack_util.Hook(identify_other_callback, pattern=r"<@(.*)>\s+has scroll\s+(.*)")
check_hook = slack_util.Hook(check_callback, pattern=r"what is my scroll")
name_hook = slack_util.Hook(name_callback, pattern=r"what is my name")
identify_hook = slack_util.Hook(identify_callback, patterns=r"my scroll is (.*)")
identify_other_hook = slack_util.Hook(identify_other_callback, patterns=r"<@(.*)>\s+has scroll\s+(.*)")
check_hook = slack_util.Hook(check_callback, patterns=r"what is my scroll")
name_hook = slack_util.Hook(name_callback, patterns=r"what is my name")

View File

@ -314,21 +314,33 @@ async def nag_callback(slack, msg, match):
signoff_hook = slack_util.Hook(signoff_callback,
pattern=r"signoff\s+(.*)",
patterns=[
r"signoff\s+(.*)",
r"sign off\s+(.*)",
],
channel_whitelist=[channel_util.HOUSEJOBS])
late_hook = slack_util.Hook(late_callback,
pattern=r"marklate\s+(.*)",
patterns=[
r"marklate\s+(.*)",
r"mark late\s+(.*)",
],
channel_whitelist=[channel_util.HOUSEJOBS])
reset_hook = slack_util.Hook(reset_callback,
pattern=r"reset signoffs",
patterns=[
r"reset signoffs",
r"reset sign offs",
],
channel_whitelist=[channel_util.COMMAND_CENTER_ID])
nag_hook = slack_util.Hook(nag_callback,
pattern=r"nagjobs\s*(.*)",
patterns=[
r"nagjobs\s+(.*)",
r"nag jobs\s+(.*)"
],
channel_whitelist=[channel_util.COMMAND_CENTER_ID])
reassign_hook = slack_util.Hook(reassign_callback,
pattern=r"reassign\s+(.*?)-&gt;\s+(.+)",
patterns=r"reassign\s+(.*?)-&gt;\s+(.+)",
channel_whitelist=[channel_util.HOUSEJOBS])

View File

@ -45,7 +45,7 @@ def main() -> None:
wrap.add_hook(job_commands.reassign_hook)
# Add help
wrap.add_hook(slack_util.Hook(help_callback, pattern=management_commands.bot_help_pattern))
wrap.add_hook(slack_util.Hook(help_callback, patterns=[r"help", r"bot\s+help"]))
# Add boozebot
# wrap.add_passive(periodicals.ItsTenPM())
@ -61,6 +61,7 @@ def main() -> None:
event_loop.run_until_complete(both)
# noinspection PyUnusedLocal
async def help_callback(slack: SlackClient, msg: dict, match: Match) -> None:
slack_util.reply(slack, msg, textwrap.dedent("""
Commands are as follows. Note that some only work in certain channels.

View File

@ -9,7 +9,7 @@ import slack_util
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))
slack_util.reply(slack, msg, "\n".join(hook.patterns for hook in hooks))
return callback
@ -23,7 +23,6 @@ async def reboot_callback(slack: SlackClient, msg: dict, match: Match) -> None:
# Make hooks
bot_help_pattern = r"help" # Can't init this directly, as it relies on us knowing all other hooks. handle in main
reboot_hook = slack_util.Hook(reboot_callback,
pattern=r"reboot",
patterns=r"reboot",
channel_whitelist=[channel_util.COMMAND_CENTER_ID])

View File

@ -105,4 +105,4 @@ async def find_by_name(name: str, threshold: Optional[float] = None) -> Brother:
raise BrotherNotFound(msg)
scroll_hook = slack_util.Hook(scroll_callback, pattern=r"scroll\s+(.*)")
scroll_hook = slack_util.Hook(scroll_callback, patterns=r"scroll\s+(.*)")

View File

@ -1,7 +1,6 @@
import re
import typing
from time import sleep, time
from typing import Any, Optional, Generator, Match, Callable, List, Coroutine
from typing import Any, Optional, Generator, Match, Callable, List, Coroutine, Union, TypeVar, Awaitable
from slackclient import SlackClient
from slackclient.client import SlackNotConnected
@ -68,7 +67,7 @@ def message_stream(slack: SlackClient) -> Generator[dict, None, None]:
print("Connection failed - retrying")
T = typing.TypeVar("T")
T = TypeVar("T")
class VerboseWrapper(Callable):
@ -80,7 +79,7 @@ class VerboseWrapper(Callable):
self.slack = slack
self.command_msg = command_msg
async def __call__(self, awt: typing.Awaitable[T]) -> T:
async def __call__(self, awt: Awaitable[T]) -> T:
try:
return await awt
except Exception as e:
@ -108,14 +107,17 @@ class AbsHook(object):
class Hook(AbsHook):
def __init__(self,
callback: Callback,
pattern: str,
patterns: Union[str, List[str]],
channel_whitelist: Optional[List[str]] = None,
channel_blacklist: Optional[List[str]] = None,
consumer: bool = True):
super(Hook, self).__init__(consumer)
# Save all
self.pattern = pattern
if not isinstance(patterns, list):
patterns = [patterns]
self.patterns = patterns
self.channel_whitelist = channel_whitelist
self.channel_blacklist = channel_blacklist
self.callback = callback
@ -134,7 +136,12 @@ class Hook(AbsHook):
Returns whether a message should be handled by this dict, returning a Match if so, or None
"""
# Fail if pattern invalid
match = re.match(self.pattern, msg['text'], flags=re.IGNORECASE)
match = None
for p in self.patterns:
match = re.match(p, msg['text'], flags=re.IGNORECASE)
if match is not None:
break
if match is None:
return None
@ -170,6 +177,7 @@ class ReplyWaiter(AbsHook):
# If so, give up the ghost
if self.dead or should_expire:
print("Reply waiter has expired after {} seconds".format(time_alive))
raise DeadHook()
# Otherwise proceed normally

View File

@ -93,8 +93,8 @@ async def dump_work_callback(slack: SlackClient, msg: dict, match: Match) -> Non
# Make dem HOOKs
count_work_hook = slack_util.Hook(count_work_callback,
pattern=".*",
patterns=".*",
channel_whitelist=[channel_util.SLAVES_TO_THE_MACHINE_ID])
dump_work_hook = slack_util.Hook(dump_work_callback,
pattern="dump towel data",
patterns="dump towel data",
channel_whitelist=[channel_util.COMMAND_CENTER_ID])