Merge JonasPardon-master

master
Dragory 2018-07-27 19:43:54 +03:00
commit 4a1f3b0bd5
4 changed files with 21 additions and 1 deletions

View File

@ -84,4 +84,9 @@ These go in `config.json`. See also `config.example.json`.
|typingProxy|false|If enabled, any time a user is typing to modmail in their DMs, the modmail thread will show the bot as "typing"| |typingProxy|false|If enabled, any time a user is typing to modmail in their DMs, the modmail thread will show the bot as "typing"|
|typingProxyReverse|false|If enabled, any time a moderator is typing in a modmail thread, the user will see the bot "typing" in their DMs| |typingProxyReverse|false|If enabled, any time a moderator is typing in a modmail thread, the user will see the bot "typing" in their DMs|
|mentionRole|"here"|Role that is mentioned when new threads are created or the bot is mentioned. Accepted values are "here", "everyone", or a role id as a string. Set to null to disable these pings entirely.| |mentionRole|"here"|Role that is mentioned when new threads are created or the bot is mentioned. Accepted values are "here", "everyone", or a role id as a string. Set to null to disable these pings entirely.|
<<<<<<< HEAD
|pingOnBotMention|true|If enabled, the bot will mention staff (see mentionRole above) on the inbox server when the bot is mentioned on the main server.| |pingOnBotMention|true|If enabled, the bot will mention staff (see mentionRole above) on the inbox server when the bot is mentioned on the main server.|
=======
|userOlderThan|null|The amount of days the user's account has to exist. If the user's account is not old enough, the bot will not make a new thread and reply to the user with the message defined in `userDeniedMessage`.|
|userDeniedMessage|"Your Discord account is not old enough to contact modmail."|The message to reply to a user when their account is not old enough to contact modmail.|
>>>>>>> 9c1a5863f52d51a40e480efcdbd2275a7e3b4978

View File

@ -65,6 +65,9 @@ const defaultConfig = {
"greetingMessage": null, "greetingMessage": null,
"greetingAttachment": null, "greetingAttachment": null,
"userOlderThan": null, // Amount of days
"userDeniedMessage": "Your Discord account is not old enough to contact modmail.",
"relaySmallAttachmentsAsAttachments": false, "relaySmallAttachmentsAsAttachments": false,
"port": 8890, "port": 8890,

View File

@ -56,6 +56,18 @@ async function createNewThreadForUser(user, quiet = false) {
throw new Error('Attempted to create a new thread for a user with an existing open thread!'); throw new Error('Attempted to create a new thread for a user with an existing open thread!');
} }
// Check the config for a requirement of account age to contact modmail,
// if the account is too young, return an optional message without making a new thread
if (config.userOlderThan) {
if (user.createdAt > moment() - config.userOlderThan * 86400000){
if (config.userDeniedMessage) {
const privateChannel = await user.getDMChannel();
await privateChannel.createMessage(config.userDeniedMessage);
}
return;
}
}
// Use the user's name+discrim for the thread channel's name // Use the user's name+discrim for the thread channel's name
// Channel names are particularly picky about what characters they allow, so we gotta do some clean-up // Channel names are particularly picky about what characters they allow, so we gotta do some clean-up
let cleanName = transliterate.slugify(user.username); let cleanName = transliterate.slugify(user.username);

View File

@ -86,7 +86,7 @@ bot.on('messageCreate', async msg => {
thread = await threads.createNewThreadForUser(msg.author); thread = await threads.createNewThreadForUser(msg.author);
} }
await thread.receiveUserReply(msg); if (thread) await thread.receiveUserReply(msg);
}); });
}); });