diff --git a/src/commands/admin.ts b/src/commands/admin.ts index 2ea6d77..2622087 100644 --- a/src/commands/admin.ts +++ b/src/commands/admin.ts @@ -102,8 +102,18 @@ export default new Command({ }), channel: new Command({ description: "Sets the welcome channel for your server. Type `#` to reference the channel.", - usage: "", - run: "You need to specify a channel.", + usage: "()", + async run($) { + if ($.guild) { + Storage.getGuild($.guild.id).welcomeChannel = $.channel.id; + Storage.save(); + $.channel.send( + `Successfully set ${$.channel} as the welcome channel for this server.` + ); + } else { + $.channel.send("You must use this command in a server."); + } + }, // If/when channel types come out, this will be the perfect candidate to test it. any: new Command({ async run($) { @@ -126,6 +136,32 @@ export default new Command({ } } }) + }), + message: new Command({ + description: + "Sets a custom welcome message for your server. Use `%user%` as the placeholder for the user.", + usage: "()", + async run($) { + if ($.guild) { + Storage.getGuild($.guild.id).welcomeMessage = null; + Storage.save(); + $.channel.send("Reset your server's welcome message to the default."); + } else { + $.channel.send("You must use this command in a server."); + } + }, + any: new Command({ + async run($) { + if ($.guild) { + const message = $.args.join(" "); + Storage.getGuild($.guild.id).welcomeMessage = message; + Storage.save(); + $.channel.send(`Set your server's welcome message to \`${message}\`.`); + } else { + $.channel.send("You must use this command in a server."); + } + } + }) }) } }) @@ -275,6 +311,19 @@ export default new Command({ ); } }) + }), + syslog: new Command({ + description: "Sets up the current channel to receive system logs.", + permission: Command.PERMISSIONS.BOT_ADMIN, + async run($) { + if ($.guild) { + Config.systemLogsChannel = $.channel.id; + Config.save(); + $.channel.send(`Successfully set ${$.channel} as the system logs channel.`); + } else { + $.channel.send("DM system log channels aren't supported."); + } + } }) } }); diff --git a/src/core/structures.ts b/src/core/structures.ts index 384184c..13bdc9f 100644 --- a/src/core/structures.ts +++ b/src/core/structures.ts @@ -3,12 +3,15 @@ import $, {select, GenericJSON, GenericStructure} from "./lib"; import {watch} from "fs"; import {Guild as DiscordGuild, Snowflake} from "discord.js"; +// Maybe use getters and setters to auto-save on set? + class ConfigStructure extends GenericStructure { public token: string; public prefix: string; public owner: string; public admins: string[]; public support: string[]; + public systemLogsChannel: string | null; constructor(data: GenericJSON) { super("config"); @@ -17,6 +20,7 @@ class ConfigStructure extends GenericStructure { this.owner = select(data.owner, "", String); this.admins = select(data.admins, [], String, true); this.support = select(data.support, [], String, true); + this.systemLogsChannel = select(data.systemLogsChannel, null, String); } } @@ -53,10 +57,12 @@ class Guild { public prefix: string | null; public welcomeType: "none" | "text" | "graphical"; public welcomeChannel: string | null; + public welcomeMessage: string | null; constructor(data?: GenericJSON) { this.prefix = select(data?.prefix, null, String); this.welcomeChannel = select(data?.welcomeChannel, null, String); + this.welcomeMessage = select(data?.welcomeMessage, null, String); switch (data?.welcomeType) { case "text": diff --git a/src/events/guildCreate.ts b/src/events/guildCreate.ts index 0fe94dd..02189b3 100644 --- a/src/events/guildCreate.ts +++ b/src/events/guildCreate.ts @@ -1,6 +1,9 @@ import Event from "../core/event"; import $ from "../core/lib"; import {updateGlobalEmoteRegistry} from "../core/lib"; +import {client} from "../index"; +import {Config} from "../core/structures"; +import {TextChannel} from "discord.js"; export default new Event<"guildCreate">({ on(guild) { @@ -9,6 +12,21 @@ export default new Event<"guildCreate">({ guild.owner!.user.id }). Updated emote registry.` ); + + if (Config.systemLogsChannel) { + const channel = client.channels.cache.get(Config.systemLogsChannel); + + if (channel && channel.type === "text") { + (channel as TextChannel).send( + `TravBot joined: \`${guild.name}\`. The owner of this guild is: \`${guild.owner!.user.tag}\` (\`${ + guild.owner!.user.id + }\`)` + ); + } else { + console.warn(`${Config.systemLogsChannel} is not a valid text channel for system logs!`); + } + } + updateGlobalEmoteRegistry(); } }); diff --git a/src/events/guildDelete.ts b/src/events/guildDelete.ts index d1a4f99..41c656f 100644 --- a/src/events/guildDelete.ts +++ b/src/events/guildDelete.ts @@ -1,10 +1,24 @@ import Event from "../core/event"; import $ from "../core/lib"; import {updateGlobalEmoteRegistry} from "../core/lib"; +import {client} from "../index"; +import {Config} from "../core/structures"; +import {TextChannel} from "discord.js"; export default new Event<"guildDelete">({ on(guild) { $.log(`[GUILD LEAVE] ${guild.name} (${guild.id}) removed the bot. Updated emote registry.`); + + if (Config.systemLogsChannel) { + const channel = client.channels.cache.get(Config.systemLogsChannel); + + if (channel && channel.type === "text") { + (channel as TextChannel).send(`\`${guild.name}\` (\`${guild.id}\`) removed the bot.`); + } else { + console.warn(`${Config.systemLogsChannel} is not a valid text channel for system logs!`); + } + } + updateGlobalEmoteRegistry(); } }); diff --git a/src/events/guildMemberAdd.ts b/src/events/guildMemberAdd.ts index ecaab3b..1855094 100644 --- a/src/events/guildMemberAdd.ts +++ b/src/events/guildMemberAdd.ts @@ -17,7 +17,7 @@ function applyText(canvas: Canvas, text: string) { export default new Event<"guildMemberAdd">({ async on(member) { - const {welcomeType, welcomeChannel} = Storage.getGuild(member.guild.id); + const {welcomeType, welcomeChannel, welcomeMessage} = Storage.getGuild(member.guild.id); if (welcomeChannel) { const channel = member.guild.channels.cache.get(welcomeChannel); @@ -60,9 +60,13 @@ export default new Event<"guildMemberAdd">({ (channel as TextChannel).send(`Welcome \`${member.user.tag}\`!`, attachment); } else if (welcomeType === "text") { (channel as TextChannel).send( - parseVars("Say hello to `%user%`, everyone! We all need a warm welcome sometimes :D", { - user: member.user.tag - }) + parseVars( + welcomeMessage || + "Say hello to `%user%`, everyone! We all need a warm welcome sometimes :D", + { + user: member.user.tag + } + ) ); } } else {