Add guildGreetings config option
parent
1f370769ac
commit
18f3da1247
|
@ -79,6 +79,7 @@ These go in `config.json`. See also `config.example.json`.
|
|||
|enableGreeting|false|Set to true to send a welcome message to new main guild members. Requires `mainGuildId` to be set.|
|
||||
|greetingAttachment|None|Path to an image or other attachment to send along with the greeting|
|
||||
|greetingMessage|None|Text content of the welcome message|
|
||||
|guildGreetings|None|When using multiple mainGuildIds, this option allows you to configure greetings on a per-server basis. The syntax is an object with the guild ID as the key, and another object with `message` and `attachment` properties as the value (identical to greetingMessage and greetingAttachment)|
|
||||
|ignoreAccidentalThreads|false|If set to true, the bot attempts to ignore common "accidental" messages that would start a new thread, such as "ok", "thanks", etc.|
|
||||
|inboxServerPermission|None|Permission required to use bot commands on the inbox server|
|
||||
|timeOnServerDeniedMessage|"You haven't been a member of the server for long enough to contact modmail."|See `requiredTimeOnServer` below|
|
||||
|
|
|
@ -75,6 +75,8 @@ const defaultConfig = {
|
|||
"greetingMessage": null,
|
||||
"greetingAttachment": null,
|
||||
|
||||
"guildGreetings": {},
|
||||
|
||||
"requiredAccountAge": null, // In hours
|
||||
"accountAgeDeniedMessage": "Your Discord account is not old enough to contact modmail.",
|
||||
|
||||
|
@ -160,6 +162,20 @@ if (! Array.isArray(finalConfig['inboxServerPermission'])) {
|
|||
}
|
||||
}
|
||||
|
||||
// Move greetingMessage/greetingAttachment to the guildGreetings object internally
|
||||
// Or, in other words, if greetingMessage and/or greetingAttachment is set, it is applied for all servers that don't
|
||||
// already have something set up in guildGreetings. This retains backwards compatibility while allowing you to override
|
||||
// greetings for specific servers in guildGreetings.
|
||||
if (finalConfig.greetingMessage || finalConfig.greetingAttachment) {
|
||||
for (const guildId of finalConfig.mainGuildId) {
|
||||
if (finalConfig.guildGreetings[guildId]) continue;
|
||||
finalConfig.guildGreetings[guildId] = {
|
||||
message: finalConfig.greetingMessage,
|
||||
message: finalConfig.greetingMessage
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// newThreadCategoryId is syntactic sugar for categoryAutomation.newThread
|
||||
if (finalConfig.newThreadCategoryId) {
|
||||
finalConfig.categoryAutomation.newThread = finalConfig.newThreadCategoryId;
|
||||
|
|
|
@ -107,7 +107,7 @@ bot.on('messageUpdate', async (msg, oldMessage) => {
|
|||
if (msg.channel instanceof Eris.PrivateChannel) {
|
||||
const thread = await threads.findOpenThreadByUserId(msg.author.id);
|
||||
if (! thread) return;
|
||||
|
||||
|
||||
const editMessage = utils.disableLinkPreviews(`**The user edited their message:**\n\`B:\` ${oldContent}\n\`A:\` ${newContent}`);
|
||||
thread.postSystemMessage(editMessage);
|
||||
}
|
||||
|
|
|
@ -5,16 +5,15 @@ const config = require('../config');
|
|||
module.exports = bot => {
|
||||
if (! config.enableGreeting) return;
|
||||
|
||||
const greetingGuilds = config.mainGuildId;
|
||||
|
||||
bot.on('guildMemberAdd', (guild, member) => {
|
||||
if (! greetingGuilds.includes(guild.id)) return;
|
||||
const guildGreeting = config.guildGreetings[guild.id];
|
||||
if (! guildGreeting || (! guildGreeting.message && ! guildGreeting.attachment)) return;
|
||||
|
||||
function sendGreeting(file) {
|
||||
function sendGreeting(message, file) {
|
||||
bot.getDMChannel(member.id).then(channel => {
|
||||
if (! channel) return;
|
||||
|
||||
channel.createMessage(config.greetingMessage || '', file)
|
||||
channel.createMessage(message || '', file)
|
||||
.catch(e => {
|
||||
if (e.code === 50007) return;
|
||||
throw e;
|
||||
|
@ -22,14 +21,14 @@ module.exports = bot => {
|
|||
});
|
||||
}
|
||||
|
||||
if (config.greetingAttachment) {
|
||||
const filename = path.basename(config.greetingAttachment);
|
||||
fs.readFile(config.greetingAttachment, (err, data) => {
|
||||
if (guildGreeting.attachment) {
|
||||
const filename = path.basename(guildGreeting.attachment);
|
||||
fs.readFile(guildGreeting.attachment, (err, data) => {
|
||||
const file = {file: data, name: filename};
|
||||
sendGreeting(file);
|
||||
sendGreeting(guildGreeting.message, file);
|
||||
});
|
||||
} else {
|
||||
sendGreeting();
|
||||
sendGreeting(guildGreeting.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue