Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added a goodbye message
for users that leave the discord.
  • Loading branch information
wsf235 authored Jun 15, 2018
commit 525833a05c363d9d240547ebd452aa2e71dbd71a
37 changes: 22 additions & 15 deletions bot/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,35 @@ client.on('ready', () => {

// Listen for messages
client.on('message', (message) => {
// set content to !tos if new memeber
const newMsg = message;
newMsg.content = message.type === 'GUILD_MEMBER_JOIN' ? '!tos' : message.content;

//create a ToS message for new members
const new_message = message;
new_message.content = message.type == 'GUILD_MEMBER_JOIN' ? '!terms' : new_message.content;

// Check for ! prefix on message to ensure it is a command
if (newMsg.content.charAt(0) === '!') {
util.log('Command message received', newMsg.content, 0);
if (new_message.content.charAt(0) === '!') {
util.log('Command message received', new_message.content, 0);

// Build basic help string
let helpString = 'v1.4.0 Discovered Commands:\n\n\t**<> - Required Item\t\t[] - Optional Item**';

// Process message against every controller
Object.keys(controllers).forEach((key) => {
// Instantiate the controller
const controllerInstance = new controllers[key](newMsg);
const controllerInstance = new controllers[key](new_message);
util.log('Controller instance', controllerInstance, 5);
// Runs commands after constructor is called
controllerInstance.run();

// Loop through commands if help command and add to string
if (newMsg.content.toLowerCase() === '!help') {
if (new_message.content.toLowerCase() === '!help') {
Object.keys(controllerInstance.commands).forEach((commandKey) => {
const commandInstance = controllerInstance.commands[commandKey];
// Check if command should be shown in help menu
if (commandInstance.showWithHelp) {
if (commandInstance.adminOnly && isAdmin(newMsg.member)) {
if (commandInstance.adminOnly && isAdmin(new_message.member)) {
helpString += `\n\n \`${commandInstance.example}\` **- Admin Only** \n\t ${commandInstance.description}`;
} else if (commandInstance.adminOnly && !isAdmin(newMsg.member)) {
} else if (commandInstance.adminOnly && !isAdmin(new_message.member)) {
helpString += '';
} else {
helpString += `\n\n \`${commandInstance.example}\` \n\t ${commandInstance.description}`;
Expand All @@ -55,17 +56,23 @@ client.on('message', (message) => {
});

// If help command called, display string
if (newMsg.content.toLowerCase() === '!help') {
newMsg.reply(helpString);
if (new_message.content.toLowerCase() === '!help') {
new_message.reply(helpString);
}
}
});

// Listen for new users to join
// Listen out for new users to the discord
client.on('guildMemberAdd', (member) => {
// Display welcome message to new memeber in General Channel
const general = member.guild.channels.find('name', 'general');
general.send(`Greetings, ${member}. I've been expecting you.`);
// Add new welcome message to general
const main_channel = member.guild.channels.find('name', 'general');
main_channel.send(`Hi, ${member}. It's nice to meet you!`);
});

//Listen out for members that leave the discord
client.on('guildMemberRemove', (member) => {
const main_channel = member.guild.channels.find('name', 'general');
main_channel.send(`${member} has left... it was nice knowing you! ;-;`);
});

client.login(process.env.TOKEN);