Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 65 additions & 10 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,65 @@ const removeEscapeSequences = (text) => {

let core = {};

let resolveChannelName = (channelId) => {
let channel = util.channels[channelId];

if (!channel) {
return null;
}

if (channel.is_im && channel.user) {
let dmUser = util.users[channel.user];
return (dmUser && dmUser.name) ? dmUser.name : channel.user;
}

if (channel.name) {
return channel.name;
}

return channelId;
};

let resolveChannelLabelDisplay = (channelId) => {
let channel = util.channels[channelId];

if (!channel) {
return chalk.white(channelId || "-");
}

let name = resolveChannelName(channelId);

if (channel.is_im && channel.user) {
return "@" + chalk[channel.color](name);
}

if (channel.name) {
return "#" + chalk[channel.color](name);
}

return chalk.white(name || "-");
};

let resolveChannelLabelKey = (channelId) => {
let channel = util.channels[channelId];

if (!channel) {
return "-";
}

let name = resolveChannelName(channelId);

if (channel.is_im && channel.user) {
return "@" + name;
}

if (channel.name) {
return "#" + name;
}

return name || "-";
};

core.display = (data, options) => {
let name, channel;

Expand All @@ -56,14 +115,10 @@ core.display = (data, options) => {
}
}

if (util.channels[data.channel]) {
channel = "#" + chalk[util.channels[data.channel].color](util.channels[data.channel].name);
if (typeof data.channel == "string") {
channel = resolveChannelLabelDisplay(data.channel);
} else {
if (typeof data.channel == "string") {
channel = chalk.white(data.channel);
} else {
channel = chalk.white("-");
}
channel = chalk.white("-");
}

data.lines.forEach((line) => {
Expand Down Expand Up @@ -330,7 +385,7 @@ core.start = async (commander) => {

// buffering
let data = {
bufferKey: (util.channels[message.channel]) ? "#" + util.channels[message.channel].name : "-",
bufferKey: (typeof message.channel == "string") ? resolveChannelLabelKey(message.channel) : "-",
lines: lines,
time: time,
channel: message.channel,
Expand Down Expand Up @@ -369,7 +424,7 @@ core.start = async (commander) => {

let response = await web.conversations.list({
limit:1000,
types: "public_channel,private_channel"
types: "public_channel,private_channel,im,mpim"
});

response.channels.forEach((v, i) => {
Expand All @@ -380,7 +435,7 @@ core.start = async (commander) => {
while(response.response_metadata.next_cursor != "") {
response = await web.conversations.list({
limit: 1000,
types: "public_channel,private_channel",
types: "public_channel,private_channel,im,mpim",
cursor: response.response_metadata.next_cursor
});

Expand Down