From 4b57c56cb488b68e4b7ac80de9eea0f8058aec9b Mon Sep 17 00:00:00 2001 From: Jay Colson Date: Wed, 27 Feb 2019 20:34:54 +0000 Subject: [PATCH 1/5] working on channel_archive and channel_deleted --- irslackd-bug.txt | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/irslackd.js | 15 +++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 irslackd-bug.txt diff --git a/irslackd-bug.txt b/irslackd-bug.txt new file mode 100644 index 0000000..5e00a50 --- /dev/null +++ b/irslackd-bug.txt @@ -0,0 +1,42 @@ +Feb 27 16:43:48 vpc irslackd[1039]: slack_in user_typing { type: 'user_typing', channel: 'D43KMNF16', user: 'U0AAQ3HQ9' } +Feb 27 16:43:48 vpc irslackd[1039]: slack_out conversations.leave { channel: 'CGJ9UEYUA' } +Feb 27 16:43:48 vpc irslackd[1039]: irc_in PART #sev_sfr Buh-bye! +Feb 27 16:43:48 vpc irslackd[1039]: Trace: irslackd_err Failed onIrcPart: Error: { +Feb 27 16:43:48 vpc irslackd[1039]: "method": "conversations.leave", +Feb 27 16:43:48 vpc irslackd[1039]: "options": { +Feb 27 16:43:48 vpc irslackd[1039]: "channel": "CGJ9UEYUA" +Feb 27 16:43:48 vpc irslackd[1039]: }, +Feb 27 16:43:48 vpc irslackd[1039]: "error": { +Feb 27 16:43:48 vpc irslackd[1039]: "code": "slackclient_platform_error", +Feb 27 16:43:48 vpc irslackd[1039]: "data": { +Feb 27 16:43:48 vpc irslackd[1039]: "ok": false, +Feb 27 16:43:48 vpc irslackd[1039]: "error": "channel_not_found", +Feb 27 16:43:48 vpc irslackd[1039]: "scopes": [ +Feb 27 16:43:48 vpc irslackd[1039]: "read", +Feb 27 16:43:48 vpc irslackd[1039]: "client", +Feb 27 16:43:48 vpc irslackd[1039]: "admin", +Feb 27 16:43:48 vpc irslackd[1039]: "identify", +Feb 27 16:43:48 vpc irslackd[1039]: "post", +Feb 27 16:43:48 vpc irslackd[1039]: "apps" +Feb 27 16:43:48 vpc irslackd[1039]: ], +Feb 27 16:43:48 vpc irslackd[1039]: "acceptedScopes": [ +Feb 27 16:43:48 vpc irslackd[1039]: "channels:write", +Feb 27 16:43:48 vpc irslackd[1039]: "groups:write", +Feb 27 16:43:48 vpc irslackd[1039]: "mpim:write", +Feb 27 16:43:48 vpc irslackd[1039]: "im:write", +Feb 27 16:43:48 vpc irslackd[1039]: "post" +Feb 27 16:43:48 vpc irslackd[1039]: ] +Feb 27 16:43:48 vpc irslackd[1039]: } +Feb 27 16:43:48 vpc irslackd[1039]: } +Feb 27 16:43:48 vpc irslackd[1039]: } +Feb 27 16:43:48 vpc irslackd[1039]: at WebClient.apiCallOrThrow (/home/ec2-user/src/irslackd/lib/irslackd.js:1268:13) +Feb 27 16:43:48 vpc irslackd[1039]: at +Feb 27 16:43:48 vpc irslackd[1039]: at process._tickCallback (internal/process/next_tick.js:189:7) +Feb 27 16:43:48 vpc irslackd[1039]: at Irslackd.logError (/home/ec2-user/src/irslackd/lib/irslackd.js:1059:13) +Feb 27 16:43:48 vpc irslackd[1039]: at res.catch (/home/ec2-user/src/irslackd/lib/irslackd.js:1231:18) +Feb 27 16:43:48 vpc irslackd[1039]: at +Feb 27 16:43:48 vpc irslackd[1039]: at process._tickCallback (internal/process/next_tick.js:189:7) +Feb 27 16:43:49 vpc irslackd[1039]: slack_in pong { type: 'pong', reply_to: 1564 } +Feb 27 16:43:49 vpc irslackd[1039]: slack_in pong { type: 'pong', reply_to: 25602 } +Feb 27 16:43:50 vpc irslackd[1039]: irc_in WHO #randomtest + diff --git a/lib/irslackd.js b/lib/irslackd.js index 3d75c13..fd5e4fc 100644 --- a/lib/irslackd.js +++ b/lib/irslackd.js @@ -98,6 +98,8 @@ class Irslackd { ['channel_left', self.makeSlackHandler(self.onSlackChannelLeft)], ['channel_rename', self.makeSlackHandler(self.onSlackChannelRename)], ['channel_created', self.makeSlackHandler(self.onSlackChannelCreated)], + ['channel_deleted', self.makeSlackHandler(self.onSlackChannelDeleted)], + ['channel_archive', self.makeSlackHandler(self.onSlackChannelDeleted)], ['member_joined_channel', self.makeSlackHandler(self.onSlackMemberJoinedChannel)], ['member_left_channel', self.makeSlackHandler(self.onSlackMemberLeftChannel)], ['mpim_open', self.makeSlackHandler(self.onSlackMpimOpen)], @@ -740,6 +742,18 @@ class Irslackd { }, event.channel); } } + async onSlackChannelDeleted(ircUser, event) { + let oldIrcChan = await this.resolveSlackChannel(ircUser, event.channel.id); + // let newIrcChan = '#' + event.channel.name; + let isInChan = ircUser.isInChannel(oldIrcChan); + if (isInChan) { + this.ircd.write(ircUser.socket, ircUser.ircNick, 'PART', [oldIrcChan]); + ircUser.partChannel(oldIrcChan); + } + ircUser.ircToSlack.delete(oldIrcChan); + ircUser.slackToIrc.delete(event.channel.id); + // if (isInChan) await this.onIrcJoinOne(ircUser, newIrcChan, event.channel.id); + } async onSlackChannelRename(ircUser, event) { let oldIrcChan = await this.resolveSlackChannel(ircUser, event.channel.id); let newIrcChan = '#' + event.channel.name; @@ -999,6 +1013,7 @@ class Irslackd { async resolveSlackChannel(ircUser, slackChan) { // Check cache let ircChan = ircUser.slackToIrc.get(slackChan); + console.log('irchannel: ' + ircChan); if (ircChan) return ircChan; // Try conversations.info From 08744b52c7f9758f88f8a034e32117048ab49f61 Mon Sep 17 00:00:00 2001 From: Jay Colson Date: Thu, 28 Feb 2019 17:56:38 +0000 Subject: [PATCH 2/5] WIP rename issue #68 --- irslackd-bug.txt => irslackd-bug.log | 0 lib/irslackd.js | 1 + rename_private.log | 31 +++++++++++++++++ rename_private_mod.log | 43 +++++++++++++++++++++++ rename_public.log | 51 ++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+) rename irslackd-bug.txt => irslackd-bug.log (100%) create mode 100644 rename_private.log create mode 100644 rename_private_mod.log create mode 100644 rename_public.log diff --git a/irslackd-bug.txt b/irslackd-bug.log similarity index 100% rename from irslackd-bug.txt rename to irslackd-bug.log diff --git a/lib/irslackd.js b/lib/irslackd.js index fd5e4fc..e9871cf 100644 --- a/lib/irslackd.js +++ b/lib/irslackd.js @@ -97,6 +97,7 @@ class Irslackd { ['channel_joined', self.makeSlackHandler(self.onSlackChannelJoined)], ['channel_left', self.makeSlackHandler(self.onSlackChannelLeft)], ['channel_rename', self.makeSlackHandler(self.onSlackChannelRename)], + ['group_rename', self.makeSlackHandler(self.onSlackChannelRename)], ['channel_created', self.makeSlackHandler(self.onSlackChannelCreated)], ['channel_deleted', self.makeSlackHandler(self.onSlackChannelDeleted)], ['channel_archive', self.makeSlackHandler(self.onSlackChannelDeleted)], diff --git a/rename_private.log b/rename_private.log new file mode 100644 index 0000000..663be55 --- /dev/null +++ b/rename_private.log @@ -0,0 +1,31 @@ +slack_in group_rename { type: 'group_rename', + channel: + { id: 'GGM5P2ZE2', + name: 'private_jay', + name_normalized: 'private_jay', + is_group: true, + created: 1551375537 }, + event_ts: '1551375694.000300', + ts: '1551375694.000300' } +slack_in message { user: 'UG11EP7HU', + old_name: 'private_jhc', + name: 'private_jay', + user_profile: + { avatar_hash: 'g9e4ba3d4e92', + image_72: 'https://secure.gravatar.com/avatar/9e4ba3d4e9251f076028e1d909b00535.jpg?s=72&d=https%3A%2F%2Fcfr.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0018-72.png', + first_name: '', + real_name: 'Jay Colson', + display_name: 'Jay', + team: 'T9SAAJ4T0', + name: 'jay', + is_restricted: false, + is_ultra_restricted: false }, + type: 'message', + subtype: 'group_name', + team: 'T9SAAJ4T0', + text: '<@UG11EP7HU> has renamed the channel from "private_jhc" to "private_jay"', + channel: 'GGM5P2ZE2', + event_ts: '1551375694.000400', + ts: '1551375694.000400' } +irchannel: #private_jhc +irc_out :jay PRIVMSG #private_jhc :@jay has renamed the channel from "private_jhc" to "private_jay" \ No newline at end of file diff --git a/rename_private_mod.log b/rename_private_mod.log new file mode 100644 index 0000000..3990aa8 --- /dev/null +++ b/rename_private_mod.log @@ -0,0 +1,43 @@ +slack_in pong { type: 'pong', reply_to: 42 } +slack_in group_rename { type: 'group_rename', + channel: + { id: 'GGM5P2ZE2', + name: 'private_jc', + name_normalized: 'private_jc', + is_group: true, + created: 1551375537 }, + event_ts: '1551376250.000700', + ts: '1551376250.000700' } +irchannel: #private_j +irc_out :jay PART #private_j +slack_out conversations.info { channel: 'GGM5P2ZE2' } +slack_in message { user: 'UG11EP7HU', + old_name: 'private_j', + name: 'private_jc', + user_profile: + { avatar_hash: 'g9e4ba3d4e92', + image_72: 'https://secure.gravatar.com/avatar/9e4ba3d4e9251f076028e1d909b00535.jpg?s=72&d=https%3A%2F%2Fcfr.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0018-72.png', + first_name: '', + real_name: 'Jay Colson', + display_name: 'Jay', + team: 'T9SAAJ4T0', + name: 'jay', + is_restricted: false, + is_ultra_restricted: false }, + type: 'message', + subtype: 'group_name', + team: 'T9SAAJ4T0', + text: '<@UG11EP7HU> has renamed the channel from "private_j" to "private_jc"', + channel: 'GGM5P2ZE2', + event_ts: '1551376250.000800', + ts: '1551376250.000800' } +irchannel: undefined +slack_out conversations.info { channel: 'GGM5P2ZE2' } +slack_out conversations.info { channel: 'GGM5P2ZE2' } +slack_out conversations.members { channel: 'GGM5P2ZE2', limit: 1000 } +irc_out :jay JOIN #private_jc +irc_out :irslackd 353 jay = #private_jc :+jay +jay +slack_out conversations.members { channel: 'GGM5P2ZE2', limit: 1000 } +irc_out :jay JOIN #private_jc +irc_out :irslackd 353 jay = #private_jc :+jay +jay +irc_out :jay PRIVMSG #private_jc :@jay has renamed the channel from "private_j" to "private_jc" \ No newline at end of file diff --git a/rename_public.log b/rename_public.log new file mode 100644 index 0000000..a31df3b --- /dev/null +++ b/rename_public.log @@ -0,0 +1,51 @@ +slack_in channel_rename { type: 'channel_rename', + channel: + { id: 'CG3N357T6', + is_channel: true, + name: 'renamed_public', + name_normalized: 'renamed_public', + created: 1549908891 }, + event_ts: '1551375819.000400' } +irchannel: #newjaytest +irc_out :jay PART #newjaytest +slack_out conversations.info { channel: 'CG3N357T6' } +slack_in message { user: 'UG11EP7HU', + old_name: 'newjaytest', + name: 'renamed_public', + user_profile: + { avatar_hash: 'g9e4ba3d4e92', + image_72: 'https://secure.gravatar.com/avatar/9e4ba3d4e9251f076028e1d909b00535.jpg?s=72&d=https%3A%2F%2Fcfr.slack-edge.com%2F00b63%2Fimg%2Favatars%2Fava_0018-72.png', + first_name: '', + real_name: 'Jay Colson', + display_name: 'Jay', + team: 'T9SAAJ4T0', + name: 'jay', + is_restricted: false, + is_ultra_restricted: false }, + type: 'message', + subtype: 'channel_name', + team: 'T9SAAJ4T0', + text: '<@UG11EP7HU> has renamed the channel from "newjaytest" to "renamed_public"', + channel: 'CG3N357T6', + event_ts: '1551375819.000100', + ts: '1551375819.000100' } +irchannel: undefined +slack_out conversations.info { channel: 'CG3N357T6' } +slack_out conversations.members { channel: 'CG3N357T6', limit: 1000 } +slack_out conversations.info { channel: 'CG3N357T6' } +slack_in channel_marked { type: 'channel_marked', + channel: 'CG3N357T6', + ts: '1551375879.000000', + unread_count: 0, + unread_count_display: 0, + num_mentions: 0, + num_mentions_display: 0, + mention_count: 0, + mention_count_display: 0, + event_ts: '1551375819.000900' } +irc_out :jay JOIN #renamed_public +irc_out :irslackd 353 jay = #renamed_public :+jay as +jay +slack_out conversations.members { channel: 'CG3N357T6', limit: 1000 } +irc_out :jay JOIN #renamed_public +irc_out :irslackd 353 jay = #renamed_public :+jay as +jay +irc_out :jay PRIVMSG #renamed_public :@jay has renamed the channel from "newjaytest" to "renamed_public" \ No newline at end of file From ae9394e0ee59ab9143724160bbbf198a2464d82b Mon Sep 17 00:00:00 2001 From: Jay Colson Date: Thu, 28 Feb 2019 18:29:20 +0000 Subject: [PATCH 3/5] added subtype group_name and groups.mark call --- lib/irslackd.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/irslackd.js b/lib/irslackd.js index e9871cf..7939602 100644 --- a/lib/irslackd.js +++ b/lib/irslackd.js @@ -710,12 +710,19 @@ class Irslackd { }); }); // move timestamp an hour ahead - var timestamp = Math.round((new Date().getTime() / 1000) + 60); + var timestamp = Math.round((new Date().getTime() / 1000) + (60 * 60)); if (self.config.mark) { - await ircUser.slackWeb.paginateCallOrThrow('channels.mark', 'ok', { - channel: event.channel, - ts: timestamp, - }); + if (event.subtype === 'channel_name') { + await ircUser.slackWeb.paginateCallOrThrow('channels.mark', 'ok', { + channel: event.channel, + ts: timestamp, + }); + } else if (event.subtype === 'group_name') { + await ircUser.slackWeb.paginateCallOrThrow('groups.mark', 'ok', { + channel: event.channel, + ts: timestamp, + }); + } } } async onSlackTopicChange(ircUser, event) { From d64aa1d58177fc3d02e5af7b1c9c31b4fd56f2ce Mon Sep 17 00:00:00 2001 From: Jay Colson Date: Sat, 2 Mar 2019 20:22:05 +0000 Subject: [PATCH 4/5] fixed being able to /part private channels ... especially when you're the last one in them (needed a call to conversations.archive in the case that last_member error is thrown) --- lib/irslackd.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/irslackd.js b/lib/irslackd.js index 7939602..67132a0 100644 --- a/lib/irslackd.js +++ b/lib/irslackd.js @@ -245,10 +245,20 @@ class Irslackd { } // Leave Slack channel - let apiMethod = slackChan.substr(0, 1) === 'G' ? 'mpim.close' : 'conversations.leave'; - await ircUser.slackWeb.apiCallOrThrow(apiMethod, { - channel: slackChan, - }); + // let apiMethod = slackChan.substr(0, 1) === 'G' ? 'mpim.close' : 'conversations.leave'; + try { + await ircUser.slackWeb.apiCallOrThrow('conversations.leave', { + channel: slackChan, + }); + } catch (e) { + if (JSON.parse(e.message).error.data.error === 'last_member') { + await ircUser.slackWeb.apiCallOrThrow('conversations.archive', { + channel: slackChan, + }); + } else { + throw e; + } + } // Unset channel marker and leave IRC channel this.sendIrcChannelPart(ircUser, ircChan); From 062101f2961127fa2c42e424529c09ad9b0b4098 Mon Sep 17 00:00:00 2001 From: Jay Colson Date: Sat, 2 Mar 2019 20:49:41 +0000 Subject: [PATCH 5/5] make sure exception data is json and not undefined for the leaving of slack channel --- lib/irslackd.js | 2 +- rename_private_mod.log | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/irslackd.js b/lib/irslackd.js index 67132a0..9c77664 100644 --- a/lib/irslackd.js +++ b/lib/irslackd.js @@ -251,7 +251,7 @@ class Irslackd { channel: slackChan, }); } catch (e) { - if (JSON.parse(e.message).error.data.error === 'last_member') { + if (typeof JSON.parse(e.message) !== 'undefined' && JSON.parse(e.message).error.data.error === 'last_member') { await ircUser.slackWeb.apiCallOrThrow('conversations.archive', { channel: slackChan, }); diff --git a/rename_private_mod.log b/rename_private_mod.log index 3990aa8..57d20d9 100644 --- a/rename_private_mod.log +++ b/rename_private_mod.log @@ -1,4 +1,3 @@ -slack_in pong { type: 'pong', reply_to: 42 } slack_in group_rename { type: 'group_rename', channel: { id: 'GGM5P2ZE2',