Fully functioning built-in plugin to send system messages on join/leave (#437)

Co-authored-by: Miikka <2606411+Dragory@users.noreply.github.com>
cshd
Nils 2020-09-22 23:19:34 +02:00 committed by GitHub
parent 3af5a67c1b
commit 96e8eae188
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 1 deletions

View File

@ -313,6 +313,14 @@ URL to use for attachment and log links. Defaults to `http://IP:PORT`.
**Default:** `off`
If enabled, mod replies will use their nicknames (on the inbox server) instead of their usernames
#### notifyOnMainServerLeave
**Default:** `on`
If enabled, a system message will be posted into any open threads if the user leaves a main server
#### notifyOnMainServerJoin
**Default:** `on`
If enabled, a system message will be posted into any open threads if the user joins a main server
#### anonymizeChannelName
**Default:** `off`
If enabled, channel names will be the user's name and discriminator salted with the current time, then hashed to protect the user's privacy

View File

@ -51,6 +51,8 @@
* @property {boolean} [reactOnSeen=false]
* @property {string} [reactOnSeenEmoji="📨"]
* @property {boolean} [createThreadOnMention=false]
* @property {boolean} [notifyOnMainServerLeave=true]
* @property {boolean} [notifyOnMainServerJoin=true]
* @property {number} [port=8890]
* @property {string} [url]
* @property {array} [extraIntents=[]]

View File

@ -296,6 +296,16 @@
"default": false
},
"notifyOnMainServerLeave": {
"$ref": "#/definitions/customBoolean",
"default": true
},
"notifyOnMainServerJoin": {
"$ref": "#/definitions/customBoolean",
"default": true
},
"port": {
"type": "number",
"maximum": 65535,

View File

@ -28,6 +28,7 @@ const version = require("./modules/version");
const newthread = require("./modules/newthread");
const idModule = require("./modules/id");
const alert = require("./modules/alert");
const joinLeaveNotification = require("./modules/joinLeaveNotification");
const {ACCIDENTAL_THREAD_MESSAGES} = require("./data/constants");
@ -304,7 +305,8 @@ async function initPlugins() {
version,
newthread,
idModule,
alert
alert,
joinLeaveNotification
];
const plugins = [...builtInPlugins];

View File

@ -0,0 +1,31 @@
const config = require("../cfg");
const threads = require("../data/threads");
const utils = require("../utils");
module.exports = ({ bot }) => {
// Join Notification: Post a message in the thread if the user joins a main server
if (config.notifyOnMainServerJoin) {
bot.on("guildMemberAdd", async (guild, member) => {
const mainGuilds = utils.getMainGuilds();
if (! mainGuilds.find(gld => gld.id === guild.id)) return;
const thread = await threads.findOpenThreadByUserId(member.id);
if (thread != null) {
await thread.postSystemMessage(`***The user joined the guild ${guild.name}.***`);
}
});
}
// Leave Notification: Post a message in the thread if the user leaves a main server
if (config.notifyOnMainServerLeave) {
bot.on("guildMemberRemove", async (guild, member) => {
const mainGuilds = utils.getMainGuilds();
if (! mainGuilds.find(gld => gld.id === guild.id)) return;
const thread = await threads.findOpenThreadByUserId(member.id);
if (thread != null) {
await thread.postSystemMessage(`***The user left the guild ${guild.name}.***`);
}
});
}
};