Giter Club home page Giter Club logo

Comments (7)

gkelle avatar gkelle commented on August 12, 2024 4

Here's a patch @drislands and I cooked up for a quick fix. Took some inspiration from https://github.com/slackapi/node-slack-sdk/wiki/DataStore-v3.x-Migration-Guide

--- a/lib/bot.js	2021-08-27 23:34:32.622846730 -0700
+++ b/lib/bot.js	2021-08-27 23:34:28.351824023 -0700
@@ -254,27 +254,29 @@
         return;
       }
 
-      const currentChannelUsernames = slackChannel.members.map(member =>
-        dataStore.getUserById(member).name
-      );
+      this.slack.web.conversations.members(slackChannel.id).then( resp => {
+        const currentChannelUsernames = resp.members.map(member =>
+          dataStore.getUserById(member).name
+        );
 
-      const mappedText = currentChannelUsernames.reduce((current, username) =>
-        highlightUsername(username, current)
-      , text);
+        const mappedText = currentChannelUsernames.reduce((current, username) =>
+          highlightUsername(username, current)
+        , text);
 
-      let iconUrl;
-      if (author !== this.nickname && this.avatarUrl) {
-        iconUrl = this.avatarUrl.replace(/\$username/g, author);
-      }
+        let iconUrl;
+        if (author !== this.nickname && this.avatarUrl) {
+          iconUrl = this.avatarUrl.replace(/\$username/g, author);
+        }
 
-      const options = {
-        username: this.slackUsernameFormat.replace(/\$username/g, author),
-        parse: 'full',
-        icon_url: iconUrl
-      };
+        const options = {
+          username: this.slackUsernameFormat.replace(/\$username/g, author),
+          parse: 'full',
+          icon_url: iconUrl
+        };
 
-      logger.debug('Sending message to Slack', mappedText, channel, '->', slackChannelName);
-      this.slack.web.chat.postMessage(slackChannel.id, mappedText, options);
+        logger.debug('Sending message to Slack', mappedText, channel, '->', slackChannelName);
+        this.slack.web.chat.postMessage(slackChannel.id, mappedText, options);
+      });
     }
   }
 }

from slack-irc.

gkelle avatar gkelle commented on August 12, 2024 3

@bovine I've just submitted a pull request for the change

from slack-irc.

adamhorden avatar adamhorden commented on August 12, 2024

We are having the same issue. I have spent a couple of hours debugging to try and find out why this has just randomly stopped working. So far not found anything. Will keep looking.

Adam Horden

from slack-irc.

Byproduct avatar Byproduct commented on August 12, 2024

My bot has stopped working too. It manages to join IRC, then soon dies with this message:

/usr/lib/node_modules/slack-irc/node_modules/irc/lib/irc.js:849
                        throw err;
                        ^

TypeError: Cannot read property 'map' of undefined
    at Bot.sendToSlack (/usr/lib/node_modules/slack-irc/dist/bot.js:295:60)
    at emitMany (events.js:147:13)
    at Client.emit (events.js:224:7)
    at Client.<anonymous> (/usr/lib/node_modules/slack-irc/node_modules/irc/lib/irc.js:557:22)
    at emitOne (events.js:116:13)
    at Client.emit (events.js:211:7)
    at iterator (/usr/lib/node_modules/slack-irc/node_modules/irc/lib/irc.js:846:26)
    at Array.forEach (<anonymous>)
    at Socket.handleData (/usr/lib/node_modules/slack-irc/node_modules/irc/lib/irc.js:841:15)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:246:13)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at TCP.onread (net.js:601:20)

from slack-irc.

drislands avatar drislands commented on August 12, 2024

Unless I'm mistaken, this is the line that is failing:

var currentChannelUsernames = slackChannel.members.map(function (member) {

Whatever part of the code that gets the members list is not working, for some reason. Perhaps an API change on Slack's end?

from slack-irc.

bovine avatar bovine commented on August 12, 2024

@gkelle Perhaps you could submit that change as a new pull request and reference this issue?

from slack-irc.

tetlowgm avatar tetlowgm commented on August 12, 2024

I can confirm this is working for me. Would be nice for @ekmartin to accept the PR.

from slack-irc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.