mirror of
https://github.com/keanuplayz/TravBot-v3.git
synced 2024-08-15 02:33:12 +00:00
Added welcome message and system logs channel
This commit is contained in:
parent
ee9c88996e
commit
c1b298a407
5 changed files with 97 additions and 6 deletions
|
@ -102,8 +102,18 @@ export default new Command({
|
||||||
}),
|
}),
|
||||||
channel: new Command({
|
channel: new Command({
|
||||||
description: "Sets the welcome channel for your server. Type `#` to reference the channel.",
|
description: "Sets the welcome channel for your server. Type `#` to reference the channel.",
|
||||||
usage: "<channel mention>",
|
usage: "(<channel mention>)",
|
||||||
run: "You need to specify a channel.",
|
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.
|
// If/when channel types come out, this will be the perfect candidate to test it.
|
||||||
any: new Command({
|
any: new Command({
|
||||||
async run($) {
|
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: "(<message>)",
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,12 +3,15 @@ import $, {select, GenericJSON, GenericStructure} from "./lib";
|
||||||
import {watch} from "fs";
|
import {watch} from "fs";
|
||||||
import {Guild as DiscordGuild, Snowflake} from "discord.js";
|
import {Guild as DiscordGuild, Snowflake} from "discord.js";
|
||||||
|
|
||||||
|
// Maybe use getters and setters to auto-save on set?
|
||||||
|
|
||||||
class ConfigStructure extends GenericStructure {
|
class ConfigStructure extends GenericStructure {
|
||||||
public token: string;
|
public token: string;
|
||||||
public prefix: string;
|
public prefix: string;
|
||||||
public owner: string;
|
public owner: string;
|
||||||
public admins: string[];
|
public admins: string[];
|
||||||
public support: string[];
|
public support: string[];
|
||||||
|
public systemLogsChannel: string | null;
|
||||||
|
|
||||||
constructor(data: GenericJSON) {
|
constructor(data: GenericJSON) {
|
||||||
super("config");
|
super("config");
|
||||||
|
@ -17,6 +20,7 @@ class ConfigStructure extends GenericStructure {
|
||||||
this.owner = select(data.owner, "", String);
|
this.owner = select(data.owner, "", String);
|
||||||
this.admins = select(data.admins, [], String, true);
|
this.admins = select(data.admins, [], String, true);
|
||||||
this.support = select(data.support, [], 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 prefix: string | null;
|
||||||
public welcomeType: "none" | "text" | "graphical";
|
public welcomeType: "none" | "text" | "graphical";
|
||||||
public welcomeChannel: string | null;
|
public welcomeChannel: string | null;
|
||||||
|
public welcomeMessage: string | null;
|
||||||
|
|
||||||
constructor(data?: GenericJSON) {
|
constructor(data?: GenericJSON) {
|
||||||
this.prefix = select(data?.prefix, null, String);
|
this.prefix = select(data?.prefix, null, String);
|
||||||
this.welcomeChannel = select(data?.welcomeChannel, null, String);
|
this.welcomeChannel = select(data?.welcomeChannel, null, String);
|
||||||
|
this.welcomeMessage = select(data?.welcomeMessage, null, String);
|
||||||
|
|
||||||
switch (data?.welcomeType) {
|
switch (data?.welcomeType) {
|
||||||
case "text":
|
case "text":
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import Event from "../core/event";
|
import Event from "../core/event";
|
||||||
import $ from "../core/lib";
|
import $ from "../core/lib";
|
||||||
import {updateGlobalEmoteRegistry} 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">({
|
export default new Event<"guildCreate">({
|
||||||
on(guild) {
|
on(guild) {
|
||||||
|
@ -9,6 +12,21 @@ export default new Event<"guildCreate">({
|
||||||
guild.owner!.user.id
|
guild.owner!.user.id
|
||||||
}). Updated emote registry.`
|
}). 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();
|
updateGlobalEmoteRegistry();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,24 @@
|
||||||
import Event from "../core/event";
|
import Event from "../core/event";
|
||||||
import $ from "../core/lib";
|
import $ from "../core/lib";
|
||||||
import {updateGlobalEmoteRegistry} 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">({
|
export default new Event<"guildDelete">({
|
||||||
on(guild) {
|
on(guild) {
|
||||||
$.log(`[GUILD LEAVE] ${guild.name} (${guild.id}) removed the bot. Updated emote registry.`);
|
$.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();
|
updateGlobalEmoteRegistry();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,7 +17,7 @@ function applyText(canvas: Canvas, text: string) {
|
||||||
|
|
||||||
export default new Event<"guildMemberAdd">({
|
export default new Event<"guildMemberAdd">({
|
||||||
async on(member) {
|
async on(member) {
|
||||||
const {welcomeType, welcomeChannel} = Storage.getGuild(member.guild.id);
|
const {welcomeType, welcomeChannel, welcomeMessage} = Storage.getGuild(member.guild.id);
|
||||||
|
|
||||||
if (welcomeChannel) {
|
if (welcomeChannel) {
|
||||||
const channel = member.guild.channels.cache.get(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);
|
(channel as TextChannel).send(`Welcome \`${member.user.tag}\`!`, attachment);
|
||||||
} else if (welcomeType === "text") {
|
} else if (welcomeType === "text") {
|
||||||
(channel as TextChannel).send(
|
(channel as TextChannel).send(
|
||||||
parseVars("Say hello to `%user%`, everyone! We all need a warm welcome sometimes :D", {
|
parseVars(
|
||||||
|
welcomeMessage ||
|
||||||
|
"Say hello to `%user%`, everyone! We all need a warm welcome sometimes :D",
|
||||||
|
{
|
||||||
user: member.user.tag
|
user: member.user.tag
|
||||||
})
|
}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue