Allow using thread number in !log

cshd
Dragory 2020-11-01 21:45:06 +02:00
parent 280fad36f7
commit 02daa367f8
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
2 changed files with 17 additions and 4 deletions

View File

@ -43,6 +43,18 @@ async function findById(id) {
return (thread ? new Thread(thread) : null); return (thread ? new Thread(thread) : null);
} }
/**
* @param {number} threadNumber
* @returns {Promise<Thread>}
*/
async function findByThreadNumber(threadNumber) {
const thread = await knex("threads")
.where("thread_number", threadNumber)
.first();
return (thread ? new Thread(thread) : null);
}
/** /**
* @param {String} userId * @param {String} userId
* @returns {Promise<Thread>} * @returns {Promise<Thread>}
@ -408,6 +420,7 @@ async function getThreadsThatShouldBeSuspended() {
module.exports = { module.exports = {
findById, findById,
findByThreadNumber,
findOpenThreadByUserId, findOpenThreadByUserId,
findByChannelId, findByChannelId,
findOpenThreadByChannelId, findOpenThreadByChannelId,

View File

@ -46,7 +46,7 @@ module.exports = ({ bot, knex, config, commands, hooks }) => {
const logUrl = await getLogUrl(thread); const logUrl = await getLogUrl(thread);
const formattedLogUrl = logUrl const formattedLogUrl = logUrl
? `<${addOptQueryStringToUrl(logUrl, args)}>` ? `<${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]"); const formattedDate = moment.utc(thread.created_at).format("MMM Do [at] HH:mm [UTC]");
return `\`#${thread.thread_number}\` \`${formattedDate}\`: ${formattedLogUrl}`; return `\`#${thread.thread_number}\` \`${formattedDate}\`: ${formattedLogUrl}`;
})); }));
@ -75,7 +75,7 @@ module.exports = ({ bot, knex, config, commands, hooks }) => {
const threadId = args.threadId || (_thread && _thread.id); const threadId = args.threadId || (_thread && _thread.id);
if (! threadId) return; if (! threadId) return;
const thread = await threads.findById(threadId); const thread = (await threads.findById(threadId)) || (await threads.findByThreadNumber(threadId));
if (! thread) return; if (! thread) return;
const customResponse = await getLogCustomResponse(thread); const customResponse = await getLogCustomResponse(thread);
@ -85,13 +85,13 @@ module.exports = ({ bot, knex, config, commands, hooks }) => {
const logUrl = await getLogUrl(thread); const logUrl = await getLogUrl(thread);
if (logUrl) { 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; return;
} }
const logFile = await getLogFile(thread); const logFile = await getLogFile(thread);
if (logFile) { 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; return;
} }