Added undo signoffs

This commit is contained in:
Jacob Henry 2018-12-04 22:24:17 -05:00
parent 2c468d5c0d
commit de373fd9a5
2 changed files with 55 additions and 16 deletions

View File

@ -180,6 +180,35 @@ async def signoff_callback(slack: SlackClient, msg: dict, match: Match) -> None:
await _mod_jobs(slack, msg, scorer, modifier) await _mod_jobs(slack, msg, scorer, modifier)
async def undo_callback(slack: SlackClient, msg: dict, match: Match) -> None:
verb = slack_util.VerboseWrapper(slack, msg)
# Find out who we are trying to sign off is
signee_name = match.group(1)
signee = await verb(scroll_util.find_by_name(signee_name, MIN_RATIO))
# Score by name similarity, only accepting jobs that are signed off
def scorer(assign: house_management.JobAssignment):
if assign.assignee is not None:
r = fuzz.ratio(signee.name, assign.assignee.name)
if assign.signer is not None and r > MIN_RATIO:
return r
# Set the assigner to be None, and notify
def modifier(context: _ModJobContext):
context.assign.signer = None
# Say we did it wooo!
slack_util.reply(slack, msg, "Undid signoff of {} for {}".format(context.assign.assignee.name,
context.assign.job.name))
alert_user(slack, context.assign.assignee, "{} undid your signoff off for {}.\n"
"Must have been a mistake".format(context.assign.signer.name,
context.assign.job.pretty_fmt()))
# Fire it off
await _mod_jobs(slack, msg, scorer, modifier)
async def late_callback(slack: SlackClient, msg: dict, match: Match) -> None: async def late_callback(slack: SlackClient, msg: dict, match: Match) -> None:
verb = slack_util.VerboseWrapper(slack, msg) verb = slack_util.VerboseWrapper(slack, msg)
@ -273,6 +302,7 @@ async def reset_callback(slack: SlackClient, msg: dict, match: Match) -> None:
slack_util.reply(slack, msg, "Reset scores and signoffs") slack_util.reply(slack, msg, "Reset scores and signoffs")
# noinspection PyUnusedLocal
async def refresh_callback(slack: SlackClient, msg: dict, match: Match) -> None: async def refresh_callback(slack: SlackClient, msg: dict, match: Match) -> None:
headers, points = await house_management.import_points() headers, points = await house_management.import_points()
house_management.apply_house_points(points, await house_management.import_assignments()) house_management.apply_house_points(points, await house_management.import_assignments())
@ -328,6 +358,14 @@ signoff_hook = slack_util.Hook(signoff_callback,
], ],
channel_whitelist=[channel_util.HOUSEJOBS]) channel_whitelist=[channel_util.HOUSEJOBS])
undo_hook = slack_util.Hook(undo_callback,
patterns=[
r"unsignoff\s+(.*)",
r"undosignoff\s+(.*)",
r"undo signoff\s+(.*)",
],
channel_whitelist=[channel_util.HOUSEJOBS])
late_hook = slack_util.Hook(late_callback, late_hook = slack_util.Hook(late_callback,
patterns=[ patterns=[
r"marklate\s+(.*)", r"marklate\s+(.*)",

19
main.py
View File

@ -66,19 +66,20 @@ def main() -> None:
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.
"my scroll is <number>" : Registers your slack account to have a certain scroll, for the purpose of automatic dm's. "my scroll is number" : Registers your slack account to have a certain scroll, for the purpose of automatic dm's.
"@person has scroll <number>" : same as above, but for other users. Helpful if they are being obstinate. "@person has scroll number" : same as above, but for other users. Helpful if they are being obstinate.
"what is my scroll" : Echos back what the bot thinks your scroll is. Largely for debugging. "what is my scroll" : Echos back what the bot thinks your scroll is. Largely for debugging.
"what is my name" : Echos back what the bot thinks your name is. Largely for debugging. If you want to change this, you'll need to fix the "Sorted family tree" file that the bot reads. Sorry. "what is my name" : Echos back what the bot thinks your name is. Largely for debugging. If you want to change this, you'll need to fix the "Sorted family tree" file that the bot reads. Sorry.
"channel id #wherever" : Debug command to get a slack channels full ID "channel id #wherever" : Debug command to get a slack channels full ID
"reboot" : Restarts the server. "reboot" : Restarts the server.
"dump towel data" : Summarize the towel roller work for the week, and reset it. "signoff John Doe" : Sign off a brother's house job. Will prompt for more information if needed.
"signoff <John Doe>" : Sign off a brother's house job. Will prompt for more information if needed. "marklate John Doe" : Same as above, but to mark a job as being completed but having been done late.
"marklate <John Doe>" : Same as above, but to mark a job as being completed but having been done late. "reassign John Doe -> James Deer" : Reassign a house job.
"reassign <John Doe> -> <James Deer>" : Reassign a house job. "undo signoff John Doe" : Marks a brother's house job as incomplete. Useful if you fucked up.
"nagjobs <day>" : Notify in general the house jobs for the week. "nagjobs day" : Notify in general the house jobs for the week.
"reset signoffs" : Clear points for the week, and undo all signoffs. Not frequently useful. "reset signoffs" : Clear points for the week, and undo all signoffs. Not frequently useful, admin only.
"help" : You stupid or something? You're reading it. This is all it does. What do you want from me? "refresh points" : Updates house job / signoff points for the week, after manual edits to the sheet. Admin only.
"help" : You're reading it. This is all it does. What do you want from me?
--- ---