1
0
Fork 0

streamline the convertNameAndTopic function

This commit is contained in:
Cadence Ember 2023-07-05 12:04:28 +12:00
parent bd32fe6c6d
commit 9569fda168

View file

@ -37,25 +37,17 @@ function applyKStateDiffToRoom(roomID, kstate) {
* @param {string?} customName * @param {string?} customName
*/ */
function convertNameAndTopic(channel, guild, customName) { function convertNameAndTopic(channel, guild, customName) {
// TODO: Improve nasty nested ifs const convertedName = customName || channel.name;
let convertedName, convertedTopic const maybeTopicWithPipe = channel.topic ? ` | ${channel.topic}` : '';
if (customName) { const maybeTopicWithNewlines = channel.topic ? `${channel.topic}\n\n` : '';
convertedName = customName const channelIDPart = `Channel ID: ${channel.id}`;
if (channel.topic) { const guildIDPart = `Guild ID: ${guild.id}`;
convertedTopic = `#${channel.name} | ${channel.topic}\n\nChannel ID: ${channel.id}\nGuild ID: ${guild.id}`
} else {
convertedTopic = `#${channel.name}\n\nChannel ID: ${channel.id}\nGuild ID: ${guild.id}`
}
} else {
convertedName = channel.name
if (channel.topic) {
convertedTopic = `${channel.topic}\n\nChannel ID: ${channel.id}\nGuild ID: ${guild.id}`
} else {
convertedTopic = `Channel ID: ${channel.id}\nGuild ID: ${guild.id}`
}
}
return [convertedName, convertedTopic] const convertedTopic = customName
? `#${channel.name}${maybeTopicWithPipe}\n\n${channelIDPart}\n${guildIDPart}`
: `${maybeTopicWithNewlines}${channelIDPart}\n${guildIDPart}`;
return [convertedName, convertedTopic];
} }
/** /**