Skip to content

Commit

Permalink
Add multi-language support for events
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek committed Apr 3, 2021
1 parent afd6dbe commit 16fb37a
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 260 deletions.
2 changes: 1 addition & 1 deletion commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.run = (client, message, args, level) => {
const embed = new Discord.MessageEmbed()
.setTitle(lang.Commands)
.setColor(colors.default)
.addField(output, `${lang.ValidCategories}:\n\`admin\`, \`economy\`, \`fun\`, \`moderation\`, \`utility\``)
.addField(output, `\n${lang.ValidCategories}:\n\`admin\`, \`economy\`, \`fun\`, \`moderation\`, \`utility\``)
.setFooter(`${lang.RespondingTo} ${message.author.tag}`, message.author.avatarURL())
.setTimestamp()

Expand Down
33 changes: 18 additions & 15 deletions events/channelCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ const Discord = require('discord.js')
const colors = require('../lib/colors.json')

module.exports = (client, channel) => {
if (channel.type == "dm") return
const settings = client.getSettings(channel.guild.id)
if (settings.logChannelUpdates == 'true') {
if (settings.modLogChannel && channel.guild.channels.cache.find(c => c.name == settings.modLogChannel)) {
const modLogChannel = channel.guild.channels.cache.find(c => c.name == settings.modLogChannel)
if (!modLogChannel.permissionsFor(channel.guild.me).has('VIEW_CHANNEL')) return
if (!modLogChannel.permissionsFor(channel.guild.me).has('SEND_MESSAGES')) return
const embed = new Discord.MessageEmbed()
.setAuthor('🔨 Channel created')
.setColor(colors.green)
.setDescription(`Created channel ${channel}`)
.setTimestamp()
if (channel.type == "dm") return
const settings = client.getSettings(channel.guild.id)
const language = settings.language
const lang = require("../lib/languages/" + language + ".json")

modLogChannel.send(embed)
if (settings.logChannelUpdates == 'true') {
if (settings.modLogChannel && channel.guild.channels.cache.find(c => c.name == settings.modLogChannel)) {
const modLogChannel = channel.guild.channels.cache.find(c => c.name == settings.modLogChannel)
if (!modLogChannel.permissionsFor(channel.guild.me).has('VIEW_CHANNEL')) return
if (!modLogChannel.permissionsFor(channel.guild.me).has('SEND_MESSAGES')) return
const embed = new Discord.MessageEmbed()
.setAuthor(`🔨 ${lang.ChannelCreated}`)
.setColor(colors.green)
.setDescription(`${lang.CreatedChannel} ${channel}`)
.setTimestamp()

modLogChannel.send(embed)
}
}
}
}
}
31 changes: 17 additions & 14 deletions events/channelDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ const Discord = require('discord.js')
const colors = require('../lib/colors.json')

module.exports = (client, channel) => {
const settings = client.getSettings(channel.guild.id)
if (settings.logChannelUpdates == 'true') {
if (settings.modLogChannel && channel.guild.channels.cache.find(c => c.name == settings.modLogChannel)) {
const modLogChannel = channel.guild.channels.cache.find(c => c.name == settings.modLogChannel)
if (!modLogChannel.permissionsFor(channel.guild.me).has('VIEW_CHANNEL')) return
if (!modLogChannel.permissionsFor(channel.guild.me).has('SEND_MESSAGES')) return
const settings = client.getSettings(channel.guild.id)
const language = settings.language
const lang = require("../lib/languages/" + language + ".json")

const embed = new Discord.MessageEmbed()
.setAuthor('🗑️ Channel deleted')
.setColor(colors.red)
.setDescription(`Deleted channel \`${channel.name}\``)
.setTimestamp()
if (settings.logChannelUpdates == 'true') {
if (settings.modLogChannel && channel.guild.channels.cache.find(c => c.name == settings.modLogChannel)) {
const modLogChannel = channel.guild.channels.cache.find(c => c.name == settings.modLogChannel)
if (!modLogChannel.permissionsFor(channel.guild.me).has('VIEW_CHANNEL')) return
if (!modLogChannel.permissionsFor(channel.guild.me).has('SEND_MESSAGES')) return

modLogChannel.send(embed)
const embed = new Discord.MessageEmbed()
.setAuthor(`🗑️ ${lang.ChannelDeleted}`)
.setColor(colors.red)
.setDescription(`${lang.DeletedChannel} \`${channel.name}\``)
.setTimestamp()

modLogChannel.send(embed)
}
}
}
}
}
27 changes: 16 additions & 11 deletions events/emojiCreate.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
const Discord = require("discord.js");
const colors = require('../lib/colors.json')

module.exports = (client, emoji) => {
let settings = client.getSettings(emoji.guild.id);
if (settings.logEmojiUpdates == "true") {
let modLogChannel = settings.modLogChannel;
let settings = client.getSettings(emoji.guild.id);
const language = settings.language
const lang = require("../lib/languages/" + language + ".json")

if (modLogChannel && emoji.guild.channels.cache.find(c => c.name === settings.modLogChannel)) {
let embed = new Discord.MessageEmbed()
.setTitle("Emoji Create")
.setColor("#eeeeee")
.setDescription(`Name: ${emoji.name}\nID: ${emoji.id}`)
.addField("Emoji URL", emoji.url);
if (settings.logEmojiUpdates == "true") {
let modLogChannel = settings.modLogChannel;

emoji.guild.channels.cache.find(c => c.name === settings.modLogChannel).send(embed);
if (modLogChannel && emoji.guild.channels.cache.find(c => c.name === settings.modLogChannel)) {
let embed = new Discord.MessageEmbed()
.setTitle(`🙂 ${lang.EmojiCreated}`)
.setColor(colors.green)
.setDescription(`${lang.Name}: ${emoji.name}\n${lang.ID}: ${emoji.id}`)
.addField(lang.EmojiURL, emoji.url)
.setTimestamp()

emoji.guild.channels.cache.find(c => c.name === settings.modLogChannel).send(embed);
}
}
}
};
27 changes: 16 additions & 11 deletions events/emojiDelete.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
const Discord = require("discord.js");
const colors = require('../lib/colors.json')

module.exports = (client, emoji) => {
let settings = client.getSettings(emoji.guild.id);
if (settings.logEmojiUpdates == "true") {
let modLogChannel = settings.modLogChannel;
let settings = client.getSettings(emoji.guild.id)
const language = settings.language
const lang = require("../lib/languages/" + language + ".json")

if (modLogChannel && emoji.guild.channels.cache.find(c => c.name === settings.modLogChannel)) {
let embed = new Discord.MessageEmbed()
.setTitle("Emoji Delete")
.setColor("#eeeeee")
.setDescription(`Name: ${emoji.name}\nID: ${emoji.id}`)
.addField("Emoji URL", emoji.url);
if (settings.logEmojiUpdates == "true") {
let modLogChannel = settings.modLogChannel;

emoji.guild.channels.cache.find(c => c.name === settings.modLogChannel).send(embed);
if (modLogChannel && emoji.guild.channels.cache.find(c => c.name === settings.modLogChannel)) {
let embed = new Discord.MessageEmbed()
.setTitle(`🙂 ${lang.EmojiDeleted}`)
.setColor(colors.red)
.setDescription(`${lang.Name}: ${emoji.name}\n${lang.ID}: ${emoji.id}`)
.addField(lang.EmojiURL, emoji.url)
.setTimestamp()

emoji.guild.channels.cache.find(c => c.name === settings.modLogChannel).send(embed);
}
}
}
};
35 changes: 19 additions & 16 deletions events/emojiUpdate.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
const Discord = require("discord.js");
const Discord = require("discord.js");
const colors = require('../lib/colors.json')

module.exports = (client, oldemoji, newemoji) => {
let settings = client.getSettings(newemoji.guild.id); // Get settings
if (settings.logEmojiUpdates == "true") { // If the "log emoji update" setting is set to true, then we should do this.
let modLogChannel = settings.modLogChannel; // Set the logging channel
let settings = client.getSettings(newemoji.guild.id);
const language = settings.language
const lang = require("../lib/languages/" + language + ".json")

if (modLogChannel && newemoji.guild.channels.cache.find(c => c.name === settings.modLogChannel)) {
let embed = new Discord.MessageEmbed() // Create embed
.setTitle("Emoji Update") // Set embed title
.setColor("#eeeeee") // Set color in HEX
.setDescription(`New Name: ${newemoji.name}\nOld Name: ${oldemoji.name}\nID: ${newemoji.id}`) // Description of the embed
.addField("New Emoji URL", newemoji.url) // URL link to the New™ Emoji®
.addField("Old Emoji URL", oldemoji.url); // Url link to the old Emoji®
if (settings.logEmojiUpdates == "true") {
let modLogChannel = settings.modLogChannel;

newemoji.guild.channels.cache.find(c => c.name === settings.modLogChannel).send(embed); // And then we send all that to the logging channel.
}
}
};
if (modLogChannel && newemoji.guild.channels.cache.find(c => c.name === settings.modLogChannel)) {
let embed = new Discord.MessageEmbed()
.setTitle(`🙂 ${lang.EmojiUpdated}`)
.setColor(colors.default)
.setDescription(`${lang.NewName}: ${newemoji.name}\n${lang.OldName}: ${oldemoji.name}\n${lang.ID}: ${newemoji.id}`)
.addField(lang.NewURL, newemoji.url)
.addField(lang.OldURL, oldemoji.url)
.setTimestamp()

// comments by odysssssssssssssssssssssssssssssssssssssssssssssssssssey346
newemoji.guild.channels.cache.find(c => c.name === settings.modLogChannel).send(embed);
}
}
};
8 changes: 4 additions & 4 deletions events/error.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Discord = require("discord.js");
module.exports = async (client, error) => {
if (JSON.stringify(error).toLowerCase().includes("discordapierror")) return;
client.logger.log(error.message, "error"); // Log error
client.channels.cache.get("751473673474539560").send(error.message);
};
if (JSON.stringify(error).toLowerCase().includes("discordapierror")) return;
client.logger.log(error.message, "error"); // Log error
client.channels.cache.get("828038899825508352").send(error.message);
};
38 changes: 20 additions & 18 deletions events/guildBanAdd.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
const Discord = require('discord.js')
const Discord = require('discord.js')
const colors = require('../lib/colors.json')

module.exports = (client, guild, user) => {
const settings = client.getSettings(guild.id)
const modLogChannel = guild.channels.cache.find(c => c.name === settings.modLogChannel)
const settings = client.getSettings(guild.id)
const language = settings.language
const lang = require("../lib/languages/" + language + ".json")
const modLogChannel = guild.channels.cache.find(c => c.name === settings.modLogChannel)

if (guild === null) return
if (guild === null) return

if (settings.logMessageUpdates == 'true') {
if (settings.modLogChannel && guild.channels.cache.find(c => c.name == settings.modLogChannel)) {
const modLogChannel = guild.channels.cache.find(c => c.name == settings.modLogChannel)
if (!modLogChannel.permissionsFor(guild.me).has('VIEW_CHANNEL')) return
if (!modLogChannel.permissionsFor(guild.me).has('SEND_MESSAGES')) return
if (settings.logMessageUpdates == 'true') {
if (settings.modLogChannel && guild.channels.cache.find(c => c.name == settings.modLogChannel)) {
const modLogChannel = guild.channels.cache.find(c => c.name == settings.modLogChannel)
if (!modLogChannel.permissionsFor(guild.me).has('VIEW_CHANNEL')) return
if (!modLogChannel.permissionsFor(guild.me).has('SEND_MESSAGES')) return

const embed = new Discord.MessageEmbed()
.setTitle('🔨 Member banned')
.setColor(colors.red)
.setDescription(`**Total member count:** \`${guild.memberCount}\`\n<@${user.id}> was banned from the Discord.`)
.setThumbnail(user.displayAvatarURL)
.setTimestamp()
const embed = new Discord.MessageEmbed()
.setTitle(`🔨 ${lang.UserBanned}`)
.setColor(colors.red)
.setDescription(`**${lang.TotalMemberCount}:** \`${guild.memberCount}\`\n<@${user.id}> ${lang.BannedFromDiscord}`)
.setThumbnail(user.displayAvatarURL)
.setTimestamp()

modLogChannel.send(embed)
modLogChannel.send(embed)
}
}
}
}
}
6 changes: 4 additions & 2 deletions events/guildBanRemove.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ const colors = require('../lib/colors.json')

module.exports = (client, guild, user) => {
const settings = client.getSettings(guild.id);
const language = settings.language
const lang = require("../lib/languages/" + language + ".json")
const modLogChannel = settings.modLogChannel;

if (modLogChannel && guild.channels.cache.find(c => c.name === settings.modLogChannel)) {
let embed = new Discord.MessageEmbed()
.setTitle("User unbanned")
.setTitle(lang.UserUnbanned)
.setColor(colors.green)
.setDescription(`Name: ${user.username}\nID: ${user.id}`);
.setDescription(`${lang.Name}: ${user.username}\n${lang.ID}: ${user.id}`);

guild.channels.cache.find(c => c.name === settings.modLogChannel).send(embed);
}
Expand Down
76 changes: 25 additions & 51 deletions events/guildMemberAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,37 @@ const Discord = require('discord.js')
const colors = require('../lib/colors.json')

module.exports = (client, member) => {
const settings = client.getSettings(member.guild.id)
if (settings.welcomeEnabled !== 'true') return
const settings = client.getSettings(member.guild.id)
const language = settings.language
const lang = require("../lib/languages/" + language + ".json")

const welcomeChannel = member.guild.channels.cache.find(c => c.name == settings.welcomeChannel)
if (settings.welcomeEnabled !== 'true') return

if (settings.welcomeMessage && welcomeChannel) {
if (!welcomeChannel.permissionsFor(member.guild.me).has('VIEW_CHANNEL')) return
if (!welcomeChannel.permissionsFor(member.guild.me).has('SEND_MESSAGES')) return
const welcomeChannel = member.guild.channels.cache.find(c => c.name == settings.welcomeChannel)

if (settings.welcomeMessage && welcomeChannel) {
if (!welcomeChannel.permissionsFor(member.guild.me).has('VIEW_CHANNEL')) return
if (!welcomeChannel.permissionsFor(member.guild.me).has('SEND_MESSAGES')) return

// TODO: Better way of doing this
if (settings.welcomeMessage.includes('{{name}}')) { // If includes {{name}}
if (settings.welcomeMessage.includes('{{mention}}')) { // If includes {{name}} and {{mention}}
if (settings.welcomeMessage.includes('{{members}}')) { // If includes {{name}}, {{mention}} and {{members}}
const welcomeMessage = settings.welcomeMessage.replace('{{name}}', member.user.tag).replace('{{mention}}', '<@' + member.user.id + '>').replace('{{members}}', member.guild.memberCount)
welcomeChannel.send(welcomeMessage)
} else {
const welcomeMessage = settings.welcomeMessage.replace('{{name}}', member.user.tag).replace('{{mention}}', '<@' + member.user.id + '>')
welcomeChannel.send(welcomeMessage)
}
} else {
const welcomeMessage = settings.welcomeMessage.replace('{{name}}', member.user.tag).replace('{{mention}}', '<@' + member.user.id + '>').replace('{{members}}', member.guild.memberCount)
welcomeChannel.send(welcomeMessage)
}
} else {
if (settings.welcomeMessage.includes('{{mention}}')) { // If includes {{mention}}
if (settings.welcomeMessage.includes('{{members}}')) { // If includes {{mention}} and {{members}}
const welcomeMessage = settings.welcomeMessage.replace('{{mention}}', '<@' + member.user.id + '>').replace('{{members}}', member.guild.memberCount)
welcomeChannel.send(welcomeMessage)
} else {
const welcomeMessage = settings.welcomeMessage.replace('{{mention}}', '<@' + member.user.id + '>')
welcomeChannel.send(welcomeMessage)
}
} else {
if (settings.welcomeMessage.includes('{{members}}')) { // If includes {{members}}
const welcomeMessage = settings.welcomeMessage.replace('{{members}}', member.guild.memberCount)
welcomeChannel.send(welcomeMessage)
} else { // If doesn't contain any variables
welcomeChannel.send(settings.welcomeMessage)
}
}

}
}

if (settings.logMessageUpdates === 'true') {
const modLogChannel = member.guild.channels.cache.find(c => c.name === settings.modLogChannel)
if (settings.modLogChannel && modLogChannel) {
if (!modLogChannel.permissionsFor(member.guild.me).has('VIEW_CHANNEL')) return
if (!modLogChannel.permissionsFor(member.guild.me).has('SEND_MESSAGES')) return
if (settings.logMessageUpdates === 'true') {
const modLogChannel = member.guild.channels.cache.find(c => c.name === settings.modLogChannel)
if (settings.modLogChannel && modLogChannel) {
if (!modLogChannel.permissionsFor(member.guild.me).has('VIEW_CHANNEL')) return
if (!modLogChannel.permissionsFor(member.guild.me).has('SEND_MESSAGES')) return

const embed = new Discord.MessageEmbed()
.setAuthor('📥 Member joined')
.setColor(colors.green)
.setDescription(`**Total member count:** \`${member.guild.memberCount}\`\n<@${member.user.id}> joined the Discord.`)
.setThumbnail(`${member.user.displayAvatarURL}`)
.setTimestamp()
const embed = new Discord.MessageEmbed()
.setAuthor(`📥 ${lang.MemberJoined}`)
.setColor(colors.green)
.setDescription(`**${lang.TotalMemberCount}:** \`${member.guild.memberCount}\`\n<@${member.user.id}> ${lang.JoinedTheDiscord}.`)
.setThumbnail(`${member.user.displayAvatarURL}`)
.setTimestamp()

modLogChannel.send(embed)
}
}
}
modLogChannel.send(embed)
}
}
}
Loading

0 comments on commit 16fb37a

Please sign in to comment.