forked from cadence/out-of-your-element
Move to util
This commit is contained in:
parent
9a33ba3ed2
commit
cf39737b5a
2 changed files with 22 additions and 11 deletions
|
@ -491,19 +491,11 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
} else { // repliedToUnknownEvent
|
} else { // repliedToUnknownEvent
|
||||||
// This reply can't point to the Matrix event because it isn't bridged, we need to indicate this.
|
// This reply can't point to the Matrix event because it isn't bridged, we need to indicate this.
|
||||||
assert(message.referenced_message)
|
assert(message.referenced_message)
|
||||||
const dateDifference = new Date(message.timestamp).getTime() - new Date(message.referenced_message.timestamp).getTime()
|
const dateDisplay = dUtils.howOldUnbridgedMessage(message.referenced_message.timestamp, message.timestamp)
|
||||||
const oneHour = 60 * 60 * 1000
|
html = `<blockquote>In reply to ${dateDisplay} from ${repliedToDisplayName}:`
|
||||||
if (dateDifference < oneHour) {
|
|
||||||
var dateDisplay = "n"
|
|
||||||
} else if (dateDifference < 25 * oneHour) {
|
|
||||||
var dateDisplay = ` ${Math.floor(dateDifference / oneHour)}-hour-old`
|
|
||||||
} else {
|
|
||||||
var dateDisplay = ` ${Math.round(dateDifference / (24 * oneHour))}-day-old`
|
|
||||||
}
|
|
||||||
html = `<blockquote>In reply to a${dateDisplay} unbridged message from ${repliedToDisplayName}:`
|
|
||||||
+ `<br>${repliedToHtml}</blockquote>`
|
+ `<br>${repliedToHtml}</blockquote>`
|
||||||
+ html
|
+ html
|
||||||
body = (`In reply to a${dateDisplay} unbridged message:\n${repliedToDisplayName}: `
|
body = (`In reply to ${dateDisplay}:\n${repliedToDisplayName}: `
|
||||||
+ repliedToBody).split("\n").map(line => "> " + line).join("\n")
|
+ repliedToBody).split("\n").map(line => "> " + line).join("\n")
|
||||||
+ "\n\n" + body
|
+ "\n\n" + body
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,6 +136,24 @@ function getPublicUrlForCdn(url) {
|
||||||
return `${reg.ooye.bridge_origin}/download/discord${match[1]}/${match[2]}/${match[3]}/${match[4]}`
|
return `${reg.ooye.bridge_origin}/download/discord${match[1]}/${match[2]}/${match[3]}/${match[4]}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} oldTimestamp
|
||||||
|
* @param {string} newTimestamp
|
||||||
|
* @returns {string} "a x-day-old unbridged message"
|
||||||
|
*/
|
||||||
|
function howOldUnbridgedMessage(oldTimestamp, newTimestamp) {
|
||||||
|
const dateDifference = new Date(newTimestamp).getTime() - new Date(oldTimestamp).getTime()
|
||||||
|
const oneHour = 60 * 60 * 1000
|
||||||
|
if (dateDifference < oneHour) {
|
||||||
|
return "an unbridged message"
|
||||||
|
} else if (dateDifference < 25 * oneHour) {
|
||||||
|
var dateDisplay = `a ${Math.floor(dateDifference / oneHour)}-hour-old unbridged message`
|
||||||
|
} else {
|
||||||
|
var dateDisplay = `a ${Math.round(dateDifference / (24 * oneHour))}-day-old unbridged message`
|
||||||
|
}
|
||||||
|
return dateDisplay
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.getPermissions = getPermissions
|
module.exports.getPermissions = getPermissions
|
||||||
module.exports.hasPermission = hasPermission
|
module.exports.hasPermission = hasPermission
|
||||||
module.exports.hasSomePermissions = hasSomePermissions
|
module.exports.hasSomePermissions = hasSomePermissions
|
||||||
|
@ -145,3 +163,4 @@ module.exports.isEphemeralMessage = isEphemeralMessage
|
||||||
module.exports.snowflakeToTimestampExact = snowflakeToTimestampExact
|
module.exports.snowflakeToTimestampExact = snowflakeToTimestampExact
|
||||||
module.exports.timestampToSnowflakeInexact = timestampToSnowflakeInexact
|
module.exports.timestampToSnowflakeInexact = timestampToSnowflakeInexact
|
||||||
module.exports.getPublicUrlForCdn = getPublicUrlForCdn
|
module.exports.getPublicUrlForCdn = getPublicUrlForCdn
|
||||||
|
module.exports.howOldUnbridgedMessage = howOldUnbridgedMessage
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue