Skip to content

Commit

Permalink
Merge branch 'bug-slack-channel_archive' into bleading
Browse files Browse the repository at this point in the history
* bug-slack-channel_archive:
  make sure exception data is json and not undefined for the leaving of slack channel
  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)
  added subtype group_name and groups.mark call
  WIP rename issue adsr#68
  working on channel_archive and channel_deleted
  • Loading branch information
jcolson committed Mar 3, 2019
2 parents 610f09b + 062101f commit 4a583c7
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 9 deletions.
42 changes: 42 additions & 0 deletions irslackd-bug.log
Original file line number Diff line number Diff line change
@@ -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 <anonymous>
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 <anonymous>
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

51 changes: 42 additions & 9 deletions lib/irslackd.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ 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)],
['member_joined_channel', self.makeSlackHandler(self.onSlackMemberJoinedChannel)],
['member_left_channel', self.makeSlackHandler(self.onSlackMemberLeftChannel)],
['mpim_open', self.makeSlackHandler(self.onSlackMpimOpen)],
Expand Down Expand Up @@ -242,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 (typeof JSON.parse(e.message) !== 'undefined' && 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);
Expand Down Expand Up @@ -707,12 +720,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) {
Expand Down Expand Up @@ -740,6 +760,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;
Expand Down Expand Up @@ -999,6 +1031,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
Expand Down
31 changes: 31 additions & 0 deletions rename_private.log
Original file line number Diff line number Diff line change
@@ -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"
42 changes: 42 additions & 0 deletions rename_private_mod.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,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"
51 changes: 51 additions & 0 deletions rename_public.log
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 4a583c7

Please sign in to comment.