From efef9e81695d155f6edf36e329619ba2289eccc2 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Sat, 4 May 2024 20:05:39 -0500 Subject: [PATCH] Command to restart a matrix pool --- backend/src/event-handlers/bot-commands.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/backend/src/event-handlers/bot-commands.js b/backend/src/event-handlers/bot-commands.js index 9794d28..9d96867 100644 --- a/backend/src/event-handlers/bot-commands.js +++ b/backend/src/event-handlers/bot-commands.js @@ -1,13 +1,15 @@ const { registerMatrixMessageHandler } = require('../matrix-bot'); const { setTargetRoomId } = require('../matrix-bot/outbound-queue'); - const { appState, proposalEventIds, + matrixPools, } = require('../util/db'); const submitRollup = require('./rollup/submit-rollup'); const { resetBatchItems } = require('./rollup/batch-items'); const { initiateMatrixPools } = require('./rollup/matrix-pools/initiate-matrix-pools'); +const initiateMatrixPool = require('./rollup/matrix-pools/initiate'); +const read = require('../util/forum/read'); const { BOT_INSTANCE_ID, @@ -25,6 +27,7 @@ const handleCommand = async (client, roomId, event) => { const proposalRegex = /\bprop(|osal) ([0-9]+)\b/i; const submitRollupRegex = /^!submitBatch\b/i; const resetBatchRegex = /^!resetBatch (.*)\b/i; + const restartMatrixPoolRegex = /^!restartMatrixPool (.*)\b/i; const { body } = event.content; @@ -75,6 +78,16 @@ const handleCommand = async (client, roomId, event) => { await initiateMatrixPools(); await client.replyText(roomId, event, `Reset batch, now contains ${batchItems.length} items`); } + } else if (restartMatrixPoolRegex.test(body)) { + const [, postId] = restartMatrixPoolRegex.exec(body); + console.log(`!restartMatrixPool roomId ${roomId} postId ${postId}`); + try { + const { sender, fee } = await matrixPools.get(postId); + const post = await read(postId); + await initiateMatrixPool(postId, post, sender, fee); + } catch (e) { + // Can't restart if it was never started + } } };