send welcome message when added to server

This commit is contained in:
janderedev 2022-01-05 23:20:19 +01:00
parent 426d5f6259
commit 205a93dfb2
Signed by: Lea
GPG key ID: 5D5E18ACB990F57A

View file

@ -2,14 +2,16 @@ import { ulid } from "ulid";
import { client } from "../..";
import Infraction from "../../struct/antispam/Infraction";
import InfractionType from "../../struct/antispam/InfractionType";
import { storeInfraction } from "../util";
import logger from "../logger";
import { hasPermForChannel, storeInfraction } from "../util";
import { DEFAULT_PREFIX } from "./command_handler";
// Listen to system messages
client.on('message', async message => {
if (typeof message.content != 'object') return;
let sysMsg = message.asSystemMessage;
switch(sysMsg.type) {
case 'user_kicked':
case 'user_banned':
@ -41,3 +43,38 @@ client.on('message', async message => {
case 'user_left' : break;
}
});
// Send a message when added to a server
client.on('member/join', (member) => {
if (member._id.user != client.user?._id) return;
let url = `https://rvembed.janderedev.xyz/embed`
+ `?title=${encodeURIComponent('Hi there, thanks for adding me!')}`
+ `&description=${encodeURIComponent(`My prefix is "${DEFAULT_PREFIX}", `
+ `but you can also @mention me instead.\nCheck out ${DEFAULT_PREFIX}help to get started!`)}`
+ `&link=${encodeURIComponent(`/bot/${client.user._id}`)}`
+ `&redir=${encodeURIComponent(`https://github.com/janderedev/revolt-automod`)}`
+ `&color=${encodeURIComponent("#ff6e6d")}`
+ `&image=${encodeURIComponent(client.user.generateAvatarURL({ size: 128 }))}`
+ `&image_large=false`;
if (!member.server) return;
let channels = member.server.channels.filter(
c => c
&& c.channel_type == 'TextChannel'
&& hasPermForChannel(member, c, 'SendMessage')
&& hasPermForChannel(member, c, 'EmbedLinks')
);
// Attempt to find an appropriate channel, otherwise use the first one available
let channel = channels.find(c => c?.name?.toLowerCase() == 'welcome')
|| channels.find(c => c?.name?.toLowerCase() == 'general')
|| channels.find(c => c?.name?.toLowerCase() == 'bots')
|| channels.find(c => c?.name?.toLowerCase() == 'spam')
|| channels[0];
if (!channel) return logger.debug('Cannot send hello message: No suitable channel found');
channel.sendMessage(`[:wave:](${url} "Hi there!")`)
.catch(e => logger.debug('Cannot send hello message: ' + e));
});