Added some aliases. Maybe fixed some shit idk.
This commit is contained in:
parent
3446558487
commit
d2843fb7ed
|
|
@ -28,4 +28,4 @@ async def channel_check_callback(slack: SlackClient, msg: dict, match: Match) ->
|
||||||
|
|
||||||
|
|
||||||
channel_check_hook = slack_util.Hook(channel_check_callback,
|
channel_check_hook = slack_util.Hook(channel_check_callback,
|
||||||
pattern=r"channel id\s*(.*)")
|
patterns=r"channel id\s*(.*)")
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ def lookup_brother_userids(brother: scroll_util.Brother) -> List[str]:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
identify_hook = slack_util.Hook(identify_callback, pattern=r"my scroll is (.*)")
|
identify_hook = slack_util.Hook(identify_callback, patterns=r"my scroll is (.*)")
|
||||||
identify_other_hook = slack_util.Hook(identify_other_callback, pattern=r"<@(.*)>\s+has scroll\s+(.*)")
|
identify_other_hook = slack_util.Hook(identify_other_callback, patterns=r"<@(.*)>\s+has scroll\s+(.*)")
|
||||||
check_hook = slack_util.Hook(check_callback, pattern=r"what is my scroll")
|
check_hook = slack_util.Hook(check_callback, patterns=r"what is my scroll")
|
||||||
name_hook = slack_util.Hook(name_callback, pattern=r"what is my name")
|
name_hook = slack_util.Hook(name_callback, patterns=r"what is my name")
|
||||||
|
|
|
||||||
|
|
@ -314,21 +314,33 @@ async def nag_callback(slack, msg, match):
|
||||||
|
|
||||||
|
|
||||||
signoff_hook = slack_util.Hook(signoff_callback,
|
signoff_hook = slack_util.Hook(signoff_callback,
|
||||||
pattern=r"signoff\s+(.*)",
|
patterns=[
|
||||||
|
r"signoff\s+(.*)",
|
||||||
|
r"sign off\s+(.*)",
|
||||||
|
],
|
||||||
channel_whitelist=[channel_util.HOUSEJOBS])
|
channel_whitelist=[channel_util.HOUSEJOBS])
|
||||||
|
|
||||||
late_hook = slack_util.Hook(late_callback,
|
late_hook = slack_util.Hook(late_callback,
|
||||||
pattern=r"marklate\s+(.*)",
|
patterns=[
|
||||||
|
r"marklate\s+(.*)",
|
||||||
|
r"mark late\s+(.*)",
|
||||||
|
],
|
||||||
channel_whitelist=[channel_util.HOUSEJOBS])
|
channel_whitelist=[channel_util.HOUSEJOBS])
|
||||||
|
|
||||||
reset_hook = slack_util.Hook(reset_callback,
|
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])
|
channel_whitelist=[channel_util.COMMAND_CENTER_ID])
|
||||||
|
|
||||||
nag_hook = slack_util.Hook(nag_callback,
|
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])
|
channel_whitelist=[channel_util.COMMAND_CENTER_ID])
|
||||||
|
|
||||||
reassign_hook = slack_util.Hook(reassign_callback,
|
reassign_hook = slack_util.Hook(reassign_callback,
|
||||||
pattern=r"reassign\s+(.*?)->\s+(.+)",
|
patterns=r"reassign\s+(.*?)->\s+(.+)",
|
||||||
channel_whitelist=[channel_util.HOUSEJOBS])
|
channel_whitelist=[channel_util.HOUSEJOBS])
|
||||||
|
|
|
||||||
3
main.py
3
main.py
|
|
@ -45,7 +45,7 @@ def main() -> None:
|
||||||
wrap.add_hook(job_commands.reassign_hook)
|
wrap.add_hook(job_commands.reassign_hook)
|
||||||
|
|
||||||
# Add help
|
# 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
|
# Add boozebot
|
||||||
# wrap.add_passive(periodicals.ItsTenPM())
|
# wrap.add_passive(periodicals.ItsTenPM())
|
||||||
|
|
@ -61,6 +61,7 @@ def main() -> None:
|
||||||
event_loop.run_until_complete(both)
|
event_loop.run_until_complete(both)
|
||||||
|
|
||||||
|
|
||||||
|
# noinspection PyUnusedLocal
|
||||||
async def help_callback(slack: SlackClient, msg: dict, match: Match) -> None:
|
async def help_callback(slack: SlackClient, msg: dict, match: Match) -> None:
|
||||||
slack_util.reply(slack, msg, textwrap.dedent("""
|
slack_util.reply(slack, msg, textwrap.dedent("""
|
||||||
Commands are as follows. Note that some only work in certain channels.
|
Commands are as follows. Note that some only work in certain channels.
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import slack_util
|
||||||
def list_hooks_callback_gen(hooks: List[slack_util.Hook]) -> slack_util.Callback:
|
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.patterns for hook in hooks))
|
||||||
|
|
||||||
return callback
|
return callback
|
||||||
|
|
||||||
|
|
@ -23,7 +23,6 @@ async def reboot_callback(slack: SlackClient, msg: dict, match: Match) -> None:
|
||||||
|
|
||||||
|
|
||||||
# Make hooks
|
# 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,
|
reboot_hook = slack_util.Hook(reboot_callback,
|
||||||
pattern=r"reboot",
|
patterns=r"reboot",
|
||||||
channel_whitelist=[channel_util.COMMAND_CENTER_ID])
|
channel_whitelist=[channel_util.COMMAND_CENTER_ID])
|
||||||
|
|
|
||||||
|
|
@ -105,4 +105,4 @@ async def find_by_name(name: str, threshold: Optional[float] = None) -> Brother:
|
||||||
raise BrotherNotFound(msg)
|
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+(.*)")
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import re
|
import re
|
||||||
import typing
|
|
||||||
from time import sleep, time
|
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 import SlackClient
|
||||||
from slackclient.client import SlackNotConnected
|
from slackclient.client import SlackNotConnected
|
||||||
|
|
@ -68,7 +67,7 @@ def message_stream(slack: SlackClient) -> Generator[dict, None, None]:
|
||||||
print("Connection failed - retrying")
|
print("Connection failed - retrying")
|
||||||
|
|
||||||
|
|
||||||
T = typing.TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
|
||||||
|
|
||||||
class VerboseWrapper(Callable):
|
class VerboseWrapper(Callable):
|
||||||
|
|
@ -80,7 +79,7 @@ class VerboseWrapper(Callable):
|
||||||
self.slack = slack
|
self.slack = slack
|
||||||
self.command_msg = command_msg
|
self.command_msg = command_msg
|
||||||
|
|
||||||
async def __call__(self, awt: typing.Awaitable[T]) -> T:
|
async def __call__(self, awt: Awaitable[T]) -> T:
|
||||||
try:
|
try:
|
||||||
return await awt
|
return await awt
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -108,14 +107,17 @@ class AbsHook(object):
|
||||||
class Hook(AbsHook):
|
class Hook(AbsHook):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
callback: Callback,
|
callback: Callback,
|
||||||
pattern: str,
|
patterns: Union[str, List[str]],
|
||||||
channel_whitelist: Optional[List[str]] = None,
|
channel_whitelist: Optional[List[str]] = None,
|
||||||
channel_blacklist: Optional[List[str]] = None,
|
channel_blacklist: Optional[List[str]] = None,
|
||||||
consumer: bool = True):
|
consumer: bool = True):
|
||||||
super(Hook, self).__init__(consumer)
|
super(Hook, self).__init__(consumer)
|
||||||
|
|
||||||
# Save all
|
# Save all
|
||||||
self.pattern = pattern
|
if not isinstance(patterns, list):
|
||||||
|
patterns = [patterns]
|
||||||
|
|
||||||
|
self.patterns = patterns
|
||||||
self.channel_whitelist = channel_whitelist
|
self.channel_whitelist = channel_whitelist
|
||||||
self.channel_blacklist = channel_blacklist
|
self.channel_blacklist = channel_blacklist
|
||||||
self.callback = callback
|
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
|
Returns whether a message should be handled by this dict, returning a Match if so, or None
|
||||||
"""
|
"""
|
||||||
# Fail if pattern invalid
|
# 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:
|
if match is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
@ -170,6 +177,7 @@ class ReplyWaiter(AbsHook):
|
||||||
|
|
||||||
# If so, give up the ghost
|
# If so, give up the ghost
|
||||||
if self.dead or should_expire:
|
if self.dead or should_expire:
|
||||||
|
print("Reply waiter has expired after {} seconds".format(time_alive))
|
||||||
raise DeadHook()
|
raise DeadHook()
|
||||||
|
|
||||||
# Otherwise proceed normally
|
# Otherwise proceed normally
|
||||||
|
|
|
||||||
|
|
@ -93,8 +93,8 @@ async def dump_work_callback(slack: SlackClient, msg: dict, match: Match) -> Non
|
||||||
|
|
||||||
# Make dem HOOKs
|
# Make dem HOOKs
|
||||||
count_work_hook = slack_util.Hook(count_work_callback,
|
count_work_hook = slack_util.Hook(count_work_callback,
|
||||||
pattern=".*",
|
patterns=".*",
|
||||||
channel_whitelist=[channel_util.SLAVES_TO_THE_MACHINE_ID])
|
channel_whitelist=[channel_util.SLAVES_TO_THE_MACHINE_ID])
|
||||||
dump_work_hook = slack_util.Hook(dump_work_callback,
|
dump_work_hook = slack_util.Hook(dump_work_callback,
|
||||||
pattern="dump towel data",
|
patterns="dump towel data",
|
||||||
channel_whitelist=[channel_util.COMMAND_CENTER_ID])
|
channel_whitelist=[channel_util.COMMAND_CENTER_ID])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue