From 58eef21ea4ca564cf760f7156642ad51a80b829c Mon Sep 17 00:00:00 2001 From: stephenyeargin Date: Thu, 14 May 2026 12:09:12 -0500 Subject: [PATCH] Update Slack detection approach --- .flox/env/manifest.lock | 2 +- .flox/env/manifest.toml | 2 +- README.md | 2 +- .../package-lock.json | 2 + .../src/aggregator.js | 13 +++++- .../test/aggregation-module.test.js | 46 ++++++++++++++++++- .../hubot-slacklogs/src/slacklogs.js | 18 ++++++-- hubot-modules/hubot-wisdom/src/wisdom.js | 11 ++++- 8 files changed, 86 insertions(+), 10 deletions(-) diff --git a/.flox/env/manifest.lock b/.flox/env/manifest.lock index 1f7644e..f936706 100644 --- a/.flox/env/manifest.lock +++ b/.flox/env/manifest.lock @@ -1,7 +1,7 @@ { "lockfile-version": 1, "manifest": { - "version": 1, + "schema-version": "1.12.0", "install": { "ack": { "pkg-path": "ack" diff --git a/.flox/env/manifest.toml b/.flox/env/manifest.toml index d99cfd3..b16ccc1 100644 --- a/.flox/env/manifest.toml +++ b/.flox/env/manifest.toml @@ -4,7 +4,7 @@ # or see flox-edit(1), manifest.toml(5) for more information. # # Flox manifest version managed by Flox CLI -version = 1 +schema-version = "1.12.0" # List packages you wish to install in your environment inside # the `[install]` section. diff --git a/README.md b/README.md index e0d13f8..00646dc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Mando Fun This is the collection tools, daemons, libraries and binaries for collaborating -with your collegues across the internet. +with your colleagues across the internet. The primary goal is to be things that are enjoyable to use, but ultimately have some utility in terms of helping people accomplish something -- even if that diff --git a/hubot-modules/hubot-message-aggregator/package-lock.json b/hubot-modules/hubot-message-aggregator/package-lock.json index d9a06bc..e44d1f6 100644 --- a/hubot-modules/hubot-message-aggregator/package-lock.json +++ b/hubot-modules/hubot-message-aggregator/package-lock.json @@ -424,6 +424,7 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", "dev": true, + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -964,6 +965,7 @@ "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.39.3.tgz", "integrity": "sha512-VmQ+sifHUbI/IcSopBCF/HO3YiHQx/AVd3UVyYL6weuwW+HvON9VYn5l6Zl1WZzPWXPNZrSQpxwkkZ/VuvJZzg==", "dev": true, + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", diff --git a/hubot-modules/hubot-message-aggregator/src/aggregator.js b/hubot-modules/hubot-message-aggregator/src/aggregator.js index ac58549..ff1884e 100644 --- a/hubot-modules/hubot-message-aggregator/src/aggregator.js +++ b/hubot-modules/hubot-message-aggregator/src/aggregator.js @@ -52,6 +52,15 @@ const handleReaction = (res, robot) => { handleReactionWithChannelId(res, robot, targetChannel, aggregatorPattern, regexFlags); }; +function isSlackAdapter(robot) { + const adapterName = robot.adapterName != null + ? robot.adapterName + : robot.adapter && robot.adapter.name != null + ? robot.adapter.name + : ''; + return /slack/i.test(adapterName); +} + function handleReactionWithChannelId(res, robot, channelId, aggregatorPattern, regexFlags) { const message = res.message; const reactionRegex = new RegExp(aggregatorPattern, regexFlags); @@ -182,7 +191,7 @@ function findChannelIdByName(robot, channelName) { } module.exports = (robot) => { - if (robot.adapterName !== 'slack') { + if (!isSlackAdapter(robot)) { return; } @@ -196,4 +205,4 @@ module.exports.handleReaction = handleReaction; module.exports.handleReactionWithChannelId = handleReactionWithChannelId; module.exports.cleanupBrain = cleanupBrain; module.exports.fetchMessagePermalink = fetchMessagePermalink; -module.exports.findChannelIdByName = findChannelIdByName; \ No newline at end of file +module.exports.findChannelIdByName = findChannelIdByName; diff --git a/hubot-modules/hubot-message-aggregator/test/aggregation-module.test.js b/hubot-modules/hubot-message-aggregator/test/aggregation-module.test.js index ff2f778..f8bb445 100644 --- a/hubot-modules/hubot-message-aggregator/test/aggregation-module.test.js +++ b/hubot-modules/hubot-message-aggregator/test/aggregation-module.test.js @@ -11,6 +11,7 @@ const { findChannelIdByName, fetchMessagePermalink } = aggregator; +const isSlackAdapter = aggregator.__get__('isSlackAdapter'); describe('reaction-aggregator module exports', () => { let robot; @@ -573,6 +574,27 @@ describe('reaction-aggregator module exports', () => { }); }); + describe('isSlackAdapter', () => { + it('matches adapterName values containing slack', () => { + expect(isSlackAdapter({ + adapterName: '@hubot-friends/hubot-slack' + })).to.be.true; + }); + + it('falls back to robot.adapter.name when adapterName is unset', () => { + expect(isSlackAdapter({ + adapter: { name: 'SlackBot' } + })).to.be.true; + }); + + it('returns false when neither adapter value is slack', () => { + expect(isSlackAdapter({ + adapterName: 'shell', + adapter: { name: 'discord' } + })).to.be.false; + }); + }); + describe('module initialization', () => { it('does not register listener for non-slack adapter', () => { const initRobot = { @@ -594,6 +616,28 @@ describe('reaction-aggregator module exports', () => { expect(initRobot.hearReaction.calledOnce).to.be.true; }); + it('registers hearReaction for adapter names containing slack', () => { + const initRobot = { + adapterName: '@hubot-friends/hubot-slack', + hearReaction: sinon.spy(), + logger: { error: sinon.spy(), info: sinon.spy() }, + brain: { data: {} } + }; + aggregator(initRobot); + expect(initRobot.hearReaction.calledOnce).to.be.true; + }); + + it('registers hearReaction when robot.adapter.name contains slack', () => { + const initRobot = { + adapter: { name: 'Slack Adapter' }, + hearReaction: sinon.spy(), + logger: { error: sinon.spy(), info: sinon.spy() }, + brain: { data: {} } + }; + aggregator(initRobot); + expect(initRobot.hearReaction.calledOnce).to.be.true; + }); + it('runs brain cleanup on 24-hour interval', () => { const initRobot = { adapterName: 'slack', @@ -619,4 +663,4 @@ describe('reaction-aggregator module exports', () => { expect(initRobot.brain.data).to.have.property('permalink_fresh'); }); }); -}); \ No newline at end of file +}); diff --git a/hubot-modules/hubot-slacklogs/src/slacklogs.js b/hubot-modules/hubot-slacklogs/src/slacklogs.js index 364b5eb..f651b9d 100644 --- a/hubot-modules/hubot-slacklogs/src/slacklogs.js +++ b/hubot-modules/hubot-slacklogs/src/slacklogs.js @@ -33,6 +33,18 @@ const slackClient = slackToken ? new WebClient(slackToken) : null; // In-memory cache for room name/type const roomCache = new Map(); +function getAdapterName(robot) { + return robot.adapterName != null + ? robot.adapterName + : robot.adapter && robot.adapter.name != null + ? robot.adapter.name + : ''; +} + +function isSlackAdapter(robot) { + return /slack/i.test(getAdapterName(robot)); +} + function getSlackRoomType(roomId) { if (!roomId || typeof roomId !== 'string') return 'unknown'; if (roomId.startsWith('C')) return 'public_channel'; @@ -74,8 +86,9 @@ async function getRoomInfo(roomId) { } module.exports = (robot) => { - if (robot.adapterName !== 'slack') { - console.log(`[hubot-logger] Adapter is '${robot.adapterName}', skipping Slack-specific logging.`); + const adapterName = getAdapterName(robot); + if (!isSlackAdapter(robot)) { + console.log(`[hubot-logger] Adapter is '${adapterName}', skipping Slack-specific logging.`); return; } @@ -113,4 +126,3 @@ module.exports = (robot) => { } }); }; - diff --git a/hubot-modules/hubot-wisdom/src/wisdom.js b/hubot-modules/hubot-wisdom/src/wisdom.js index 92f69fd..1ebac69 100644 --- a/hubot-modules/hubot-wisdom/src/wisdom.js +++ b/hubot-modules/hubot-wisdom/src/wisdom.js @@ -17,6 +17,15 @@ const { WebClient } = require('@slack/web-api'); +function isSlackAdapter(robot) { + const adapterName = robot.adapterName != null + ? robot.adapterName + : robot.adapter && robot.adapter.name != null + ? robot.adapter.name + : ''; + return /slack/i.test(adapterName); +} + module.exports = (robot) => { // Listening for quotes and storing them @@ -41,7 +50,7 @@ module.exports = (robot) => { }); // Check if the bot is running in Slack - if(robot.adapterName === 'slack') { + if(isSlackAdapter(robot)) { const slackMessage = msg.message.rawMessage; if(slackMessage && slackMessage.ts && slackMessage.channel) {