From 02374a051d9b7a6a26565931dfc106267d95a9f3 Mon Sep 17 00:00:00 2001 From: Zapdos26 Date: Fri, 7 Feb 2020 21:15:18 -0500 Subject: [PATCH 01/11] No longer ping users on poll move Make &, >, < work on poll move --- src/Actions.ts | 16 +++++++++++----- src/Poll.ts | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Actions.ts b/src/Actions.ts index bcf8059..966eda0 100644 --- a/src/Actions.ts +++ b/src/Actions.ts @@ -1,7 +1,7 @@ -import { Poll } from "./Poll"; -import { WebClient, WebAPICallResult, ChatPostMessageArguments } from "@slack/web-api"; -import { KnownBlock } from "@slack/types"; -import { Request, Response } from "express"; +import {Poll} from "./Poll"; +import {ChatPostMessageArguments, ChatUpdateArguments, WebAPICallResult, WebClient} from "@slack/web-api"; +import {KnownBlock} from "@slack/types"; +import {Request, Response} from "express"; import * as Sentry from "@sentry/node"; const errorMsg = "An error occurred; please contact the administrators for assistance."; @@ -109,7 +109,13 @@ export class Actions { await this.wc.chat.delete({ channel: payload.channel.id, ts: payload.message.ts }) .catch((err: any) => console.error(err)); // Must be artificially slowed down to prevent the poll from glitching out on Slack's end - setTimeout(() => this.postMessage(payload.channel.id, payload.message.text, payload.message.blocks), 300); + setTimeout(() => this.postMessage(payload.channel.id, "Poll Moved!", []).then((res: any) => { + const msg: ChatUpdateArguments = { + channel: payload.channel.id, text: payload.message.text, + ts: res.ts, blocks: payload.message.blocks + }; + this.wc.chat.update(msg); + }), 300); } else { this.postEphemeralOnlyAuthor("move", "poll", payload.channel.id, payload.user.id); } diff --git a/src/Poll.ts b/src/Poll.ts index b0c111f..49fc457 100644 --- a/src/Poll.ts +++ b/src/Poll.ts @@ -1,7 +1,14 @@ import { - KnownBlock, SectionBlock, ContextBlock, Button, ActionsBlock, StaticSelect, PlainTextElement, MrkdwnElement + ActionsBlock, + Button, + ContextBlock, + KnownBlock, + MrkdwnElement, + PlainTextElement, + SectionBlock, + StaticSelect } from "@slack/types"; -import { PollHelpers } from "./PollHelpers"; +import {PollHelpers} from "./PollHelpers"; import * as Sentry from "@sentry/node"; export class Poll { @@ -81,7 +88,10 @@ export class Poll { } public getBlocks(): KnownBlock[] { - return this.message; + let str = JSON.stringify(this.message); + str = str.replace("<", "<") + .replace(">", ">").replace("&", "&"); + return JSON.parse(str); } public getAuthor(): string { From 8582ba71ddea11b4c2ad373cf3fb31764e96fe99 Mon Sep 17 00:00:00 2001 From: Zapdos26 Date: Tue, 11 Feb 2020 22:07:32 -0500 Subject: [PATCH 02/11] Fixed spacing --- src/Poll.ts | 11 ++--------- src/PollHelpers.ts | 6 ++---- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Poll.ts b/src/Poll.ts index 49fc457..70b6333 100644 --- a/src/Poll.ts +++ b/src/Poll.ts @@ -1,12 +1,5 @@ import { - ActionsBlock, - Button, - ContextBlock, - KnownBlock, - MrkdwnElement, - PlainTextElement, - SectionBlock, - StaticSelect + ActionsBlock, Button, ContextBlock, KnownBlock, MrkdwnElement, PlainTextElement, SectionBlock, StaticSelect } from "@slack/types"; import {PollHelpers} from "./PollHelpers"; import * as Sentry from "@sentry/node"; @@ -192,7 +185,7 @@ export class Poll { } private generateVoteResults(): void { - // We throw out the old vote response and construct them again + // We throw out the old vote response and construct them again const sectionBlocks = this.generateResults(false); this.message = this.message.slice(0, this.getDividerId() + 1).concat(sectionBlocks); } diff --git a/src/PollHelpers.ts b/src/PollHelpers.ts index 00abd84..a5f0bc1 100644 --- a/src/PollHelpers.ts +++ b/src/PollHelpers.ts @@ -1,6 +1,4 @@ -import { - SectionBlock, ContextBlock, PlainTextElement, Option -} from "@slack/types"; +import { SectionBlock, ContextBlock, PlainTextElement, Option } from "@slack/types"; export class PollHelpers { public static appendIfMatching(optionArray: string[], keyword: string, appendText: string): string { @@ -22,4 +20,4 @@ export class PollHelpers { public static buildTextElem(text: string): PlainTextElement { return { type: "plain_text", text, emoji: true }; } -} \ No newline at end of file +} From d8a9f0a279b7e181c1cbe1e214b52393df3dd3bf Mon Sep 17 00:00:00 2001 From: Zapdos26 Date: Tue, 11 Feb 2020 22:12:11 -0500 Subject: [PATCH 03/11] Fixed spacing --- src/Actions.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Actions.ts b/src/Actions.ts index 966eda0..db30089 100644 --- a/src/Actions.ts +++ b/src/Actions.ts @@ -1,7 +1,7 @@ -import {Poll} from "./Poll"; -import {ChatPostMessageArguments, ChatUpdateArguments, WebAPICallResult, WebClient} from "@slack/web-api"; -import {KnownBlock} from "@slack/types"; -import {Request, Response} from "express"; +import { Poll } from "./Poll" +import { ChatPostMessageArguments, ChatUpdateArguments, WebAPICallResult, WebClient } from "@slack/web-api"; +import { KnownBlock } from "@slack/types"; +import { Request, Response } from "express"; import * as Sentry from "@sentry/node"; const errorMsg = "An error occurred; please contact the administrators for assistance."; From 7707f645f2becdc2aa73e22a1276ea9db12ad0ac Mon Sep 17 00:00:00 2001 From: Zapdos26 Date: Tue, 11 Feb 2020 22:15:14 -0500 Subject: [PATCH 04/11] Fixed spacing --- src/Poll.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Poll.ts b/src/Poll.ts index 70b6333..a13b933 100644 --- a/src/Poll.ts +++ b/src/Poll.ts @@ -1,7 +1,7 @@ import { ActionsBlock, Button, ContextBlock, KnownBlock, MrkdwnElement, PlainTextElement, SectionBlock, StaticSelect } from "@slack/types"; -import {PollHelpers} from "./PollHelpers"; +import { PollHelpers } from "./PollHelpers"; import * as Sentry from "@sentry/node"; export class Poll { From a88622293a6f507e8322cb9e101d4b4a1ea2bd24 Mon Sep 17 00:00:00 2001 From: Zapdos26 Date: Tue, 11 Feb 2020 22:16:12 -0500 Subject: [PATCH 05/11] Added semicolon --- src/Actions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Actions.ts b/src/Actions.ts index db30089..701ab7a 100644 --- a/src/Actions.ts +++ b/src/Actions.ts @@ -1,4 +1,4 @@ -import { Poll } from "./Poll" +import { Poll } from "./Poll"; import { ChatPostMessageArguments, ChatUpdateArguments, WebAPICallResult, WebClient } from "@slack/web-api"; import { KnownBlock } from "@slack/types"; import { Request, Response } from "express"; From 9e6321af0be2f6e97ff5945085a750be814b695e Mon Sep 17 00:00:00 2001 From: Zapdos26 Date: Fri, 7 Feb 2020 21:15:18 -0500 Subject: [PATCH 06/11] No longer ping users on poll move Make &, >, < work on poll move --- src/Actions.ts | 16 +++++++++++----- src/Poll.ts | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Actions.ts b/src/Actions.ts index bcf8059..966eda0 100644 --- a/src/Actions.ts +++ b/src/Actions.ts @@ -1,7 +1,7 @@ -import { Poll } from "./Poll"; -import { WebClient, WebAPICallResult, ChatPostMessageArguments } from "@slack/web-api"; -import { KnownBlock } from "@slack/types"; -import { Request, Response } from "express"; +import {Poll} from "./Poll"; +import {ChatPostMessageArguments, ChatUpdateArguments, WebAPICallResult, WebClient} from "@slack/web-api"; +import {KnownBlock} from "@slack/types"; +import {Request, Response} from "express"; import * as Sentry from "@sentry/node"; const errorMsg = "An error occurred; please contact the administrators for assistance."; @@ -109,7 +109,13 @@ export class Actions { await this.wc.chat.delete({ channel: payload.channel.id, ts: payload.message.ts }) .catch((err: any) => console.error(err)); // Must be artificially slowed down to prevent the poll from glitching out on Slack's end - setTimeout(() => this.postMessage(payload.channel.id, payload.message.text, payload.message.blocks), 300); + setTimeout(() => this.postMessage(payload.channel.id, "Poll Moved!", []).then((res: any) => { + const msg: ChatUpdateArguments = { + channel: payload.channel.id, text: payload.message.text, + ts: res.ts, blocks: payload.message.blocks + }; + this.wc.chat.update(msg); + }), 300); } else { this.postEphemeralOnlyAuthor("move", "poll", payload.channel.id, payload.user.id); } diff --git a/src/Poll.ts b/src/Poll.ts index b0c111f..49fc457 100644 --- a/src/Poll.ts +++ b/src/Poll.ts @@ -1,7 +1,14 @@ import { - KnownBlock, SectionBlock, ContextBlock, Button, ActionsBlock, StaticSelect, PlainTextElement, MrkdwnElement + ActionsBlock, + Button, + ContextBlock, + KnownBlock, + MrkdwnElement, + PlainTextElement, + SectionBlock, + StaticSelect } from "@slack/types"; -import { PollHelpers } from "./PollHelpers"; +import {PollHelpers} from "./PollHelpers"; import * as Sentry from "@sentry/node"; export class Poll { @@ -81,7 +88,10 @@ export class Poll { } public getBlocks(): KnownBlock[] { - return this.message; + let str = JSON.stringify(this.message); + str = str.replace("<", "<") + .replace(">", ">").replace("&", "&"); + return JSON.parse(str); } public getAuthor(): string { From 37a1bad0fc14bfab968f48b1263148dce4622bd1 Mon Sep 17 00:00:00 2001 From: Zapdos26 Date: Tue, 11 Feb 2020 22:07:32 -0500 Subject: [PATCH 07/11] Fixed spacing --- src/Poll.ts | 11 ++--------- src/PollHelpers.ts | 6 ++---- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Poll.ts b/src/Poll.ts index 49fc457..70b6333 100644 --- a/src/Poll.ts +++ b/src/Poll.ts @@ -1,12 +1,5 @@ import { - ActionsBlock, - Button, - ContextBlock, - KnownBlock, - MrkdwnElement, - PlainTextElement, - SectionBlock, - StaticSelect + ActionsBlock, Button, ContextBlock, KnownBlock, MrkdwnElement, PlainTextElement, SectionBlock, StaticSelect } from "@slack/types"; import {PollHelpers} from "./PollHelpers"; import * as Sentry from "@sentry/node"; @@ -192,7 +185,7 @@ export class Poll { } private generateVoteResults(): void { - // We throw out the old vote response and construct them again + // We throw out the old vote response and construct them again const sectionBlocks = this.generateResults(false); this.message = this.message.slice(0, this.getDividerId() + 1).concat(sectionBlocks); } diff --git a/src/PollHelpers.ts b/src/PollHelpers.ts index 00abd84..a5f0bc1 100644 --- a/src/PollHelpers.ts +++ b/src/PollHelpers.ts @@ -1,6 +1,4 @@ -import { - SectionBlock, ContextBlock, PlainTextElement, Option -} from "@slack/types"; +import { SectionBlock, ContextBlock, PlainTextElement, Option } from "@slack/types"; export class PollHelpers { public static appendIfMatching(optionArray: string[], keyword: string, appendText: string): string { @@ -22,4 +20,4 @@ export class PollHelpers { public static buildTextElem(text: string): PlainTextElement { return { type: "plain_text", text, emoji: true }; } -} \ No newline at end of file +} From daed5c12256104d3de36ff8ab06f73c2aad6a6ad Mon Sep 17 00:00:00 2001 From: Zapdos26 Date: Tue, 11 Feb 2020 22:12:11 -0500 Subject: [PATCH 08/11] Fixed spacing --- src/Actions.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Actions.ts b/src/Actions.ts index 966eda0..db30089 100644 --- a/src/Actions.ts +++ b/src/Actions.ts @@ -1,7 +1,7 @@ -import {Poll} from "./Poll"; -import {ChatPostMessageArguments, ChatUpdateArguments, WebAPICallResult, WebClient} from "@slack/web-api"; -import {KnownBlock} from "@slack/types"; -import {Request, Response} from "express"; +import { Poll } from "./Poll" +import { ChatPostMessageArguments, ChatUpdateArguments, WebAPICallResult, WebClient } from "@slack/web-api"; +import { KnownBlock } from "@slack/types"; +import { Request, Response } from "express"; import * as Sentry from "@sentry/node"; const errorMsg = "An error occurred; please contact the administrators for assistance."; From d5b221e19ac6d05c085b9677917871e01fe10a1c Mon Sep 17 00:00:00 2001 From: Zapdos26 Date: Tue, 11 Feb 2020 22:15:14 -0500 Subject: [PATCH 09/11] Fixed spacing --- src/Poll.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Poll.ts b/src/Poll.ts index 70b6333..a13b933 100644 --- a/src/Poll.ts +++ b/src/Poll.ts @@ -1,7 +1,7 @@ import { ActionsBlock, Button, ContextBlock, KnownBlock, MrkdwnElement, PlainTextElement, SectionBlock, StaticSelect } from "@slack/types"; -import {PollHelpers} from "./PollHelpers"; +import { PollHelpers } from "./PollHelpers"; import * as Sentry from "@sentry/node"; export class Poll { From 342e3d3b236131ea4a1f26fa26c9946f9c81cfd0 Mon Sep 17 00:00:00 2001 From: Zapdos26 Date: Tue, 11 Feb 2020 22:16:12 -0500 Subject: [PATCH 10/11] Added semicolon --- src/Actions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Actions.ts b/src/Actions.ts index db30089..701ab7a 100644 --- a/src/Actions.ts +++ b/src/Actions.ts @@ -1,4 +1,4 @@ -import { Poll } from "./Poll" +import { Poll } from "./Poll"; import { ChatPostMessageArguments, ChatUpdateArguments, WebAPICallResult, WebClient } from "@slack/web-api"; import { KnownBlock } from "@slack/types"; import { Request, Response } from "express"; From b5eb98a059c4e82f292035d0d8741db9ab787eba Mon Sep 17 00:00:00 2001 From: Zapdos26 Date: Tue, 11 Feb 2020 22:45:22 -0500 Subject: [PATCH 11/11] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1b3d395..e55c209 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "slack-poll", - "version": "2.2.3", + "version": "2.2.4", "description": "Databaseless Slack Polling", "main": "server.js", "scripts": {