From 20330bfddb54dcb438c8b25f88db79362e1ed9ab Mon Sep 17 00:00:00 2001 From: Michael Jolley Date: Tue, 6 Jun 2023 14:54:22 -0500 Subject: [PATCH] fix: Extension now sends list of available themes to chat rather than whisper --- .vscode/launch.json | 3 +-- .vscode/tasks.json | 14 -------------- src/api.ts | 2 +- src/chatClient.ts | 11 ----------- src/extension.ts | 8 -------- src/test/suite/themer.test.ts | 19 +++++++++---------- src/themer.ts | 22 +++++----------------- 7 files changed, 16 insertions(+), 63 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 588238a..b160e9c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,8 +13,7 @@ "--extensionDevelopmentPath=${workspaceFolder}", "--disable-extensions" ], - "outFiles": ["${workspaceFolder}/out/**/*.js"], - "preLaunchTask": "npm: watch" + "preLaunchTask": "npm: compile" }, { "name": "Extension Tests", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 9e3300b..94039bf 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -3,20 +3,6 @@ { "version": "2.0.0", "tasks": [ - { - "type": "npm", - "script": "watch", - "problemMatcher": "$ts-webpack-watch", - "isBackground": true, - "presentation": { - "reveal": "never", - "group": "watchers" - }, - "group": { - "kind": "build", - "isDefault": true - } - }, { "type": "npm", "script": "watch-tests", diff --git a/src/api.ts b/src/api.ts index 104566a..4365de4 100644 --- a/src/api.ts +++ b/src/api.ts @@ -128,7 +128,7 @@ export default class API { const repoUrl = `https://raw.githubusercontent.com/${repoUrlMatches[1].replace( ".git", "" - )}/main/package.json`; + )}/HEAD/package.json`; res = await fetch(repoUrl, { method: "GET" }); if (res.status !== 200) { return { diff --git a/src/chatClient.ts b/src/chatClient.ts index b58f016..d52c8b7 100644 --- a/src/chatClient.ts +++ b/src/chatClient.ts @@ -151,17 +151,6 @@ export default class ChatClient { } } - /** - * Sends a whisper to the specified user - * @param twitchUser - Username of the recipient of the whisper - * @param message - Message to send to the twitchUser - */ - public whisper(whisperMessage: WhisperMessage) { - if (this.isConnected() && whisperMessage.user !== undefined) { - comfyJS.Whisper(whisperMessage.message, whisperMessage.user); - } - } - /** * Sends a message to Twitch chat * @param message - Message to send to chat diff --git a/src/extension.ts b/src/extension.ts index 0051e20..1afa378 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -5,12 +5,10 @@ import ChatClient from "./chatClient"; import Logger from "./logger"; import Themer from "./themer"; -import { WhisperMessage } from "./types/whisperMessage"; import { ChatMessage } from "./types/chatMessage"; import { Commands, LogLevel } from "./constants"; import { createStatusBarItem } from "./statusBar"; -let _authentication: Authentication; let _chatClient: ChatClient | undefined; let _themer: Themer | undefined; @@ -50,7 +48,6 @@ export async function activate(context: vscode.ExtensionContext) { ); const themerOnSendMessage = _themer.onSendMessage(onSendMessage); - const themerOnSendWhisper = _themer.onSendWhisper(onSendWhisper); const chatOnChatMessageReceived = _chatClient.onChatMessageReceived( onChatMessageReceived ); @@ -62,7 +59,6 @@ export async function activate(context: vscode.ExtensionContext) { context.subscriptions.push( themerOnSendMessage, - themerOnSendWhisper, chatOnChatMessageReceived, authOnAuthStatusChanged, chatOnConnectionChanged, @@ -109,10 +105,6 @@ async function onSendMessage(message: string) { await _chatClient?.sendMessage(message); } -async function onSendWhisper(whisper: WhisperMessage) { - _chatClient?.whisper(whisper); -} - async function onChatMessageReceived(chatMessage: ChatMessage) { await _themer?.handleCommands(chatMessage); } diff --git a/src/test/suite/themer.test.ts b/src/test/suite/themer.test.ts index 4fa20f0..694a224 100644 --- a/src/test/suite/themer.test.ts +++ b/src/test/suite/themer.test.ts @@ -388,15 +388,14 @@ suite("Themer Tests", function () { test("Themer should return a comma separated list of themes", function (done) { let recipient: string; - let whisperedMessage: string; + let sentMessage: string; - const whisperStub = sinon - .stub(fakeChatClient, "whisper") - .callsFake((whisperMessage: WhisperMessage) => { - recipient = whisperMessage.user; - whisperedMessage = whisperMessage.message; + const sendMessageStub = sinon + .stub(fakeChatClient, "sendMessage") + .callsFake(async (message: string) => { + sentMessage = message; }); - fakeThemer.onSendWhisper(whisperStub); + fakeThemer.onSendMessage(sendMessageStub); const message = ""; const chatMessage: ChatMessage = { @@ -407,11 +406,11 @@ suite("Themer Tests", function () { }; fakeThemer.handleCommands(chatMessage).then(() => { try { - whisperStub.calledOnce.should.be.true; + sendMessageStub.calledOnce.should.be.true; recipient!.should.exist; recipient!.should.equal("test"); - whisperedMessage.should.exist; - whisperedMessage.split(", ").length.should.be.greaterThan(0); + sentMessage.should.exist; + sentMessage.split(", ").length.should.be.greaterThan(0); done(); } catch (error) { done(error); diff --git a/src/themer.ts b/src/themer.ts index 1acf46f..ad4863d 100644 --- a/src/themer.ts +++ b/src/themer.ts @@ -30,12 +30,8 @@ export default class Themer { private _redemptionHoldPeriodMinutes: number = 5; private _pauseThemer: boolean = false; - private sendWhisperEventEmitter = new vscode.EventEmitter(); private sendMessageEventEmitter = new vscode.EventEmitter(); - /** Event that fires when themer needs to send a whisper */ - public onSendWhisper = this.sendWhisperEventEmitter.event; - /** Event that fires when themer needs to send a message */ public onSendMessage = this.sendMessageEventEmitter.event; @@ -348,19 +344,13 @@ export default class Themer { } else { /** If no more theme names can be added, go ahead and send the first message * and start over building the next message */ - this.sendWhisperEventEmitter.fire({ - user, - message: message.replace(/(^[,\s]+)|([,\s]+$)/g, ""), - }); + this.sendMessageEventEmitter.fire(message.replace(/(^[,\s]+)|([,\s]+$)/g, "")); message = `${name}, `; } } /** Send the final message */ - this.sendWhisperEventEmitter.fire({ - user, - message: message.replace(/(^[,\s]+)|([,\s]+$)/g, ""), - }); + this.sendMessageEventEmitter.fire(message.replace(/(^[,\s]+)|([,\s]+$)/g, "")); } /** @@ -571,9 +561,8 @@ export default class Themer { try { // Authorize the install of the extension if we do not allow for auto-installed extensions. if (!this._autoInstall) { - const msg = `${user} wants to install theme(s) ${ - isValidExtResult.label ? isValidExtResult.label.join(", ") : theme - }.`; + const msg = `${user} wants to install theme(s) ${isValidExtResult.label ? isValidExtResult.label.join(", ") : theme + }.`; Logger.log(LogLevel.info, `${msg}`); let choice = await vscode.window.showInformationMessage( msg, @@ -736,8 +725,7 @@ export default class Themer { // start a "pause" timer this.setPauseStatus(true); this.sendMessageEventEmitter.fire( - `${user} has redeemed pausing the theme on ${themeName} for ${ - this._redemptionHoldPeriodMinutes + `${user} has redeemed pausing the theme on ${themeName} for ${this._redemptionHoldPeriodMinutes } minute${this._redemptionHoldPeriodMinutes === 1 ? "" : "s"}.` ); setTimeout(() => {