Skip to content

Commit

Permalink
fix: Extension now sends list of available themes to chat rather than…
Browse files Browse the repository at this point in the history
… whisper
  • Loading branch information
michaeljolley committed Jun 6, 2023
1 parent db6f4ff commit 20330bf
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 63 deletions.
3 changes: 1 addition & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"--extensionDevelopmentPath=${workspaceFolder}",
"--disable-extensions"
],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "npm: watch"
"preLaunchTask": "npm: compile"
},
{
"name": "Extension Tests",
Expand Down
14 changes: 0 additions & 14 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 0 additions & 11 deletions src/chatClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
);
Expand All @@ -62,7 +59,6 @@ export async function activate(context: vscode.ExtensionContext) {

context.subscriptions.push(
themerOnSendMessage,
themerOnSendWhisper,
chatOnChatMessageReceived,
authOnAuthStatusChanged,
chatOnConnectionChanged,
Expand Down Expand Up @@ -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);
}
Expand Down
19 changes: 9 additions & 10 deletions src/test/suite/themer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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);
Expand Down
22 changes: 5 additions & 17 deletions src/themer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ export default class Themer {
private _redemptionHoldPeriodMinutes: number = 5;
private _pauseThemer: boolean = false;

private sendWhisperEventEmitter = new vscode.EventEmitter<WhisperMessage>();
private sendMessageEventEmitter = new vscode.EventEmitter<string>();

/** 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;

Expand Down Expand Up @@ -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, ""));
}

/**
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(() => {
Expand Down

0 comments on commit 20330bf

Please sign in to comment.