Fully functioning built-in plugin to send system messages on join/leave (#437)
Co-authored-by: Miikka <2606411+Dragory@users.noreply.github.com>cshd
parent
3af5a67c1b
commit
96e8eae188
|
@ -313,6 +313,14 @@ URL to use for attachment and log links. Defaults to `http://IP:PORT`.
|
||||||
**Default:** `off`
|
**Default:** `off`
|
||||||
If enabled, mod replies will use their nicknames (on the inbox server) instead of their usernames
|
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
|
#### anonymizeChannelName
|
||||||
**Default:** `off`
|
**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
|
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
|
||||||
|
|
|
@ -51,6 +51,8 @@
|
||||||
* @property {boolean} [reactOnSeen=false]
|
* @property {boolean} [reactOnSeen=false]
|
||||||
* @property {string} [reactOnSeenEmoji="📨"]
|
* @property {string} [reactOnSeenEmoji="📨"]
|
||||||
* @property {boolean} [createThreadOnMention=false]
|
* @property {boolean} [createThreadOnMention=false]
|
||||||
|
* @property {boolean} [notifyOnMainServerLeave=true]
|
||||||
|
* @property {boolean} [notifyOnMainServerJoin=true]
|
||||||
* @property {number} [port=8890]
|
* @property {number} [port=8890]
|
||||||
* @property {string} [url]
|
* @property {string} [url]
|
||||||
* @property {array} [extraIntents=[]]
|
* @property {array} [extraIntents=[]]
|
||||||
|
|
|
@ -296,6 +296,16 @@
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"notifyOnMainServerLeave": {
|
||||||
|
"$ref": "#/definitions/customBoolean",
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
|
||||||
|
"notifyOnMainServerJoin": {
|
||||||
|
"$ref": "#/definitions/customBoolean",
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
|
||||||
"port": {
|
"port": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"maximum": 65535,
|
"maximum": 65535,
|
||||||
|
|
|
@ -28,6 +28,7 @@ const version = require("./modules/version");
|
||||||
const newthread = require("./modules/newthread");
|
const newthread = require("./modules/newthread");
|
||||||
const idModule = require("./modules/id");
|
const idModule = require("./modules/id");
|
||||||
const alert = require("./modules/alert");
|
const alert = require("./modules/alert");
|
||||||
|
const joinLeaveNotification = require("./modules/joinLeaveNotification");
|
||||||
|
|
||||||
const {ACCIDENTAL_THREAD_MESSAGES} = require("./data/constants");
|
const {ACCIDENTAL_THREAD_MESSAGES} = require("./data/constants");
|
||||||
|
|
||||||
|
@ -304,7 +305,8 @@ async function initPlugins() {
|
||||||
version,
|
version,
|
||||||
newthread,
|
newthread,
|
||||||
idModule,
|
idModule,
|
||||||
alert
|
alert,
|
||||||
|
joinLeaveNotification
|
||||||
];
|
];
|
||||||
|
|
||||||
const plugins = [...builtInPlugins];
|
const plugins = [...builtInPlugins];
|
||||||
|
|
|
@ -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}.***`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue