Fix missing here ping on new threads. Add threadTimestamps option to revert removal of thread timestamps.

master
Dragory 2018-02-18 23:29:24 +02:00
parent 92ac21aa33
commit adce3e0cbb
5 changed files with 27 additions and 11 deletions

View File

@ -67,3 +67,4 @@ These go in `config.json`. See also `config.example.json`.
|logChannelId|Server's default channel|Channel where to post links to closed threads and other alerts|
|newThreadCategoryId|None|ID of the category where new modmail thread channels should be placed|
|relaySmallAttachmentsAsAttachments|false|Whether to relay small (<2MB) attachments from users as attachments rather than links in modmail threads|
|threadTimestamps|false|Whether to show custom timestamps in threads, in addition to Discord's own timestamps. Logs always have accurate timestamps, regardless of this setting.|

View File

@ -27,6 +27,7 @@ const defaultConfig = {
"alwaysReplyAnon": false,
"useNicknames": false,
"ignoreAccidentalThreads": false,
"threadTimestamps": false,
"enableGreeting": false,
"greetingMessage": null,

View File

@ -47,14 +47,18 @@ class Thread {
}
// Build the reply message
const timestamp = utils.getTimestamp();
let dmContent = `**${modUsername}:** ${text}`;
let threadContent = `**${logModUsername}:** ${text}`;
let logContent = text;
let files = [];
if (config.threadTimestamps) {
const timestamp = utils.getTimestamp();
threadContent = `[${timestamp}] » ${threadContent}`;
}
// Prepare attachments, if any
let files = [];
if (replyAttachments.length > 0) {
for (const attachment of replyAttachments) {
files.push(await attachments.attachmentToFile(attachment));
@ -99,6 +103,13 @@ class Thread {
let threadContent = `**${msg.author.username}#${msg.author.discriminator}:** ${content}`;
let logContent = msg.content;
if (config.threadTimestamps) {
const timestamp = utils.getTimestamp(msg.timestamp, 'x');
threadContent = `[${timestamp}] « ${threadContent}`;
}
// Prepare attachments, if any
let attachmentFiles = [];
for (const attachment of msg.attachments) {
@ -145,13 +156,11 @@ class Thread {
}
/**
* @param {String} text
* @param {Eris~MessageFile|Eris~MessageFile[]} file
* @returns {Promise<Eris~Message>}
*/
async postToThreadChannel(text, file = null) {
async postToThreadChannel(...args) {
try {
return await bot.createMessage(this.channel_id, text, file);
return await bot.createMessage(this.channel_id, ...args);
} catch (e) {
// Channel not found
if (e.code === 10003) {
@ -183,8 +192,8 @@ class Thread {
* @param {String} text
* @returns {Promise<void>}
*/
async postNonLogMessage(text) {
await this.postToThreadChannel(text);
async postNonLogMessage(...args) {
await this.postToThreadChannel(...args);
}
/**

View File

@ -79,6 +79,12 @@ async function createNewThreadForUser(user) {
const newThread = await findById(newThreadId);
// Ping moderators of the new thread
await newThread.postNonLogMessage({
content: `@here New modmail thread (${newThread.user_name})`,
disableEveryone: false
});
// Post the log link to the beginning (but don't save it in thread messages)
const logUrl = await newThread.getLogUrl();
await newThread.postNonLogMessage(`Log URL: <${logUrl}>`);

View File

@ -128,11 +128,10 @@ function getUserMention(str) {
/**
* Returns the current timestamp in an easily readable form
* @param {String|Date|undefined} date
* @returns {String}
*/
function getTimestamp(date) {
return moment.utc(date).format('HH:mm');
function getTimestamp(...momentArgs) {
return moment.utc(...momentArgs).format('HH:mm');
}
/**