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 855faa5..112986d 100644 --- a/hubot-modules/hubot-message-aggregator/package-lock.json +++ b/hubot-modules/hubot-message-aggregator/package-lock.json @@ -460,6 +460,7 @@ "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -1200,6 +1201,7 @@ "integrity": "sha512-XoMjdBOwe/esVgEvLmNsD3IRHkm7fbKIUGvrleloJXUZgDHig2IPWNniv+GwjyJXzuNqVjlr5+4yVUZjycJwfQ==", "dev": true, "license": "MIT", + "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) {