mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Add WelcomeMessage plugin
This commit is contained in:
parent
1fef4128cf
commit
23eb057780
2 changed files with 56 additions and 0 deletions
|
@ -92,6 +92,7 @@ import { ZeppelinPlugin } from "./plugins/ZeppelinPlugin";
|
|||
import { customArgumentTypes } from "./customArgumentTypes";
|
||||
import { startUptimeCounter } from "./uptime";
|
||||
import { UsernameSaver } from "./plugins/UsernameSaver";
|
||||
import { WelcomeMessagePlugin } from "./plugins/WelcomeMessage";
|
||||
|
||||
// Run latest database migrations
|
||||
logger.info("Running database migrations");
|
||||
|
@ -136,6 +137,7 @@ connect().then(async conn => {
|
|||
PingableRolesPlugin,
|
||||
SelfGrantableRolesPlugin,
|
||||
RemindersPlugin,
|
||||
WelcomeMessagePlugin,
|
||||
],
|
||||
|
||||
globalPlugins: [BotControlPlugin, LogServerPlugin, UsernameSaver],
|
||||
|
|
54
src/plugins/WelcomeMessage.ts
Normal file
54
src/plugins/WelcomeMessage.ts
Normal file
|
@ -0,0 +1,54 @@
|
|||
import { ZeppelinPlugin } from "./ZeppelinPlugin";
|
||||
import { decorators as d, IPluginOptions } from "knub";
|
||||
import { Member, TextChannel } from "eris";
|
||||
import { renderTemplate } from "../templateFormatter";
|
||||
import { createChunkedMessage, stripObjectToScalars } from "../utils";
|
||||
|
||||
interface IWelcomeMessageConfig {
|
||||
send_dm: boolean;
|
||||
send_to_channel: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export class WelcomeMessagePlugin extends ZeppelinPlugin<IWelcomeMessageConfig> {
|
||||
public static pluginName = "welcome_message";
|
||||
|
||||
protected getDefaultOptions(): IPluginOptions<IWelcomeMessageConfig> {
|
||||
return {
|
||||
config: {
|
||||
send_dm: false,
|
||||
send_to_channel: null,
|
||||
message: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@d.event("guildMemberAdd")
|
||||
async onGuildMemberAdd(_, member: Member) {
|
||||
const config = this.getConfig();
|
||||
if (!config.message) return;
|
||||
if (!config.send_dm && !config.send_to_channel) return;
|
||||
|
||||
const formatted = await renderTemplate(config.message, {
|
||||
member: stripObjectToScalars(member, ["user"]),
|
||||
});
|
||||
|
||||
if (config.send_dm) {
|
||||
const dmChannel = await member.user.getDMChannel();
|
||||
if (!dmChannel) return;
|
||||
|
||||
try {
|
||||
createChunkedMessage(dmChannel, formatted);
|
||||
} catch (e) {} // tslint:disable-line
|
||||
}
|
||||
|
||||
if (config.send_to_channel) {
|
||||
const channel = this.guild.channels.get(config.send_to_channel);
|
||||
if (!channel || !(channel instanceof TextChannel)) return;
|
||||
|
||||
try {
|
||||
createChunkedMessage(channel, formatted);
|
||||
} catch (e) {} // tslint:disable-line
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue