diff --git a/src/data/threads.js b/src/data/threads.js index f53a9a1..fbefdb2 100644 --- a/src/data/threads.js +++ b/src/data/threads.js @@ -43,6 +43,18 @@ async function findById(id) { return (thread ? new Thread(thread) : null); } +/** + * @param {number} threadNumber + * @returns {Promise} + */ +async function findByThreadNumber(threadNumber) { + const thread = await knex("threads") + .where("thread_number", threadNumber) + .first(); + + return (thread ? new Thread(thread) : null); +} + /** * @param {String} userId * @returns {Promise} @@ -408,6 +420,7 @@ async function getThreadsThatShouldBeSuspended() { module.exports = { findById, + findByThreadNumber, findOpenThreadByUserId, findByChannelId, findOpenThreadByChannelId, diff --git a/src/modules/logs.js b/src/modules/logs.js index 9fa7757..928d3f2 100644 --- a/src/modules/logs.js +++ b/src/modules/logs.js @@ -46,7 +46,7 @@ module.exports = ({ bot, knex, config, commands, hooks }) => { const logUrl = await getLogUrl(thread); const formattedLogUrl = logUrl ? `<${addOptQueryStringToUrl(logUrl, args)}>` - : `View log with \`${config.prefix}log ${thread.id}\`` + : `View log with \`${config.prefix}log ${thread.thread_number}\`` const formattedDate = moment.utc(thread.created_at).format("MMM Do [at] HH:mm [UTC]"); return `\`#${thread.thread_number}\` \`${formattedDate}\`: ${formattedLogUrl}`; })); @@ -75,7 +75,7 @@ module.exports = ({ bot, knex, config, commands, hooks }) => { const threadId = args.threadId || (_thread && _thread.id); if (! threadId) return; - const thread = await threads.findById(threadId); + const thread = (await threads.findById(threadId)) || (await threads.findByThreadNumber(threadId)); if (! thread) return; const customResponse = await getLogCustomResponse(thread); @@ -85,13 +85,13 @@ module.exports = ({ bot, knex, config, commands, hooks }) => { const logUrl = await getLogUrl(thread); if (logUrl) { - msg.channel.createMessage(`Open the following link to view the log:\n<${addOptQueryStringToUrl(logUrl, args)}>`); + msg.channel.createMessage(`Open the following link to view the log for thread #${thread.thread_number}:\n<${addOptQueryStringToUrl(logUrl, args)}>`); return; } const logFile = await getLogFile(thread); if (logFile) { - msg.channel.createMessage("Download the following file to view the log:", logFile); + msg.channel.createMessage(`Download the following file to view the log for thread #${thread.thread_number}:`, logFile); return; }