From 56e8d221268449a431abddace9e00e5297c01512 Mon Sep 17 00:00:00 2001 From: Phoebe <40956085+C1701D@users.noreply.github.com> Date: Sun, 12 May 2024 19:43:32 +0200 Subject: [PATCH] [Halpy-361] Combine Cases Command First Pass - Adds a new command, ``combcases``, and adds a corresponding help text. --- data/help/commands.json | 5 +++++ halpybot/commands/caseutils.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/data/help/commands.json b/data/help/commands.json index ef24dae7..96ecb9dd 100644 --- a/data/help/commands.json +++ b/data/help/commands.json @@ -197,6 +197,11 @@ "arguments": "[Board ID] [New Dispatchers]", "use": "Add a new dispatcher to a given case on the board." }, + "combcases": { + "aliases:": [], + "arguments": "[Board ID to keep] [Board ID to combine]", + "use": "Combine two cases into a single case." + }, "delcase": { "aliases:": [ "remcase" diff --git a/halpybot/commands/caseutils.py b/halpybot/commands/caseutils.py index 8d14b20e..2575f6b6 100644 --- a/halpybot/commands/caseutils.py +++ b/halpybot/commands/caseutils.py @@ -753,6 +753,36 @@ async def cmd_editnote(ctx: Context, args: List[str], case: Case): # ADMINSTRATIVE MANAGEMENT +@Commands.command("combcases") +@needs_permission(Admin) +@in_channel +@gather_case(2) +async def cmd_combine_cases(ctx: Context, args: List[str], case: Case): + """ + Combines two cases into one, transferring all notes and responders from the second case to the first. + + Usage: !combcases [board ID to keep] [board ID to combine] + Aliases: n/a + """ + try: + case2: Case = await get_case(ctx, args[1]) + except KeyError: + return await ctx.reply(f"No case found for {args[1]!r}.") + # case.case_notes.extend(case2.case_notes) + case.responders.extend(case2.responders) + case.dispatchers.extend(case2.dispatchers) + if case2.welcomed: + res_kwarg = {"welcomed": True} + await ctx.bot.board.mod_case(case_id=case.board_id, **res_kwarg) + case_comb_note = f"{ctx.sender} combined case {case2.board_id} into case {case.board_id} at {now(tz='UTC').to_time_string()}" + case_summary = f"{case2}" + case.case_notes.append(case_comb_note) + case.case_notes.append(case_summary) + + await ctx.bot.board.del_case(case=case2) + return await ctx.reply(f"Combined case {case2.board_id} into case {case.board_id}.") + + @Commands.command("delcase", "remcase") @needs_permission(Admin) @in_channel