Skip to content

Commit

Permalink
Added Reply function (#63)
Browse files Browse the repository at this point in the history
* added reply function

* allow commands in replies "@user !command msg"
  • Loading branch information
liyunze-coding authored Jan 18, 2025
1 parent 4ebf9b8 commit 1b45775
Show file tree
Hide file tree
Showing 7 changed files with 1,202 additions and 653 deletions.
19 changes: 19 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,17 @@ var comfyJS = {
}
return false;
},
Reply: function (parentId, message, channel) {
if (client) {
if (!channel) {
channel = mainChannel;
}
const replyMessage = `@reply-parent-msg-id=${parentId} PRIVMSG #${channel} :${message}`;
client.ws.send(replyMessage);
return true;
}
return false;
},
Whisper: function( message, user ) {
if( client ) {
client.whisper( user, message )
Expand Down Expand Up @@ -463,6 +474,14 @@ var comfyJS = {
var msg = parts[ 1 ] || "";
extra["sinceLastCommand"] = getTimePeriod( command, userId );
comfyJS.onCommand( user, command, msg, flags, extra );
} else if (!self && message.split(" ").length > 0 && message[0] === "@" && message.split(" ")[1][0] === "!"){
// Message is also a command: @user !command
// Remove first word (@mention)
var parts = message.split(" ");
var command = parts[1].slice(1).toLowerCase();
var msg = parts.slice(2).join(" ");
extra["sinceLastCommand"] = getTimePeriod(command, userId);
comfyJS.onCommand(user, command, msg, flags, extra);
}
else {
if( messageType === "action" || messageType === "chat" ) {
Expand Down
23 changes: 21 additions & 2 deletions dist/comfy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
// Comfy.JS v1.1.16
// Comfy.JS v1.1.17
var tmi = require( "tmi.js" );
var fetch = require( "node-fetch" );
var NodeSocket = require( "ws" );
Expand Down Expand Up @@ -223,7 +223,7 @@ var comfyJS = {
isDebug: false,
chatModes: {},
version: function() {
return "1.1.16";
return "1.1.17";
},
onError: function( error ) {
console.error( "Error:", error );
Expand Down Expand Up @@ -333,6 +333,17 @@ var comfyJS = {
}
return false;
},
Reply: function (parentId, message, channel) {
if (client) {
if (!channel) {
channel = mainChannel;
}
const replyMessage = `@reply-parent-msg-id=${parentId} PRIVMSG #${channel} :${message}`;
client.ws.send(replyMessage);
return true;
}
return false;
},
Whisper: function( message, user ) {
if( client ) {
client.whisper( user, message )
Expand Down Expand Up @@ -464,6 +475,14 @@ var comfyJS = {
var msg = parts[ 1 ] || "";
extra["sinceLastCommand"] = getTimePeriod( command, userId );
comfyJS.onCommand( user, command, msg, flags, extra );
} else if (!self && message.split(" ").length > 0 && message[0] === "@" && message.split(" ")[1][0] === "!"){
// Message is also a command: @user !command
// Remove first word (@mention)
var parts = message.split(" ");
var command = parts[1].slice(1).toLowerCase();
var msg = parts.slice(2).join(" ");
extra["sinceLastCommand"] = getTimePeriod(command, userId);
comfyJS.onCommand(user, command, msg, flags, extra);
}
else {
if( messageType === "action" || messageType === "chat" ) {
Expand Down
2 changes: 1 addition & 1 deletion dist/comfy.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/comfy.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 1b45775

Please sign in to comment.