Skip to content

Commit

Permalink
Fix cmd not found msg and other sendChatMessage() calls in friendMess…
Browse files Browse the repository at this point in the history
…age event not working
  • Loading branch information
3urobeat committed May 6, 2023
1 parent 8347cb6 commit 8d0bdea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/bot/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 09.07.2021 16:26:00
* Author: 3urobeat
*
* Last Modified: 03.05.2023 17:14:51
* Last Modified: 06.05.2023 10:56:38
* Modified By: 3urobeat
*
* Copyright (c) 2021 3urobeat <https://github.com/HerrEurobeat>
Expand Down Expand Up @@ -135,9 +135,11 @@ module.exports = Bot;
Bot.prototype.checkMsgBlock = function(steamID64, message) {}; // eslint-disable-line

/**
* Send a message to a Steam user
* @param {Object} resInf Object containing information passed to command by friendMessage event
* Our commandHandler respondModule implementation - Sends a message to a Steam user
* @param {Object} _this The Bot object context
* @param {Object} resInfo Object containing information passed to command by friendMessage event
* @param {String} txt The text to send
* @param {Boolean} retry Internal: true if this message called itself again to send failure message
* @param {Number} part Internal: Index of which part to send for messages larger than 750 chars
*/
Bot.prototype.sendChatMessage = function(resInf, txt, retry) {}; // eslint-disable-line
Bot.prototype.sendChatMessage = function(_this, resInfo, txt, retry, part = 0) {}; // eslint-disable-line
12 changes: 6 additions & 6 deletions src/bot/events/friendMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 09.07.2021 16:26:00
* Author: 3urobeat
*
* Last Modified: 03.05.2023 21:50:24
* Last Modified: 06.05.2023 10:58:06
* Modified By: 3urobeat
*
* Copyright (c) 2021 3urobeat <https://github.com/HerrEurobeat>
Expand All @@ -26,8 +26,8 @@ const Bot = require("../bot.js");
Bot.prototype._attachSteamFriendMessageEvent = function() {

this.user.on("friendMessage", (steamID, message) => {
let resInfo = { steamID64: steamID.getSteamID64() }; // Object required for sendChatMessage(), our commandHandler respondModule implementation
let steamID64 = new SteamID(String(steamID)).getSteamID64();
let resInfo = { steamID64: steamID64 }; // Object required for sendChatMessage(), our commandHandler respondModule implementation


// Check if this event should be handled or if user is blocked
Expand All @@ -44,10 +44,10 @@ Bot.prototype._attachSteamFriendMessageEvent = function() {
if (this.index !== 0) {
switch(message.toLowerCase()) {
case "!about": // Please don't change this message as it gives credit to me; the person who put really much of his free time into this project. The bot will still refer to you - the operator of this instance.
this.sendChatMessage(resInfo, this.controller.data.datafile.aboutstr);
this.sendChatMessage(this, resInfo, this.controller.data.datafile.aboutstr);
break;
default:
if (message.startsWith("!")) this.sendChatMessage(steamID64, `${this.controller.data.lang.childbotmessage}\nhttps://steamcommunity.com/profiles/${new SteamID(String(this.controller.main.user.steamID)).getSteamID64()}`);
if (message.startsWith("!")) this.sendChatMessage(this, resInfo, `${this.controller.data.lang.childbotmessage}\nhttps://steamcommunity.com/profiles/${new SteamID(String(this.controller.main.user.steamID)).getSteamID64()}`);
else logger("debug", `[${this.logPrefix}] Chat message is not a command, ignoring message.`);
}

Expand All @@ -74,7 +74,7 @@ Bot.prototype._attachSteamFriendMessageEvent = function() {

// Handle non-prefixed messages
if (!message.startsWith("!")) {
if (message.toLowerCase() == ":)") return this.sendChatMessage(steamID, ":))"); // Hehe
if (message.toLowerCase() == ":)") return this.sendChatMessage(this, resInfo, ":))"); // Hehe

logger("debug", "Chat message is not a command, ignoring message.");
return;
Expand All @@ -87,7 +87,7 @@ Bot.prototype._attachSteamFriendMessageEvent = function() {

let success = this.controller.commandHandler.runCommand(cont[0].toLowerCase(), args, steamID64, this.sendChatMessage, this, resInfo);

if (!success) this.sendChatMessage(steamID, this.controller.data.lang.commandnotfound); // Send cmd not found msg if runCommand() returned false
if (!success) this.sendChatMessage(this, resInfo, this.controller.data.lang.commandnotfound); // Send cmd not found msg if runCommand() returned false
});

};

0 comments on commit 8d0bdea

Please sign in to comment.