From c7c709d51676edbe7214831f11276d2ad782861a Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 6 Aug 2020 17:19:26 +0100 Subject: [PATCH] fixed the fallback channel setting --- legacy/config.json | 1 + package.json | 1 + src/discord-commands.js | 15 +++++++++++++-- src/discord-events.js | 16 +++++++--------- src/discord-helpers.js | 3 ++- 5 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 legacy/config.json diff --git a/legacy/config.json b/legacy/config.json new file mode 100644 index 0000000..16d5169 --- /dev/null +++ b/legacy/config.json @@ -0,0 +1 @@ +{"token":"YOUR BOT TOKEN HERE","game":"BOT GAME HERE","owner":"BOT OWNER ID HERE","hastebinServer":"https://hastebin.com"} \ No newline at end of file diff --git a/package.json b/package.json index 01ace51..e7d30f4 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "colors": "^1.4.0", "dotenv": "^8.2.0", "eris": "^0.13.3", + "express-authentication": "^0.3.2", "moment": "^2.27.0", "sequelize": "^6.3.3", "sqlite3": "^5.0.0" diff --git a/src/discord-commands.js b/src/discord-commands.js index c97e8e9..b4f4cd7 100644 --- a/src/discord-commands.js +++ b/src/discord-commands.js @@ -151,8 +151,19 @@ async function SetPrefix(message, args) async function SetLogChannel(message, args) { - Database.UpdateGuildLogChannel(guild.id, message.channel.id); - + const AlreadyGuild = await Database.FetchGuild(message.guildID); + const guild = await Discord.bot.getRESTGuild(message.guildID); + if (AlreadyGuild == -1) + { + Database.NewGuild(guild.id, guild.name, '*', message.channel.id, {}, 0); + } else { + if (AlreadyGuild.name != guild.name) + { + Database.UpdateGuildName(guild.id, message.guild.name); + } + Database.UpdateGuildLogChannel(guild.id, message.channel.id); + } + DiscordHelpers.SendMessageSafe(message.channel.id, 'Logging fallback channel set to this channel'); } diff --git a/src/discord-events.js b/src/discord-events.js index c7ca454..72e48e5 100644 --- a/src/discord-events.js +++ b/src/discord-events.js @@ -606,27 +606,25 @@ async function GuildMemberRemove(guild, member) DiscordHelpers.SendMessageSafe(FallbackChannel, { embed: embed.sendable }); } -// FIXME: this is broken af lmao async function MessageDelete(message) { const FallbackChannel = await GetLogChannel(message.channel.guild.id); if (FallbackChannel == -1) return; - /* - * IMPORTANT(aosync): Check if audit log entry is recent enough. Because it might cause it to use an entry for a previous action. - * When this is implemented, we'll just have to assume deleter is author when no recent enough entry is found. - */ + + // FIXME: Check if audit log entry is recent enough. Because it might cause it to use an entry for a previous action. + // When this is implemented, we'll just have to assume deleter is author when no recent enough entry is found. const LastAuditEntry = (await message.channel.guild.getAuditLogs(1, undefined, MESSAGE_DELETE)).entries[0]; const DeletedMessage = LastAuditEntry.channel.messages.random(); try { - var authorMention = 'Author not found'; - var author = { + let authorMention = 'Author not found'; + let author = { name: 'Unknown', url: 'https://logori.xyz' } - var responsible = LastAuditEntry ? LastAuditEntry.user.mention : 'Message author'; + let responsible = LastAuditEntry ? LastAuditEntry.user.mention : 'Message author'; if (message.author) { author.name = message.author.username; author.icon_url = message.author.avatarURL; @@ -639,7 +637,7 @@ async function MessageDelete(message) // Left blank because currently inaccurate. When the IMPORTANT comment is achieved, the above lines can be uncommented. } - var embed = new DiscordEmbed({ + let embed = new DiscordEmbed({ author: author, title: 'Message Deleted', colour: ColourConvert('#E0532B'), diff --git a/src/discord-helpers.js b/src/discord-helpers.js index c4207a0..3098dcc 100644 --- a/src/discord-helpers.js +++ b/src/discord-helpers.js @@ -16,7 +16,8 @@ module.exports.GetMemberJoinPos = (memberid, guild) => } module.exports.SendMessageSafe = async (channelid, message) => { - // TODO: make this an actual check instead of a guess + // TODO: make this an actual check instead of a guess & catch lol + try { Discord.bot.createMessage(channelid, message); } catch (e)