Browse Source

Fix formatting for code

master
Abheek Dhawan 4 years ago
parent
commit
ee1b1474b0
  1. 383
      index.js

383
index.js

@ -10,20 +10,20 @@ const CONNECTION_URL = "localhost:27017";
const prefix = '$'; const prefix = '$';
MongoClient.connect("mongodb://" + CONNECTION_URL, { useNewUrlParser: true }, (error, client) => { MongoClient.connect("mongodb://" + CONNECTION_URL, { useNewUrlParser: true }, (error, client) => {
if(error) { if (error) {
throw error; throw error;
} }
database = client.db(DATABASE_NAME); database = client.db(DATABASE_NAME);
collection = database.collection("awesome_mod"); collection = database.collection("awesome_mod");
console.log("Connected to `" + DATABASE_NAME + "`!"); console.log("Connected to `" + DATABASE_NAME + "`!");
}); });
client.on("guildCreate", async guild => { client.on("guildCreate", async guild => {
let awesomeModCatID, botLogID, roleReqID; let awesomeModCatID, botLogID, roleReqID;
collection.insertOne({ guild_id: guild.id }, (error, result) => { collection.insertOne({ guild_id: guild.id }, (error, result) => {
if(error) { if (error) {
console.error; console.error;
} }
}); });
// Create "Awesome Mod" category for other channels to reside in // Create "Awesome Mod" category for other channels to reside in
guild.channels.create('Awesome Mod', { guild.channels.create('Awesome Mod', {
@ -35,44 +35,45 @@ client.on("guildCreate", async guild => {
deny: ['VIEW_CHANNEL'], deny: ['VIEW_CHANNEL'],
}] }]
}) })
.then(channel => { .then(channel => {
// Create "#bot-logs" text channel to track message deletes, edits, and channel creations // Create "#bot-logs" text channel to track message deletes, edits, and channel creations
guild.channels.create('bot-logs', { guild.channels.create('bot-logs', {
type: 'text', type: 'text',
parent: channel.id, parent: channel.id,
// Remove view permissions from "@everyone" // Remove view permissions from "@everyone"
permissionOverwrites: [{ permissionOverwrites: [{
id: guild.id, id: guild.id,
deny: ['VIEW_CHANNEL'], deny: ['VIEW_CHANNEL'],
}] }]
}).then(channel => { }).then(channel => {
// Add the ID of the "#bot-logs" channel to the database // Add the ID of the "#bot-logs" channel to the database
collection.updateOne({ guild_id: guild.id }, { $set: { "bot_logs_id": `${channel.id}` }}); collection.updateOne({ guild_id: guild.id }, { $set: { "bot_logs_id": `${channel.id}` } });
}); });
// Create "#role-requests" text channel to have people request roles // Create "#role-requests" text channel to have people request roles
guild.channels.create('role-requests', { guild.channels.create('role-requests', {
type: 'text', type: 'text',
parent: channel.id, parent: channel.id,
// Remove view permissions from "@everyone" // Remove view permissions from "@everyone"
permissionOverwrites: [{ permissionOverwrites: [{
id: guild.id, id: guild.id,
allow: ['VIEW_CHANNEL'], allow: ['VIEW_CHANNEL'],
}] }]
}).then(channel => { }).then(channel => {
// Add the ID of the "#bot-logs" channel to the database // Add the ID of the "#bot-logs" channel to the database
collection.updateOne({ guild_id: guild.id }, { $set: { "role_requests_id": `${channel.id}` }}); collection.updateOne({ guild_id: guild.id }, { $set: { "role_requests_id": `${channel.id}` } });
// Add slowmode // Add slowmode
channel.setRateLimitPerUser(60); channel.setRateLimitPerUser(60);
}); });
}); });
}); });
client.on("guildDelete", async guild => { client.on("guildDelete", async guild => {
// If the bot is removed from a guild or the guild is deleted, the bot deletes the old data
collection.deleteOne({ "guild_id": `${guild.id}` }, (error, result) => { collection.deleteOne({ "guild_id": `${guild.id}` }, (error, result) => {
if(error) { if (error) {
console.error; console.error;
} }
}); });
}); });
@ -186,32 +187,32 @@ async function roleRequest(message) {
return; return;
} }
collection.findOne({ guild_id: message.guild.id}, (error, result) => { collection.findOne({ guild_id: message.guild.id }, (error, result) => {
if(error) { if (error) {
console.error; console.error;
} }
roleChannel = result.role_requests_id; roleChannel = result.role_requests_id;
if (message.channel.id !== roleChannel) { if (message.channel.id !== roleChannel) {
message.reply(`wrong channel! Roles can only be requested in <#${roleChannel}>.`); message.reply(`wrong channel! Roles can only be requested in <#${roleChannel}>.`);
return; return;
} }
const verificationMessage = message.channel.send(`<@${message.author.id}> would like the **${role}** role. Are they worthy?`); const verificationMessage = message.channel.send(`<@${message.author.id}> would like the **${role}** role. Are they worthy?`);
message.react('👍'); message.react('👍');
message.react('👎'); message.react('👎');
const filter = (reaction, user) => { const filter = (reaction, user) => {
return ['👍', '👎'].includes(reaction.emoji.name) && message.guild.members.cache.get(user.id).hasPermission('ADMINISTRATOR') && !user.bot; return ['👍', '👎'].includes(reaction.emoji.name) && message.guild.members.cache.get(user.id).hasPermission('ADMINISTRATOR') && !user.bot;
}; };
message.awaitReactions(filter, { max: 1, time: 600000000, errors: ['time'] }) message.awaitReactions(filter, { max: 1, time: 600000000, errors: ['time'] })
.then(userReaction => { .then(userReaction => {
const reaction = userReaction.first(); const reaction = userReaction.first();
if (reaction.emoji.name === '👍') { if (reaction.emoji.name === '👍') {
message.reply("wow I guess you ARE worthy! ||mods must be real mistaken||"); message.reply("wow I guess you ARE worthy! ||mods must be real mistaken||");
message.member.roles.add(role).catch(() => { message.reply("It seems I don't have permissions to give that role, as it's likely above me :(") }); message.member.roles.add(role).catch(() => { message.reply("It seems I don't have permissions to give that role, as it's likely above me :(") });
} else { } else {
message.reply("I guess you won't be getting that role!"); message.reply("I guess you won't be getting that role!");
} }
}).catch("Role reaction timeout, I guess the mods don't really care about you and forgot."); }).catch("Role reaction timeout, I guess the mods don't really care about you and forgot.");
}); });
} }
@ -237,7 +238,7 @@ async function bulkDelete(message) {
return; return;
} }
await message.channel.messages.fetch( { limit: amount + 1 } ).then(messages => { await message.channel.messages.fetch({ limit: amount + 1 }).then(messages => {
message.channel.bulkDelete(messages).catch(console.error); message.channel.bulkDelete(messages).catch(console.error);
}).catch(console.error); }).catch(console.error);
} }
@ -266,8 +267,8 @@ client.on('messageDelete', message => {
.setTimestamp() .setTimestamp()
.setColor('e7778b'); .setColor('e7778b');
collection.findOne({ guild_id: message.guild.id}, (error, result) => { collection.findOne({ guild_id: message.guild.id }, (error, result) => {
if(error) { if (error) {
console.error; console.error;
} }
botLogsChannel = result.bot_logs_id; botLogsChannel = result.bot_logs_id;
@ -287,8 +288,8 @@ client.on('messageDeleteBulk', messages => {
.setTimestamp() .setTimestamp()
.setColor('e7778b'); .setColor('e7778b');
collection.findOne({ guild_id: messagesChannel.guild.id}, (error, result) => { collection.findOne({ guild_id: messagesChannel.guild.id }, (error, result) => {
if(error) { if (error) {
console.error; console.error;
} }
botLogsChannel = result.bot_logs_id; botLogsChannel = result.bot_logs_id;
@ -311,8 +312,8 @@ client.on('messageUpdate', (originalMessage, editedMessage) => {
.setFooter("ID: " + editedMessage.id) .setFooter("ID: " + editedMessage.id)
.setTimestamp() .setTimestamp()
.setColor('c9ff00'); .setColor('c9ff00');
collection.findOne({ guild_id: message.guild.id}, (error, result) => { collection.findOne({ guild_id: message.guild.id }, (error, result) => {
if(error) { if (error) {
console.error; console.error;
} }
botLogsChannel = result.bot_logs_id; botLogsChannel = result.bot_logs_id;
@ -324,139 +325,139 @@ client.on('messageUpdate', (originalMessage, editedMessage) => {
}); });
client.on('channelCreate', channel => { client.on('channelCreate', channel => {
const channelName = channel.name; const channelName = channel.name;
const channelID = channel.id; const channelID = channel.id;
const channelType = channel.type; const channelType = channel.type;
let channelCategory; let channelCategory;
if (channel.parent) { if (channel.parent) {
channelCategory = channel.parent.name; channelCategory = channel.parent.name;
} else { } else {
channelCategory = "None"; channelCategory = "None";
}
const channelCreateEmbed = new Discord.MessageEmbed()
.setTitle("Channel Created")
.addField("Name", channelName)
.addField("Type", channelType)
.addField("Category", channelCategory)
.setFooter("ID: " + channelID)
.setTimestamp()
.setColor('00aaff');
collection.findOne({ guild_id: channel.guild.id }, (error, result) => {
if (error) {
console.error;
} }
const channelCreateEmbed = new Discord.MessageEmbed() botLogsChannel = result.bot_logs_id;
.setTitle("Channel Created") if (channel.guild.channels.cache.get(botLogsChannel)) {
.addField("Name", channelName) channel.guild.channels.cache.get(botLogsChannel).send(channelCreateEmbed).catch(console.error);
.addField("Type", channelType) }
.addField("Category", channelCategory) });
.setFooter("ID: " + channelID)
.setTimestamp()
.setColor('00aaff');
collection.findOne({ guild_id: channel.guild.id}, (error, result) => {
if(error) {
console.error;
}
botLogsChannel = result.bot_logs_id;
if (channel.guild.channels.cache.get(botLogsChannel)) {
channel.guild.channels.cache.get(botLogsChannel).send(channelCreateEmbed).catch(console.error);
}
});
}); });
client.on('messageReactionAdd', (messageReaction, user) => { client.on('messageReactionAdd', (messageReaction, user) => {
const userTag = user.tag; const userTag = user.tag;
const emoji = messageReaction.emoji.name; const emoji = messageReaction.emoji.name;
const numEmoji = messageReaction.count; const numEmoji = messageReaction.count;
const messageContent = messageReaction.message.content; const messageContent = messageReaction.message.content;
let channelCategory; let channelCategory;
const messageReactionAddEmbed = new Discord.MessageEmbed() const messageReactionAddEmbed = new Discord.MessageEmbed()
.setTitle("Reaction Added") .setTitle("Reaction Added")
.addField("Message", messageContent) .addField("Message", messageContent)
.addField("Reactions", `${userTag} reacted with ${emoji}, along with ${numEmoji} other people in #${messageReaction.message.channel.name}.`) .addField("Reactions", `${userTag} reacted with ${emoji}, along with ${numEmoji} other people in #${messageReaction.message.channel.name}.`)
.setFooter("Message ID: " + messageReaction.message.id) .setFooter("Message ID: " + messageReaction.message.id)
.setTimestamp() .setTimestamp()
.setColor('00aaff'); .setColor('00aaff');
collection.findOne({ guild_id: messageReaction.message.guild.id}, (error, result) => { collection.findOne({ guild_id: messageReaction.message.guild.id }, (error, result) => {
if(error) { if (error) {
console.error; console.error;
} }
botLogsChannel = result.bot_logs_id; botLogsChannel = result.bot_logs_id;
if (messageReaction.message.guild.channels.cache.get(botLogsChannel)) { if (messageReaction.message.guild.channels.cache.get(botLogsChannel)) {
messageReaction.message.guild.channels.cache.get(botLogsChannel).send(messageReactionAddEmbed).catch(console.error); messageReaction.message.guild.channels.cache.get(botLogsChannel).send(messageReactionAddEmbed).catch(console.error);
} }
}); });
}); });
client.on('messageReactionRemove', (messageReaction, user) => { client.on('messageReactionRemove', (messageReaction, user) => {
const userTag = user.tag; const userTag = user.tag;
const emoji = messageReaction.emoji.name; const emoji = messageReaction.emoji.name;
const messageContent = messageReaction.message.content; const messageContent = messageReaction.message.content;
let channelCategory; let channelCategory;
const messageReactionRemoveEmbed = new Discord.MessageEmbed() const messageReactionRemoveEmbed = new Discord.MessageEmbed()
.setTitle("Reaction Removed") .setTitle("Reaction Removed")
.addField("Message", messageContent) .addField("Message", messageContent)
.addField("Reactions", `${userTag} removed their reaction ${emoji} in #${messageReaction.message.channel.name}.`) .addField("Reactions", `${userTag} removed their reaction ${emoji} in #${messageReaction.message.channel.name}.`)
.setFooter("Message ID: " + messageReaction.message.id) .setFooter("Message ID: " + messageReaction.message.id)
.setTimestamp() .setTimestamp()
.setColor('e7778b'); .setColor('e7778b');
collection.findOne({ guild_id: messageReaction.message.guild.id}, (error, result) => { collection.findOne({ guild_id: messageReaction.message.guild.id }, (error, result) => {
if(error) { if (error) {
console.error; console.error;
} }
botLogsChannel = result.bot_logs_id; botLogsChannel = result.bot_logs_id;
if (messageReaction.message.guild.channels.cache.get(botLogsChannel)) { if (messageReaction.message.guild.channels.cache.get(botLogsChannel)) {
messageReaction.message.guild.channels.cache.get(botLogsChannel).send(messageReactionRemoveEmbed).catch(console.error); messageReaction.message.guild.channels.cache.get(botLogsChannel).send(messageReactionRemoveEmbed).catch(console.error);
} }
}); });
}); });
client.on('roleCreate', role => { client.on('roleCreate', role => {
const roleCreateEmbed = new Discord.MessageEmbed() const roleCreateEmbed = new Discord.MessageEmbed()
.setTitle("Role Added") .setTitle("Role Added")
.addField("Name", role.name) .addField("Name", role.name)
.addField("Permissions", role.permissions.bitfield) .addField("Permissions", role.permissions.bitfield)
.addField("Mentionable", role.mentionable) .addField("Mentionable", role.mentionable)
.setFooter("Role ID: " + role.id) .setFooter("Role ID: " + role.id)
.setTimestamp() .setTimestamp()
.setColor('00aaff'); .setColor('00aaff');
collection.findOne({ guild_id: role.guild.id}, (error, result) => { collection.findOne({ guild_id: role.guild.id }, (error, result) => {
if(error) { if (error) {
console.error; console.error;
} }
botLogsChannel = result.bot_logs_id; botLogsChannel = result.bot_logs_id;
if (role.guild.channels.cache.get(botLogsChannel)) { if (role.guild.channels.cache.get(botLogsChannel)) {
role.guild.channels.cache.get(botLogsChannel).send(roleCreateEmbed).catch(console.error); role.guild.channels.cache.get(botLogsChannel).send(roleCreateEmbed).catch(console.error);
} }
}); });
}); });
client.on('roleDelete', role => { client.on('roleDelete', role => {
const roleDeleteEmbed = new Discord.MessageEmbed() const roleDeleteEmbed = new Discord.MessageEmbed()
.setTitle("Role Removed") .setTitle("Role Removed")
.addField("Name", role.name) .addField("Name", role.name)
.addField("Permissions", role.permissions.bitfield) .addField("Permissions", role.permissions.bitfield)
.addField("Mentionable", role.mentionable) .addField("Mentionable", role.mentionable)
.setFooter("Role ID: " + role.id) .setFooter("Role ID: " + role.id)
.setTimestamp() .setTimestamp()
.setColor('e7778b'); .setColor('e7778b');
collection.findOne({ guild_id: role.guild.id}, (error, result) => { collection.findOne({ guild_id: role.guild.id }, (error, result) => {
if(error) { if (error) {
console.error; console.error;
} }
botLogsChannel = result.bot_logs_id; botLogsChannel = result.bot_logs_id;
if (role.guild.channels.cache.get(botLogsChannel)) { if (role.guild.channels.cache.get(botLogsChannel)) {
role.guild.channels.cache.get(botLogsChannel).send(roleDeleteEmbed).catch(console.error); role.guild.channels.cache.get(botLogsChannel).send(roleDeleteEmbed).catch(console.error);
} }
}); });
}); });
client.on('roleUpdate', (oldRole, newRole) => { client.on('roleUpdate', (oldRole, newRole) => {
const roleUpdateEmbed = new Discord.MessageEmbed() const roleUpdateEmbed = new Discord.MessageEmbed()
.setTitle("Role Updated") .setTitle("Role Updated")
.addField("Name", `${oldRole.name} >> ${newRole.name}`) .addField("Name", `${oldRole.name} >> ${newRole.name}`)
.addField("Permissions", `${oldRole.permissions.bitfield} >> ${newRole.permissions.bitfield}`) .addField("Permissions", `${oldRole.permissions.bitfield} >> ${newRole.permissions.bitfield}`)
.addField("Mentionable", `${oldRole.mentionable} >> ${newRole.mentionable}`) .addField("Mentionable", `${oldRole.mentionable} >> ${newRole.mentionable}`)
.setFooter("Role ID: " + newRole.id) .setFooter("Role ID: " + newRole.id)
.setTimestamp() .setTimestamp()
.setColor('c9ff00'); .setColor('c9ff00');
collection.findOne({ guild_id: newRole.guild.id}, (error, result) => { collection.findOne({ guild_id: newRole.guild.id }, (error, result) => {
if(error) { if (error) {
console.error; console.error;
} }
botLogsChannel = result.bot_logs_id; botLogsChannel = result.bot_logs_id;
if (newRole.guild.channels.cache.get(botLogsChannel)) { if (newRole.guild.channels.cache.get(botLogsChannel)) {
newRole.guild.channels.cache.get(botLogsChannel).send(roleUpdateEmbed).catch(console.error); newRole.guild.channels.cache.get(botLogsChannel).send(roleUpdateEmbed).catch(console.error);
} }
}); });
}); });
/*client.on('userUpdate', (oldUser, newUser) => { /*client.on('userUpdate', (oldUser, newUser) => {

Loading…
Cancel
Save