1 |
|
/** |
2 |
|
* This file is part of SudoBot. |
3 |
|
* |
4 |
|
* Copyright (C) 2021-2022 OSN Inc. |
5 |
|
* |
6 |
|
* SudoBot is free software; you can redistribute it and/or modify it |
7 |
|
* under the terms of the GNU Affero General Public License as published by |
8 |
|
* the Free Software Foundation, either version 3 of the License, or |
9 |
|
* (at your option) any later version. |
10 |
|
* |
11 |
|
* SudoBot is distributed in the hope that it will be useful, but |
12 |
|
* WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
* GNU Affero General Public License for more details. |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU Affero General Public License |
17 |
|
* along with SudoBot. If not, see <https://www.gnu.org/licenses/>. |
18 |
|
*/ |
19 |
|
|
20 |
import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; |
import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; |
|
import DiscordClient from "../client/Client"; |
|
21 |
import fs from 'fs'; |
import fs from 'fs'; |
22 |
import path from "path"; |
import path from "path"; |
23 |
import Service from "../utils/structures/Service"; |
import Service from "../utils/structures/Service"; |
24 |
|
|
25 |
export default class Welcomer extends Service { |
export default class Welcomer extends Service { |
26 |
messages: string[] = JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', '..', 'resources', 'welcome_messages.json')).toString()); |
messages: string[] = JSON.parse(fs.readFileSync(path.resolve(process.env.SUDO_PREFIX ?? path.join(__dirname, '..', '..'), 'resources', 'welcome_messages.json')).toString()); |
27 |
|
|
28 |
generateEmbed(member: GuildMember, index?: number) { |
generateEmbed(member: GuildMember, index?: number) { |
29 |
const { message, randomize } = this.client.config.props[member.guild.id].welcomer; |
const { message, randomize } = this.client.config.props[member.guild.id].welcomer; |
30 |
let content = message ?? ''; |
let content: string = message ?? ''; |
31 |
|
|
32 |
if (randomize) { |
if (randomize) { |
33 |
content = this.generateMessage(index) + (message ? "\n" + content : ''); |
content = this.generateMessage(index) + (message ? "\n" + content : ''); |
38 |
} |
} |
39 |
|
|
40 |
content = content |
content = content |
41 |
.replace(':name:', member.displayName) |
.replace(/:name:/g, member.displayName) |
42 |
.replace(':tag:', member.user.tag) |
.replace(/:tag:/g, member.user.tag) |
43 |
.replace(':username:', member.user.username) |
.replace(/:username:/g, member.user.username) |
44 |
.replace(':discrim:', member.user.discriminator) |
.replace(/:discrim:/g, member.user.discriminator) |
45 |
.replace(':avatar:', member.displayAvatarURL()) |
.replace(/:avatar:/g, member.displayAvatarURL()) |
46 |
.replace(':date:', `<t:${member.joinedAt?.getTime()}>`) |
.replace(/:date:/g, `<t:${member.joinedAt?.getTime()}>`) |
47 |
.replace(':guild:', member.guild.name) |
.replace(/:guild:/g, member.guild.name) |
48 |
.replace(':mention:', member.toString()); |
.replace(/:mention:/g, member.toString()); |
49 |
|
|
50 |
return { |
return { |
51 |
content: member.toString(), |
content: member.toString(), |